Nkwa Pay provides official SDKs for seamless in-app integration across multiple programming languages. These SDKs offer a convenient wrapper around our API endpoints, making it easier to integrate mobile money payments into your applications. All SDK operations mirror the functionality available in the API reference and the Nkwa Pay dashboard.This guide demonstrates how to install, configure, and use our SDKs to process mobile money transactions in your preferred programming language.
Install the Nkwa Pay JavaScript SDK using npm, pnpm, bun, or yarn:
terminal
Copy
# Using npm$ npm add @nkwa-pay/sdk# Using pnpm$ pnpm add @nkwa-pay/sdk# Using bun$ bun add @nkwa-pay/sdk# Using yarn$ yarn add @nkwa-pay/sdk zod# Note that Yarn does not install peer dependencies automatically
You can specify a custom server URL when initializing the client:
example
Copy
// For sandbox environmentconst pay = new Pay({ apiKeyAuth: "your_api_key", serverURL: "https://api.sandbox.pay.mynkwa.com",});// For production environmentconst pay = new Pay({ apiKeyAuth: "your_production_api_key", serverURL: "https://api.pay.mynkwa.com",});
async function collectPayment() { try { const result = await pay.collect.post({ requestBody: { amount: 1000, // Amount in XAF phoneNumber: "237600000000", description: "Payment for order #1234" } }); console.log(result.payment.id); // Use this ID to check payment status later } catch (error) { console.error(error); }}
async function disbursePayment() { try { const result = await pay.disburse.post({ requestBody: { amount: 1000, // Amount in XAF phoneNumber: "237600000000", description: "Refund for order #1234" } }); console.log(result.payment.id); // Use this ID to check disbursement status later } catch (error) { console.error(error); }}