waafipay
v0.0.2
Published
WaafiPay's official node sdk
Downloads
76
Maintainers
Readme
WaafiPay Node SDK
The official Node SDK for interacting with the WaafiPay payment gateway
Installation
Install the package using npm:
npm i waafipay
Usage
Initialize the Client
To start using the package, you need to initialize the WaafiPayClient
with your credentials and environment settings:
import { WaafiPayClient } from "waafipay";
const client = new WaafiPayClient({
apiKey: "API-669892958AHX", // Your API key provided by WaafiPay
storeId: 1000312, // Store ID / User ID provided by WaafiPay
merchantUID: "M0912255", // Your unique merchant identifier provided by WaafiPay
environment: "sandbox", // Use "production" for live environments
});
Create a Pamyent
You can create a payment by calling the createPayment
method:
(async () => {
try {
const paymentResponse = await client.createPayment({
accountNumber: "252615112233", // Mandatory, use international format without the leading "+" sign
referenceId: "123456789", // Unique reference ID from your system
amount: 10, // Required
description: "Order payment for invoice #123", // Required
paymentMethod: "WALLET", // Custom value, mapped internally to MWALLET_ACCOUNT
// Optional fields:
// invoiceId: "154",
// currency: "EUR",
});
console.log("Payment Response:", paymentResponse);
} catch (error) {
console.error("Error:", error);
}
})();
Example Payment Response
Here’s an example of the response you can expect from the createPayment
method:
{
"schemaVersion": "1.0",
"timestamp": "2024-12-05 09:04:44.741",
"responseId": "12314",
"responseCode": "2001",
"errorCode": "0",
"responseMsg": "RCS_SUCCESS",
"params": {
"accountNo": "252615****2233",
"accountType": "MWALLET_ACCOUNT",
"state": "APPROVED",
"merchantCharges": "0.1",
"referenceId": "1234",
"transactionId": "1268666",
"issuerTransactionId": "ISR0011268666",
"txAmount": "10.0"
}
}
Configuration Options
The WaafiPayClient
requires the following configuration options:
| Option | Type | Description |
| ------------- | --------------------------- | ---------------------------------------------------------------------- |
| apiKey
| string
| Your API key for authentication. |
| merchantUID
| string
| Your unique merchant identifier. |
| storeId
| number
| The store ID or User ID associated with your merchant account. |
| environment
| "sandbox" \| "production"
| The environment to use (sandbox
for testing, production
for live). |
Features
- Environment-Specific Endpoints: Automatically switches between sandbox and production environments.
- Simplified Payment Requests: Create payments with minimal configuration.
- Custom Payment Methods: Accepts
WALLET
andBANK
as simplified payment methods and maps them to the required API values. - TypeScript Support: Strongly typed interfaces for easy development.
Roadmap
- Implement the rest of WaafiPay APIs.
- Include transaction history retrieval.
- Expand error handling and reporting.
License
This project is licensed under the MIT License. See the LICENSE file for details.