### Full Charge Creation Example Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Demonstrates a full charge creation flow using bank details and multiple OTP submissions. This example requires the 'paystack-sdk' package and a valid Paystack secret key. It handles different charge statuses like 'send_birthday' and 'send_otp'. ```javascript paystack.charge .create({ amount: 2000, email: 'john@doe.com', bank: { account_number: '0000000000', code: '057', }, }) .then(async (charge) => { if (charge.data.status === 'send_birthday') { const response = await paystack.charge.submitBirthday({ birthday: '1961-09-21', reference: charge.data.reference, }); if (response.data.status === 'send_otp') { try { const result = await paystack.charge.submitOTP({ otp: '123456', reference: charge.data.reference, }); paystack.charge .submitOTP({ otp: '123456', reference: charge.data.reference, }) .then((payment) => console.log(payment)); } catch (err) { console.error(err); } } } }); ``` -------------------------------- ### Install Paystack SDK with NPM or Yarn Source: https://github.com/tekpriest/paystack-node/blob/main/README.md Installation instructions for the Paystack SDK package. Supports both Yarn and NPM package managers. Required before using any Paystack functionality. ```bash yarn add paystack-sdk ``` ```bash npm install paystack-sdk ``` -------------------------------- ### Initialize Paystack SDK (TypeScript and JavaScript) Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Demonstrates how to import and initialize the Paystack SDK in both TypeScript and JavaScript environments. Requires the 'paystack-sdk' package and a secret key. ```typescript import Paystack from 'paystack-sdk' const paystack = new Paystack("secret_key"); ``` ```javascript const Paystack = require('paystack-sdk'); const paystack = new Paystack("secret_key") ``` -------------------------------- ### Create a Plan using Paystack SDK Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Shows how to create a new plan with specified name, amount, and interval using the Paystack SDK. The result is logged to the console. ```javascript paystack.plan .create({ name: 'Test Plan', amount: 20000, interval: 'daily', }) .then((plan) => console.log(plan)); ``` -------------------------------- ### List Plans using Paystack SDK Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Demonstrates how to retrieve a list of plans, with an option to specify the number of plans per page. The fetched plans are logged to the console. ```javascript paystack.plan .list({ perPage: 2 }) .then((plans) => console.log(plans)); ``` -------------------------------- ### Initialize Paystack SDK (JavaScript) Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Imports and initializes the Paystack SDK client in JavaScript. Requires the 'paystack-sdk' package. Takes a secret key as input. ```javascript const Paystack = require('paystack-sdk'); const paystack = new Paystack("secret_key") ``` -------------------------------- ### Initialize Paystack SDK (TypeScript) Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Imports and initializes the Paystack SDK client in TypeScript. Requires the 'paystack-sdk' package. Takes a secret key as input. ```typescript import Paystack from 'paystack-sdk' const paystack = new Paystack("secret_key"); ``` -------------------------------- ### Create Subscription Plan with Paystack Node.js SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Sets up a new subscription plan for recurring payments. Requires the Paystack Node.js SDK and a secret key. It takes plan details like name, amount, interval, and currency as input, and outputs the created plan's details. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create a subscription plan const plan = await paystack.plan.create({ name: 'Premium Monthly Subscription', amount: 50000, // 500 NGN in kobo interval: 'monthly', // 'daily', 'weekly', 'monthly', 'annually' description: 'Access to premium features', currency: 'NGN', invoice_limit: 12, // Number of invoices to send send_invoices: true, send_sms: true }); if (plan.status) { console.log('Plan created successfully'); console.log('Plan code:', plan.data.plan_code); console.log('Plan ID:', plan.data.id); console.log('Amount:', plan.data.amount / 100, plan.data.currency); console.log('Interval:', plan.data.interval); // Use plan.data.plan_code when initializing subscription transactions } ``` -------------------------------- ### Plan Creation API Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Allows you to create a new plan with specified details such as name, amount, and interval. ```APIDOC ## POST /plans ### Description Creates a new plan for recurring payments. ### Method POST ### Endpoint /plans ### Parameters #### Request Body - **name** (string) - Required - The name of the plan. - **amount** (integer) - Required - The amount to charge in the smallest currency unit (e.g., kobo for NGN). - **interval** (string) - Required - The interval of the plan (e.g., 'daily', 'weekly', 'monthly', 'annually'). ### Request Example ```json { "name": "Test Plan", "amount": 20000, "interval": "daily" } ``` ### Response #### Success Response (200) - **data** (object) - The created plan object. #### Response Example ```json { "status": "success", "message": "Plan created successfully", "data": { "id": 123, "name": "Test Plan", "amount": 20000, "interval": "daily" } } ``` ``` -------------------------------- ### Create Product with Inventory using Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Adds inventory items to your Paystack integration. This function allows you to define product details such as name, description, price, currency, and quantity. Requires the Paystack SDK and a valid secret key. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create product const product = await paystack.product.create({ name: 'Premium Widget', description: 'High-quality widget with advanced features', price: 150000, // 1500 NGN in kobo currency: 'NGN', unlimited: false, quantity: 100 }); if (product.status) { console.log('Product created!'); console.log('Product ID:', product.data.id); console.log('Product code:', product.data.product_code); console.log('Price:', product.data.price / 100, product.data.currency); console.log('Available quantity:', product.data.quantity); } ``` -------------------------------- ### Initialize Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Initializes the Paystack SDK with a secret key. This sets up the client for making authenticated requests to the Paystack API. It enables access to various modules like transactions. ```typescript import { Paystack } from 'paystack-sdk'; // Initialize with secret key const paystack = new Paystack('sk_test_your_secret_key_here'); // All modules are now accessible const transaction = await paystack.transaction.initialize({ amount: '50000', email: 'customer@example.com' }); ``` -------------------------------- ### List Plans API Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Retrieves a list of all available plans, with options for pagination. ```APIDOC ## GET /plans ### Description Retrieves a list of all plans. Supports pagination. ### Method GET ### Endpoint /plans ### Parameters #### Query Parameters - **perPage** (integer) - Optional - Number of plans to return per page. Defaults to 50. - **page** (integer) - Optional - The page number to retrieve. Defaults to 1. ### Request Example ``` GET /plans?perPage=2 ``` ### Response #### Success Response (200) - **data** (array) - An array of plan objects. #### Response Example ```json { "status": "success", "message": "Plans retrieved successfully", "data": [ { "id": 123, "name": "Test Plan 1", "amount": 20000, "interval": "daily" }, { "id": 456, "name": "Test Plan 2", "amount": 25000, "interval": "weekly" } ] } ``` ``` -------------------------------- ### Fetch a Specific Plan using Paystack SDK Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Explains how to fetch details of a single plan by its ID. The retrieved plan object is then logged to the console. ```javascript paystack.plan .fetch(123456) .then((plan) => console.log(plan)); ``` -------------------------------- ### Create SubAccount with Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Sets up a subaccount for split payment configurations using the Paystack Node.js SDK. Requires business details, settlement bank, account number, and charge percentage. Returns subaccount code and configuration. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create subaccount const subaccount = await paystack.subAccount.create({ business_name: 'Partner Store', settlement_bank: '057', account_number: '0193274682', percentage_charge: 15.5, // Percentage of each transaction description: 'Partner merchant account', primary_contact_email: 'partner@example.com', primary_contact_name: 'John Partner', primary_contact_phone: '+2348012345678' }); if (subaccount.status) { console.log('Subaccount created!'); console.log('Subaccount code:', subaccount.data.subaccount_code); console.log('Business name:', subaccount.data.business_name); console.log('Percentage charge:', subaccount.data.percentage_charge); // Use subaccount code when initializing transactions } ``` -------------------------------- ### Initiate Bulk Transfers using Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Initiates multiple transfers in a single request, optimizing batch operations. It accepts a source (e.g., 'balance') and an array of transfer objects, each with amount, recipient, reference, and reason. Requires the Paystack SDK and a valid secret key. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Initiate bulk transfers const bulkTransfer = await paystack.transfer.bulk({ source: 'balance', transfers: [ { amount: 50000, recipient: 'RCP_1a25w1h3n0xctjg', reference: 'TRF1-' + Date.now(), reason: 'Monthly payout' }, { amount: 30000, recipient: 'RCP_2b36w2h4n1xdukh', reference: 'TRF2-' + Date.now(), reason: 'Commission payment' } ] }); if (bulkTransfer.status) { console.log('Bulk transfer initiated'); bulkTransfer.data.forEach(transfer => { console.log(`Transfer ${transfer.reference}: ${transfer.status}`); console.log(`Amount: ${transfer.amount / 100}`); }); } ``` -------------------------------- ### Create Customer Subscription with Paystack Node.js SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Subscribes a customer to a specific plan. This requires the Paystack Node.js SDK, a secret key, and the customer's ID, the plan code, and an authorization token. It returns details of the newly created subscription. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create subscription const subscription = await paystack.subscription.create({ customer: 'CUS_xnxdt6s1zg1f4nx', plan: 'PLN_gx2wn530m0i3w3m', authorization: 'AUTH_pmx3mgawyd', start_date: new Date('2025-01-01') }); if (subscription.status) { console.log('Subscription created!'); console.log('Subscription code:', subscription.data.subscription_code); console.log('Next payment:', subscription.data.next_payment_date); console.log('Amount:', subscription.data.amount / 100); console.log('Status:', subscription.data.status); } ``` -------------------------------- ### Initialize Paystack Client with JavaScript Source: https://github.com/tekpriest/paystack-node/blob/main/README.md Create a new Paystack instance in JavaScript using CommonJS require syntax. Supports both destructuring and direct require patterns for flexibility. ```javascript const Paystack = require('paystack-sdk').Paystack; const paystack = new Paystack('secret_key'); ``` ```javascript const { Paystack } = require('paystack-sdk'); const paystack = new Paystack('secret_key'); ``` -------------------------------- ### Create Charge Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Initiates a new charge with Paystack. Requires the 'paystack-sdk' package. Accepts amount and email as primary inputs, and returns a charge object. ```javascript paystack.charge .create({ amount: 2000, email: 'john@doe.com', }) .then((charge) => console.log(charge)); ``` -------------------------------- ### Initialize Payment Transaction Source: https://context7.com/tekpriest/paystack-node/llms.txt Creates a new payment transaction, allowing collection of money from customers. It supports various payment channels and includes optional metadata and a callback URL for post-payment processing. The output provides a payment URL and access code for redirecting the customer. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Initialize a transaction with comprehensive options const result = await paystack.transaction.initialize({ amount: '50000', // Amount in kobo (500 NGN) email: 'customer@example.com', currency: 'NGN', reference: 'TXN-' + Date.now(), callback_url: 'https://yoursite.com/payment/callback', metadata: { cart_id: '398', custom_fields: [ { display_name: 'Customer Name', variable_name: 'customer_name', value: 'John Doe' } ] }, channels: ['card', 'bank', 'ussd', 'qr', 'bank_transfer'], split_code: 'SPL_98WF13Eb3w' }); if (result.status) { console.log('Payment URL:', result.data.authorization_url); console.log('Access Code:', result.data.access_code); console.log('Reference:', result.data.reference); // Redirect customer to result.data.authorization_url } else { console.error('Transaction failed:', result.message); } ``` -------------------------------- ### Initialize Paystack Client with TypeScript Source: https://github.com/tekpriest/paystack-node/blob/main/README.md Create a new Paystack instance in TypeScript by importing the Paystack class and providing your secret API key. Enables access to all Paystack API methods with full type safety. ```typescript import {Paystack} from 'paystack-sdk'; const paystack = new Paystack("secret_key"); ``` -------------------------------- ### Update a Plan using Paystack SDK Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Illustrates how to update an existing plan using its ID and providing new details such as the amount. The updated plan details are logged. ```javascript paystack.plan .update(123456, { amount: 30000, }) .then((plan) => console.log(plan)); ``` -------------------------------- ### Create Customer with Paystack TypeScript SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Register a new customer in the Paystack integration with personal details and optional metadata. Returns a customer code that should be stored in your database for future reference. Accepts email, name, phone number, and custom metadata fields. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create a customer const customer = await paystack.customer.create({ email: 'john.doe@example.com', first_name: 'John', last_name: 'Doe', phone: '+2348012345678', metadata: { age: 30, customer_tier: 'premium', source: 'website' } }); if (customer.status) { console.log('Customer created successfully'); console.log('Customer code:', customer.data.customer_code); console.log('Customer ID:', customer.data.id); console.log('Email:', customer.data.email); // Store customer.data.customer_code in your database } else { console.error('Failed to create customer:', customer.message); } ``` -------------------------------- ### Create Refund with Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Initiates a refund for a completed transaction using the Paystack Node.js SDK. Requires transaction ID and can optionally include amount, currency, and notes. Returns refund status and details. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create refund const refund = await paystack.refund.create({ transaction: 1234567, // Transaction ID amount: 50000, // Amount to refund in kobo (optional, full refund if not specified) currency: 'NGN', customer_note: 'Refund for cancelled order', merchant_note: 'Customer requested cancellation' }); if (refund.status) { console.log('Refund initiated!'); console.log('Refund ID:', refund.data.id); console.log('Amount:', refund.data.amount / 100); console.log('Status:', refund.data.status); console.log('Transaction reference:', refund.data.transaction.reference); } ``` -------------------------------- ### Submit PIN for Charge Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Submits a PIN to verify a charge. Requires the 'paystack-sdk' package and a charge reference. Inputs include the PIN and the charge reference. ```javascript paystack.charge .submitPIN({ pin: '1234', reference: '5bwib5v6anhe9xa', }) .then((charge) => console.log(charge)); ``` -------------------------------- ### List Subscription Plans with Paystack Node.js SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Retrieves a list of all subscription plans associated with your Paystack integration. This function requires the Paystack Node.js SDK and a secret key. It accepts pagination parameters and returns an array of plan objects. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // List all plans const plans = await paystack.plan.list({ perPage: 50, page: 1 }); if (plans.status) { plans.data.forEach(plan => { console.log(`Plan: ${plan.name}`); console.log(`Code: ${plan.plan_code}`); console.log(`Amount: ${plan.amount / 100} ${plan.currency} per ${plan.interval}`); console.log(`Subscriptions: ${plan.subscriptions?.length || 0}`); }); } ``` -------------------------------- ### Create Transaction Split with Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Configures revenue sharing across multiple subaccounts for transactions using the Paystack Node.js SDK. Defines split type, currency, and subaccount shares. Returns split code and configuration details. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create transaction split const split = await paystack.split.create({ name: 'Multi-vendor Split', type: 'percentage', // or 'flat' currency: 'NGN', subaccounts: [ { subaccount: 'ACCT_hdl8abxl8drhrl3', share: 30 // 30% of transaction }, { subaccount: 'ACCT_8f4s1eq7ml6rlzj', share: 20 // 20% of transaction } ], bearer_type: 'account', // Who pays Paystack charges bearer_subaccount: 'ACCT_hdl8abxl8drhrl3' }); if (split.status) { console.log('Split configuration created!'); console.log('Split code:', split.data.split_code); console.log('Name:', split.data.name); console.log('Type:', split.data.type); console.log('Total subaccounts:', split.data.subaccounts.length); // Use split.data.split_code when initializing transactions } ``` -------------------------------- ### Create Charge with Bank or Card Details using Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Processes a direct charge using either bank or card details. This function handles multi-step charge flows including OTP and PIN verification if required by the transaction. Requires the Paystack SDK and a valid secret key. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create charge with bank details const charge = await paystack.charge.create({ amount: 200000, // 2000 NGN email: 'customer@example.com', bank: { code: '057', // Bank code account_number: '0000000000' } }); // Handle charge flow based on status if (charge.data.status === 'send_birthday') { // Submit birthday const birthdayResponse = await paystack.charge.submitBirthday({ birthday: '1990-05-15', reference: charge.data.reference }); if (birthdayResponse.data.status === 'send_otp') { // Submit OTP const otpResponse = await paystack.charge.submitOTP({ otp: '123456', reference: charge.data.reference }); if (otpResponse.data.status === 'success') { console.log('Charge successful!'); console.log('Amount:', otpResponse.data.amount / 100); } } } else if (charge.data.status === 'send_pin') { // Submit PIN if required const pinResponse = await paystack.charge.submitPIN({ pin: '1234', reference: charge.data.reference }); } ``` -------------------------------- ### Resolve Card BIN with Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Retrieves card information based on the first 6 digits (BIN) using the Paystack Node.js SDK. Returns card type, bank, brand, country, and BIN details. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Resolve card BIN const cardInfo = await paystack.verification.resolveCard(539983); if (cardInfo.status) { console.log('Card type:', cardInfo.data.card_type); console.log('Bank:', cardInfo.data.bank); console.log('Brand:', cardInfo.data.brand); console.log('Country:', cardInfo.data.country_name); console.log('BIN:', cardInfo.data.bin); } ``` -------------------------------- ### Fetch Plan API Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Retrieves the details of a specific plan using its unique ID. ```APIDOC ## GET /plans/{planId} ### Description Fetches the details of a specific plan by its ID. ### Method GET ### Endpoint /plans/{planId} ### Parameters #### Path Parameters - **planId** (integer) - Required - The unique identifier of the plan to fetch. ### Request Example ``` GET /plans/123456 ``` ### Response #### Success Response (200) - **data** (object) - The details of the requested plan. #### Response Example ```json { "status": "success", "message": "Plan fetched successfully", "data": { "id": 123456, "name": "Specific Plan", "amount": 22000, "interval": "monthly" } } ``` ``` -------------------------------- ### Initiate Bank Transfer with Paystack Node.js SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Initiates a money transfer to a recipient's bank account. This function requires the Paystack Node.js SDK, a secret key, and details such as the source of funds, amount, recipient code, currency, and a reference. It can return pending status or require OTP for finalization. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Initiate transfer to recipient const transfer = await paystack.transfer.initiate({ source: 'balance', amount: 50000, // 500 NGN in kobo recipient: 'RCP_gx2wn530m0i3w3m', reason: 'Payment for services rendered', currency: 'NGN', reference: 'TRF-' + Date.now() }); if (transfer.status) { if (transfer.data.status === 'pending') { console.log('Transfer pending - OTP disabled'); console.log('Transfer code:', transfer.data.transfer_code); console.log('Amount:', transfer.data.amount); } else if (transfer.data.status === 'otp') { console.log('Transfer requires OTP'); console.log('Transfer code:', transfer.data.transfer_code); // Use paystack.transfer.finalize() with OTP } } ``` -------------------------------- ### Submit Address for Charge Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Submits address details for charge verification. Requires the 'paystack-sdk' package. Inputs include address, city, state, and zip code. ```javascript paystack.charge .submitAddress({ address: '140 N 2ND ST', city: 'Stroudsburg', state: 'PA', zip_code: '18360', }) .then((charge) => console.log(charge)); ``` -------------------------------- ### Submit OTP for Charge Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Submits an One-Time Password (OTP) to verify a charge. Requires the 'paystack-sdk' package and a charge reference. Inputs include the OTP and the charge reference. ```javascript paystack.charge .submitOTP({ otp: '123456', reference: '5bwib5v6anhe9xa', }) .then((charge) => console.log(charge)); ``` -------------------------------- ### List Customers with Pagination in Paystack TypeScript SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Retrieve paginated customer records from Paystack with configurable page size and page number. Returns metadata including total customer count and individual customer details with transaction counts and risk actions. Useful for building customer management interfaces. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // List all customers const customers = await paystack.customer.list({ perPage: 100, page: 1 }); if (customers.status) { console.log('Total customers:', customers.meta.total); customers.data.forEach(customer => { console.log(`${customer.customer_code}: ${customer.first_name} ${customer.last_name}`); console.log(`Email: ${customer.email}`); console.log(`Transactions: ${customer.transactions.length}`); console.log(`Risk action: ${customer.risk_action}`); }); } ``` -------------------------------- ### Fetch Customer Details with Paystack TypeScript SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Retrieve comprehensive information about a specific customer using customer code or email address. Includes personal details, transaction history, active subscriptions, and saved payment authorizations with card information. Useful for displaying complete customer profiles. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Fetch by customer code or email const customer = await paystack.customer.fetch('CUS_xnxdt6s1zg1f4nx'); // OR const customer2 = await paystack.customer.fetch('customer@example.com'); if (customer.status) { console.log('Customer:', customer.data.first_name, customer.data.last_name); console.log('Email:', customer.data.email); console.log('Phone:', customer.data.phone); console.log('Customer code:', customer.data.customer_code); console.log('Total transactions:', customer.data.transactions.length); console.log('Active subscriptions:', customer.data.subscriptions.length); console.log('Saved cards:', customer.data.authorizations.length); // Access saved payment authorizations customer.data.authorizations.forEach(auth => { console.log(`Card: ${auth.card_type} ending in ${auth.last4}`); console.log(`Authorization code: ${auth.authorization_code}`); }); } ``` -------------------------------- ### Create Dedicated Virtual Account with Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Generates a unique virtual bank account number for a customer using the Paystack Node.js SDK. Requires customer ID and optionally a preferred bank. Returns account details if successful. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create dedicated virtual account const account = await paystack.dedicated.create({ customer: 'CUS_xnxdt6s1zg1f4nx', preferred_bank: 'wema-bank' // or 'test-bank' for test mode }); if (account.status) { console.log('Dedicated account created!'); console.log('Bank name:', account.data.bank.name); console.log('Account number:', account.data.account_number); console.log('Account name:', account.data.account_name); console.log('Customer code:', account.data.customer.customer_code); console.log('Active:', account.data.active); // Customer can now transfer money directly to this account } ``` -------------------------------- ### Submit Phone Number for Charge Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Submits a phone number for charge verification. Requires the 'paystack-sdk' package and a charge reference. Inputs include the phone number and the charge reference. ```javascript paystack.charge .submitPhone({ phone: '08012345678', reference: '5bwib5v6anhe9xa', }) .then((charge) => console.log(charge)); ``` -------------------------------- ### Create Invoice for Customer Payments using Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Generates payment requests (invoices) for customers. This function allows specifying customer details, line items, due dates, tax information, and currency. It can also send notifications to the customer. Requires the Paystack SDK and a valid secret key. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Create invoice const invoice = await paystack.invoice.create({ customer: 'CUS_xnxdt6s1zg1f4nx', description: 'Payment for consulting services', amount: 500000, // 5000 NGN due_date: new Date('2025-01-31'), line_items: [ { name: 'Consulting Session', amount: 300000, quantity: 1 }, { name: 'Documentation', amount: 200000, quantity: 1 } ], tax: [ { name: 'VAT', amount: 37500 // 7.5% } ], currency: 'NGN', send_notification: true }); if (invoice.status) { console.log('Invoice created!'); console.log('Invoice code:', invoice.data.code); console.log('Invoice URL:', invoice.data.url); console.log('Amount:', invoice.data.amount / 100); console.log('Due date:', invoice.data.due_date); } ``` -------------------------------- ### Finalize Transfer with OTP Verification using Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Completes a transfer that requires OTP verification. It takes a transfer ID and an OTP code as input and returns the status of the finalization. Requires the Paystack SDK and a valid secret key. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Finalize transfer with OTP const finalized = await paystack.transfer.finalize( 'TRF_vsyqdmlzble3uii', '928783' ); if (finalized.status && finalized.data.status === 'success') { console.log('Transfer completed successfully'); console.log('Amount:', finalized.data.amount / 100); console.log('Recipient:', finalized.data.recipient.details.account_name); console.log('Transfer date:', finalized.data.transferred_at); } else { console.error('Transfer failed:', finalized.message); } ``` -------------------------------- ### Submit Birthday for Charge Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Submits a birthday for charge verification. Requires the 'paystack-sdk' package and a charge reference. Inputs include the birthday and the charge reference. ```javascript paystack.charge .submitBirthday({ birthday: '1961-09-21', reference: '5bwib5v6anhe9xa', }) .then((charge) => console.log(charge)); ``` -------------------------------- ### Update Subscription Plan with Paystack Node.js SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Modifies an existing subscription plan's details, such as its name, amount, or description. This operation requires the Paystack Node.js SDK, a secret key, and the unique identifier (ID or code) of the plan to be updated. It returns the updated plan's information. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Update plan by ID or code const updated = await paystack.plan.update('PLN_gx2wn530m0i3w3m', { name: 'Premium Annual Subscription', amount: 500000, // New price: 5000 NGN description: 'Updated plan with more benefits', send_invoices: false }); if (updated.status) { console.log('Plan updated successfully'); console.log('New amount:', updated.data.amount); console.log('Updated name:', updated.data.name); } ``` -------------------------------- ### Enable/Disable Subscription with Paystack Node.js SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Programmatically controls the status of a customer's subscription, allowing it to be enabled or disabled. This functionality uses the Paystack Node.js SDK and requires the subscription code and an authentication token. It returns the updated subscription status. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Disable a subscription const disabled = await paystack.subscription.disable({ code: 'SUB_vsyqdmlzble3uii', token: 'auth_token_here' }); // Enable a subscription const enabled = await paystack.subscription.enable({ code: 'SUB_vsyqdmlzble3uii', token: 'auth_token_here' }); if (enabled.status) { console.log('Subscription enabled successfully'); } ``` -------------------------------- ### Resolve Bank Account with Paystack SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Verifies bank account details using the Paystack Node.js SDK. Requires account number and bank code. Returns account name and other details if the account is valid, otherwise indicates an error. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Resolve account number const resolved = await paystack.verification.resolveAccount({ account_number: '0022728151', bank_code: '057' }); if (resolved.status) { console.log('Account verified!'); console.log('Account name:', resolved.data.account_name); console.log('Account number:', resolved.data.account_number); console.log('Bank:', resolved.data.bank_id); // Proceed with transfer or display to user for confirmation } else { console.error('Invalid account details'); } ``` -------------------------------- ### Update Plan API Source: https://github.com/tekpriest/paystack-node/blob/main/src/plan/README.md Updates an existing plan's details, such as its amount. ```APIDOC ## PUT /plans/{planId} ### Description Updates an existing plan. ### Method PUT ### Endpoint /plans/{planId} ### Parameters #### Path Parameters - **planId** (integer) - Required - The unique identifier of the plan to update. #### Request Body - **amount** (integer) - Optional - The new amount to charge in the smallest currency unit. - **name** (string) - Optional - The new name of the plan. ### Request Example ```json { "amount": 30000 } ``` ### Response #### Success Response (200) - **data** (object) - The updated plan object. #### Response Example ```json { "status": "success", "message": "Plan updated successfully", "data": { "id": 123456, "name": "Updated Plan Name", "amount": 30000, "interval": "monthly" } } ``` ``` -------------------------------- ### Charge Authorization with Paystack TypeScript SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Charge a customer using a previously saved authorization code for recurring payments or stored card transactions. Requires a valid authorization code from a previous transaction and customer email. Supports metadata for tracking subscription details and queue parameter to prevent API overload. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Charge saved card/authorization const charge = await paystack.transaction.chargeAuthorization({ amount: '15000', // 150 NGN in kobo email: 'customer@example.com', authorization_code: 'AUTH_pmx3mgawyd', reference: 'RECURRING-' + Date.now(), currency: 'NGN', metadata: { subscription_id: 'SUB-12345', billing_cycle: 'monthly' }, channels: ['card'], queue: true // Queue for processing to avoid overload }); if (charge.status && charge.data.status === 'success') { console.log('Charge successful!'); console.log('Amount charged:', charge.data.amount); console.log('Transaction reference:', charge.data.reference); } else { console.error('Charge failed:', charge.data.gateway_response); } ``` -------------------------------- ### Update Customer Information with Paystack TypeScript SDK Source: https://context7.com/tekpriest/paystack-node/llms.txt Modify existing customer details including name, email, phone number, and custom metadata. Requires the customer code identifier and returns updated customer information with modification timestamp. Changes are immediately reflected in the Paystack system. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Update customer details const updated = await paystack.customer.update('CUS_xnxdt6s1zg1f4nx', { first_name: 'Jane', last_name: 'Smith', email: 'jane.smith@example.com', phone: '+2348087654321', metadata: { customer_tier: 'gold', loyalty_points: 500 } }); if (updated.status) { console.log('Customer updated successfully'); console.log('New email:', updated.data.email); console.log('Updated at:', updated.data.updatedAt); } ``` -------------------------------- ### List Transactions with Filters Source: https://context7.com/tekpriest/paystack-node/llms.txt Retrieves a paginated list of transactions, allowing filtering by status, date range, and amount. This function is useful for generating reports, auditing, or managing transaction history. It includes metadata for pagination details. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // List transactions with filters const transactions = await paystack.transaction.list({ perPage: 50, page: 1, status: 'success', from: new Date('2024-01-01'), to: new Date('2024-12-31'), amount: 50000 }); if (transactions.status) { console.log('Total transactions:', transactions.meta.total); console.log('Current page:', transactions.meta.page); transactions.data.forEach(txn => { console.log(`${txn.reference}: ${txn.amount} ${txn.currency} - ${txn.status}`); console.log(`Customer: ${txn.customer.email}`); console.log(`Date: ${txn.created_at}`); }); } ``` -------------------------------- ### Check Pending Charge Status Source: https://github.com/tekpriest/paystack-node/blob/main/src/charge/README.md Checks the status of a pending charge using its reference. Requires the 'paystack-sdk' package and the charge reference. ```javascript paystack.charge .checkPending('5bwib5v6anhe9xa') .then((charge) => console.log(charge)); ``` -------------------------------- ### Verify Transaction Status Source: https://context7.com/tekpriest/paystack-node/llms.txt Confirms the status of a payment transaction using its reference ID. This is crucial for validating successful payments and handling potential failures or pending statuses. The function returns detailed transaction data upon successful verification. ```typescript import { Paystack } from 'paystack-sdk'; const paystack = new Paystack(process.env.PAYSTACK_SECRET_KEY); // Verify transaction using the reference const verification = await paystack.transaction.verify('TXN-1637849234567'); if (verification.status && verification.data.status === 'success') { console.log('Payment successful!'); console.log('Amount paid:', verification.data.amount / 100, verification.data.currency); console.log('Customer:', verification.data.customer.email); console.log('Payment channel:', verification.data.channel); console.log('Transaction ID:', verification.data.id); console.log('Paid at:', verification.data.paid_at); // Process the order, grant access, etc. } else { console.log('Payment failed or pending'); console.log('Status:', verification.data.status); console.log('Gateway response:', verification.data.gateway_response); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.