For privacy reasons, FlexPay's original documentation cannot be shared without written permission. For credentials and implementation details, contact FlexPay.
- Typed mobile-money and card payment requests
- Transaction status checks and callback validation
- Development and production API environments
- ESM and CommonJS distributions with TypeScript declarations
- Node.js 24 or newer
Add the TypeScript client to your application's dependencies:
npm install @ngandu-dev/flexpay- Step 1. Contact FlexPay to get a Merchant Account You will receive a Merchant Form to complete in order to provide your business details and preferred Cash out Wallet or Banking Details.
- Step 2. Once the paperwork is completed, you will be issued with Live and Sandbox Accounts (Merchant Code and Authorization token)
Then use these credentials to authenticate your client
import{ClientasFlexpay}from"@ngandu-dev/flexpay";constflexpay=newFlexpay("merchant_code","token","dev");// use "prod" for productionimporttype{CardRequest,MobileRequest}from"@ngandu-dev/flexpay";constmobile={amount: 10,// 10 USDcurrency: "USD",phone: "243999999999",reference: "mobile_order_12345",description: "your_transaction_description",callbackUrl: "https://example.com/flexpay/callback",}satisfiesMobileRequest;constcard={amount: 10,// 10 USDcurrency: "USD",reference: "card_order_12345",description: "your_transaction_description",callbackUrl: "https://example.com/flexpay/callback",approveUrl: "https://example.com/flexpay/approved",cancelUrl: "https://example.com/flexpay/cancelled",declineUrl: "https://example.com/flexpay/declined",homeUrl: "https://example.com",}satisfiesCardRequest;Note: we highly recommend your
callbacksurls to be unique for each transaction.
Once called, Flexpay will send a payment request to the user's mobile money account, and the user will have to confirm the payment on their phone. after that the payment will be processed and the callback url will be called with the transaction details.
constmobileResponse=awaitflexpay.pay(mobile);You can set up card payment via VPOS features, which is typically used for online payments. it's a gateway that allows you to accept payments from your customers using their credit cards.
constcardResponse=awaitflexpay.pay(card);// redirect to cardResponse.url to complete the paymentFlexpay will send a POST request to the defined callbackUrl and the response will contain the transaction details. you can use the following code to validate the incoming payload.
constwebhook=flexpay.handleCallback(req.body);flexpay.isSuccessful(webhook);// true or falseYou don't trust webhook ? you can always check the transaction state by providing the order number.
if(!mobileResponse.orderNumber){thrownewError("FlexPay did not return an order number");}consttx=awaitflexpay.check(mobileResponse.orderNumber);flexpay.isSuccessful(tx);// true or falseReplace the dependency and every import with @ngandu-dev/flexpay. Version 2 is a clean package
move and does not provide an alias for the old scope.
Install dependencies with bun install, then run bun run quality before opening a pull request.
See CONTRIBUTING.md for the complete contribution workflow.
Run bun run test for the test suite or bun run test:coverage for a coverage report.
Contributions are welcome. Please read CONTRIBUTING.md and follow our Code of Conduct.
Please report vulnerabilities privately as described in SECURITY.md.
Released under the MIT License.