### Install KKIAPAY SDK via NPM Source: https://github.com/kkiapay/js-sdk/blob/master/README.md Use this command to add the KKIAPAY package to your project dependencies. ```bash $ npm i -s kkiapay ``` -------------------------------- ### Initialize KKIAPAY SDK Source: https://github.com/kkiapay/js-sdk/blob/master/README.md Initialize the SDK with your API key for either production or sandbox environments. ```js // setup your api key (https://www.kkiapay.me) //initialize kkiapay in production environnment const k = kkiapay("") ``` ```js //initialize kkiapay in sandbox environnment const k = kkiapay("",{sandbox:true}) ``` -------------------------------- ### Configure SDK environment and host settings Source: https://context7.com/kkiapay/js-sdk/llms.txt Initialize the SDK with specific environment flags or custom host configurations. Use the sandbox option for testing and the host/sdk options for widget integrations. ```javascript const kkiapay = require('kkiapay'); // Production environment - real transactions // API Base URL: https://api.kkiapay.me const prodClient = kkiapay("your-production-api-key"); // Sandbox environment - test transactions // API Base URL: https://api-sandbox.kkiapay.me const sandboxClient = kkiapay("your-sandbox-api-key", { sandbox: true }); // Alternative: Use 'Test' flag for sandbox const testClient = kkiapay("your-sandbox-api-key", { Test: true }); // Custom host configuration for widget integration const widgetClient = kkiapay("your-api-key", { sandbox: true, host: "https://your-website.com", // Sets x-widget-host header sdk: "custom-sdk-name" // Custom SDK identifier }); ``` -------------------------------- ### SDK Initialization Source: https://context7.com/kkiapay/js-sdk/llms.txt Initialize the KKIAPAY SDK with your API key. Supports both production and sandbox environments. ```APIDOC ## SDK Initialization Initialize the KKIAPAY SDK with your API key obtained from the KKIAPAY developer dashboard. The SDK supports both production and sandbox environments for testing purposes. ```javascript const kkiapay = require('kkiapay'); // Initialize for production environment const k = kkiapay("your-api-key"); // Initialize for sandbox/testing environment const kSandbox = kkiapay("your-api-key", { sandbox: true }); // Alternative sandbox configuration using Test flag const kTest = kkiapay("your-api-key", { Test: true }); ``` ``` -------------------------------- ### Include KKIAPAY SDK via CDN Source: https://github.com/kkiapay/js-sdk/blob/master/README.md Add this script tag to your HTML file to load the SDK directly from the unpkg CDN. ```html ``` -------------------------------- ### Integrate KKIAPAY in browser applications Source: https://context7.com/kkiapay/js-sdk/llms.txt Include the SDK via CDN to enable payment processing in the browser. The SDK automatically manages WebSocket connections for real-time status updates. ```html KKIAPAY Payment
``` -------------------------------- ### Initiate Payments with debitRequest() Source: https://context7.com/kkiapay/js-sdk/llms.txt Perform a low-level payment request without automatic result listening. Use this for custom WebSocket handling or server-side callback configurations. ```javascript const kkiapay = require('kkiapay'); const k = kkiapay("your-api-key", { sandbox: true }); // Initiate a debit request with customer details k.debitRequest("22997000000", 1, "JOHN", "DOE") .then((response) => { console.log("Request status:", response.status); // 200 on success // Manually set up the listener with custom timeout k.debitListener(90000) .then((data) => { console.log("Payment successful:", data); // { account: "22997000000", transactionId: "txn_xxx" } }) .catch((error) => { console.error("Payment failed:", error); // { failureCode: "...", failureMessage: "...", account: "...", transactionId: "..." } }); }) .catch((err) => { // API key validation failed or network error console.log("Request failed:", err); // { failureCode: "Your developer account is not active!" } }); // With callback URL for server-side notification k.debitRequest( "22967434270", // phone 1000, // amount in XOF "Jane", // firstname "Smith", // lastname "jane@example.com", // email false, // direct { orderId: "ORD-123" }, // stateData - custom data returned in callback "https://yourserver.com/webhook/payment", // callback URL "partner-123" // partnerId ) .then((response) => { console.log("Payment initiated, waiting for confirmation..."); }); ``` -------------------------------- ### Perform a Debit Request Source: https://github.com/kkiapay/js-sdk/blob/master/README.md Initiate a mobile money debit request using the debit method, handling success and error states via promises. ```js //request 100 XOF from 67 43 42 70, mobile money account k.debit("22967434270",100).then((res) => { // handle response }).catch((err) => { //handle error }) ``` -------------------------------- ### Debit Method Source: https://context7.com/kkiapay/js-sdk/llms.txt Initiates a mobile money payment and automatically listens for the payment result via WebSocket. Returns a promise that resolves on success or rejects on failure. ```APIDOC ## debit(phone, amount, firstname, lastname, email, timeout) The primary method for processing mobile money payments. This method initiates a debit request and automatically listens for the payment result through WebSocket. It returns a promise that resolves when payment succeeds or rejects on failure, timeout, or cancellation. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const kkiapay = require('kkiapay'); const k = kkiapay("your-api-key"); // Request 100 XOF from a mobile money account k.debit("22967434270", 100) .then((result) => { // Payment successful console.log("Transaction ID:", result.transactionId); console.log("Account:", result.account); }) .catch((error) => { // Handle various error scenarios console.error("Error Code:", error.failureCode); console.error("Error Message:", error.failureMessage); console.error("Transaction ID:", error.transactionId); console.error("Account:", error.account); // Possible failureCode values: // - "processing_error": System busy or pending payment exists // - "insufficent_fund": Account balance is insufficient // - "Timeout": Payment request timed out }); // With full customer details and 90-second timeout k.debit("22967434270", 500, "John", "Doe", "john@example.com", 90000) .then((result) => { console.log("Payment completed:", result); }) .catch((error) => { console.error("Payment failed:", error); }); ``` ### Response #### Success Response (200) - **transactionId** (string) - The unique identifier for the transaction. - **account** (string) - The mobile money account number used for the transaction. #### Error Response - **failureCode** (string) - Code indicating the reason for failure (e.g., "processing_error", "insufficent_fund", "Timeout"). - **failureMessage** (string) - A human-readable message explaining the failure. - **transactionId** (string) - The transaction ID, if available. - **account** (string) - The account number, if available. ### Response Example ```json { "transactionId": "txn_12345abcde", "account": "22967434270" } ``` ``` -------------------------------- ### Process Payments with debit() Source: https://context7.com/kkiapay/js-sdk/llms.txt Initiate a debit request and automatically listen for the result via WebSocket. This method returns a promise that resolves on success or rejects on failure. ```javascript const kkiapay = require('kkiapay'); const k = kkiapay("your-api-key"); // Request 100 XOF from a mobile money account k.debit("22967434270", 100) .then((result) => { // Payment successful console.log("Transaction ID:", result.transactionId); console.log("Account:", result.account); }) .catch((error) => { // Handle various error scenarios console.error("Error Code:", error.failureCode); console.error("Error Message:", error.failureMessage); console.error("Transaction ID:", error.transactionId); console.error("Account:", error.account); // Possible failureCode values: // - "processing_error": System busy or pending payment exists // - "insufficent_fund": Account balance is insufficient // - "Timeout": Payment request timed out }); // With full customer details and 90-second timeout k.debit("22967434270", 500, "John", "Doe", "john@example.com", 90000) .then((result) => { console.log("Payment completed:", result); }) .catch((error) => { console.error("Payment failed:", error); }); ``` -------------------------------- ### debit() Method Source: https://github.com/kkiapay/js-sdk/blob/master/README.md Performs a debit request from a mobile money account. ```APIDOC ## debit(phone, amount, [options]) ### Description Initiates a debit request from a specified mobile money account. ### Parameters #### Arguments - **phone** (String) - Required - Valid mobile money number to debit (e.g., 22967434270). - **amount** (Numeric) - Required - Amount to debit from user account (XOF). - **firstname** (String) - Optional - Client firstname. - **lastname** (String) - Optional - Client lastname. - **email** (String) - Optional - Client email address. - **callback** (String) - Optional - URL to receive payment information via POST upon success. ### Response #### Success Response - **transactionId** (String) - Unique Transaction's identifier. - **account** (String) - User phone number. #### Error Response - **failureCode** (String) - The status of requested payment (e.g., processing_error, insufficent_fund). - **failureMessage** (String) - Description of error. - **transactionId** (String) - Unique Transaction's identifier. - **account** (String) - User phone number. ``` -------------------------------- ### Debit Request Method Source: https://context7.com/kkiapay/js-sdk/llms.txt Initiates a payment request without automatically listening for the result. Use this for more control over the payment flow. Returns the HTTP response from the payment request API. ```APIDOC ## debitRequest(phone, amount, firstname, lastname, email, direct, stateData, callback, partnerId) A lower-level method that initiates a payment request without automatically listening for the result. Use this when you need more control over the payment flow or want to handle the WebSocket listener separately. Returns the HTTP response from the payment request API. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **phone** (string) - The customer's phone number. - **amount** (number) - The payment amount in XOF. - **firstname** (string) - The customer's first name. - **lastname** (string) - The customer's last name. - **email** (string) - The customer's email address. - **direct** (boolean) - If true, bypasses the confirmation step (use with caution). - **stateData** (object) - Custom data to be returned with the callback. - **callback** (string) - The URL to receive payment confirmation notifications. - **partnerId** (string) - Your partner ID, if applicable. ### Request Example ```javascript const kkiapay = require('kkiapay'); const k = kkiapay("your-api-key", { sandbox: true }); // Initiate a debit request with customer details k.debitRequest("22997000000", 1, "JOHN", "DOE") .then((response) => { console.log("Request status:", response.status); // 200 on success // Manually set up the listener with custom timeout k.debitListener(90000) .then((data) => { console.log("Payment successful:", data); // { account: "22997000000", transactionId: "txn_xxx" } }) .catch((error) => { console.error("Payment failed:", error); // { failureCode: "...", failureMessage: "...", account: "...", transactionId: "..." } }); }) .catch((err) => { // API key validation failed or network error console.log("Request failed:", err); // { failureCode: "Your developer account is not active!" } }); // With callback URL for server-side notification k.debitRequest( "22967434270", // phone 1000, // amount in XOF "Jane", // firstname "Smith", // lastname "jane@example.com", // email false, // direct { orderId: "ORD-123" }, // stateData - custom data returned in callback "https://yourserver.com/webhook/payment", // callback URL "partner-123" // partnerId ) .then((response) => { console.log("Payment initiated, waiting for confirmation..."); }); ``` ### Response #### Success Response (200) - **status** (number) - Indicates the status of the request (200 for success). #### Error Response - **failureCode** (string) - Code indicating the reason for the request failure. ### Response Example ```json { "status": 200 } ``` ``` -------------------------------- ### Listen for payment status updates with debitListener Source: https://context7.com/kkiapay/js-sdk/llms.txt Use this method to wait for real-time payment confirmation after initiating a debit request. The timeout parameter specifies the maximum duration in milliseconds to wait for a response. ```javascript const kkiapay = require('kkiapay'); const k = kkiapay("your-api-key"); // After initiating a debit request, listen for the result k.debitRequest("22967434270", 100, "John", "Doe") .then((response) => { if (response.status === 200) { // Wait up to 2 minutes for payment confirmation return k.debitListener(120000); } throw new Error("Request failed"); }) .then((result) => { // Success response // { // account: "22967434270", // transactionId: "txn_abc123def456" // } console.log("Payment completed!"); console.log("Account:", result.account); console.log("Transaction ID:", result.transactionId); }) .catch((error) => { // Failure response // { // failureCode: "insufficent_fund" | "processing_error" | "Timeout", // failureMessage: "Description of the error", // account: "22967434270", // transactionId: "txn_abc123def456" // } if (error.failureCode === "Timeout") { console.log("User did not respond in time"); } else if (error.failureCode === "insufficent_fund") { console.log("Insufficient balance in user account"); } else { console.log("Payment failed:", error.failureMessage); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.