Skip to content

Ahdeyyy/paystack-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paystack-api

A wrapper for the Paystack API with types.

Installation

NPM

    npm install @ahdeyy/paystack

PNPM

    pnpm add @ahdeyy/paystack

YARN

    yarn add @ahdeyy/paystack

BUN

    bun add @ahdeyy/paystack

Usage

Patterns

After using an API, check if the status of the call is true to work with the success response

import { Paystack } from "@ahdeyy/paystack"

// create the paystack object

const paystack = new Paystack(secret_key)

const created_request = await paystack.payment_request.create({
  amount: 10000,
  description: "Payment for goods",
  due_date: "2022-12-31",
  customer: "customer id",
})

// Check the status of the response
if (created_request.status) {
  // Work with the response success data
} else {
  // Work with the response error data
}

Payment request

Create payment request

const paystack = new Paystack(secret_key)

const created_request = await paystack.payment_request.create({
  amount: 10000,
  description: "Payment for goods",
  due_date: "2022-12-31",
  customer: "customer id",
})

Update payment request

const updated_request = await paystack.payment_request.update({
  amount: 10000,
  description: "Payment for goods",
  due_date: "2022-12-31",
  customer: "customer id",
})

Fetch payment request

const fetched_request = await paystack.payment_request.fetch("request id")

List payment requests

const list = await paystack.payment_request.list(query)

Verify payment request

const verified_request = await paystack.payment_request.verify("request id")

Send Notification

const sent_notification = await paystack.payment_request.sendNotification(
  "request id"
)

Payment request total

const total = await paystack.payment_request.total()

Finalize payment request

const finalized_request = await paystack.payment_request.finalize("request id")

Archive payment request

const archived_request = await paystack.payment_request.archive("request id")

Customer

Create customer

const customer = await paystack.customer.create({
  email: "[email protected]",
  first_name: "john",
  last_name: "doe",
})

List customers

const customer = await paystack.customer.list({ perPage: 10, page: 1 })

Fetch customer

const customer = await paystack.customer.fetch(customers_email)

Validate customer

const customer = await paystack.customer.validate(customer_code, {
  country,
  type,
  account_number,
  bvn,
  bank_code,
  first_name,
  last_name,
})

Update customer

const customer = await paystack.customer.update(customer_code, { phone })

Whitelist/Blacklist customer

const customer = await paystack.customer.whitelist_blacklist({
  customer: customer_code,
  risk_action: "deny",
})

Deactivate Authorization

const customer = await paystack.customer.deactivate_authorization(
  Authorization_code
)

Product

Create product

const product = await paystack.product.create({
  name: "sakura",
  description: "cherry blossom",
  price: 10000,
  currency: "NGN",
})

List products

const product = await paystack.product.list({ perPage: 10, page: 1 })

Fetch product

const product = await paystack.product.fetch(product_id)

Update product

const product = await paystack.product.update(product_id, { price: 69420 })

Dedicated Virtual Accounts

Create DVA

    const response = await paystack.dva.create({ customer: import.meta.env.CUSTOMER_CODE ?? '' })

Assign DVA

    const response = await paystack.dva.assign({
        email: "[email protected]",
        first_name: "Jane",
        middle_name: "Karen",
        last_name: "Doe",
        phone: "+2348100000000",
        preferred_bank: "test-bank",
        country: "NG"

    })

List DVA

    const response = await paystack.dva.list({ active: true, currency: "NGN" });

Fetch DVA

    const response = await paystack.dva.fetch("foo")

Requery DVA

    const response = await paystack.dva.requery({ account_number: "98897", provider_slug: "wema-bank" });

Deactivate DVA

    const response = await paystack.dva.deactivate("foo")

Split DVA

    const response = await paystack.dva.split({ customer: "janey" })

Remove split DVA

    const response = await paystack.dva.remove_split("bar")

Fetch bank providers

    const response = await paystack.dva.fetch_bank_providers();

Miscellanous

List banks

    const response = await paystack.miscellaneous.list_banks({ country: "nigeria", use_cursor: true, perPage: 40 })

List countries

    const response = await paystack.miscellaneous.list_countries()

List states

    const response = await paystack.miscellaneous.list_states("US")

ROADMAP

  • Requests

    • Create payment request
    • Update payment request
    • Fetch payment request
    • List payment requests
    • Verify payment request
    • Send Notification
    • Payment request total
    • Finalize payment request
    • Archive payment request
    • Tests
  • Customers

    • Create Customer
    • List Customers
    • Fetch Customer
    • Update Customer
    • Validate Customer
    • Whitelist/Blacklist Customer
    • Deactivate Authorization
    • Tests
  • Products

    • Create Product
    • List Products
    • Fetch Product
    • Update Product
    • Tests
  • Dedicated Virtual Accounts

    • Create Dedicated Virtual Account
    • Assign Dedicated Virtual Account
    • List Dedicated Accounts
    • Fetch Dedicated Account
    • Requery Dedicated Account
    • Deactivate Dedicated Account
    • Split Dedicated Account Transaction
    • Remove Split from Dedicated Account
    • Fetch Bank Providers
    • Tests
  • Transactions

  • Transaction Splits

  • Terminal

  • Apple Pay

  • Subaccounts

  • Plans

  • Subscriptions

  • Payment Pages

  • Settlements

  • Transfer Recipients

  • Transfers

  • Transfers Control

  • Bulk Charges

  • Integration

  • Charge

  • Disputes

  • Refunds

  • Verification

  • Miscellanous

Testing

To run the tests, clone the repository

    git clone https://github.com/Ahdeyyy/paystack-api.git
    bun test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published