SDK Integration

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 Client

Install the Nkwa Pay JavaScript SDK using npm, pnpm, bun, or yarn:

terminal
# 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

Configure

Import and initialize the Nkwa Pay client:

example
import { Pay } from "@nkwa-pay/sdk";

// Initialize with your API key
const pay = new Pay({
  apiKeyAuth: "your_api_key",
});

Server Selection

You can specify a custom server URL when initializing the client:

example
// For sandbox environment
const pay = new Pay({
  apiKeyAuth: "your_api_key",
  serverURL: "https://api.sandbox.pay.mynkwa.com",
});

// For production environment
const pay = new Pay({
  apiKeyAuth: "your_production_api_key",
  serverURL: "https://api.pay.mynkwa.com",
});

Collect Payment

To request a payment from a customer:

example
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);
  }
}

Disburse Payment

To send money to a customer:

example
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);
  }
}

Check Payment Status

To check the status of a payment:

example
async function checkPaymentStatus(paymentId) {
  try {
    const result = await pay.payments.get({
      id: paymentId,
    });
    
    console.log(result.payment.status); // "pending", "successful", or "failed"
  } catch (error) {
    console.error(error);
  }
}

Check MNO Availability

To check the availability of mobile network operators:

example
async function checkAvailability() {
  try {
    const result = await pay.availability.get();
    
    // Check if MTN collections are operational
    const mtnCollections = result.availability.find(a => 
      a.operator === "mtn" && a.operation.type === "collection"
    );
    
    console.log(mtnCollections.operation.status); // "OPERATIONAL" or "SUSPENDED"
  } catch (error) {
    console.error(error);
  }
}