The Transfa Node SDK provides methods and resources for interacting with the Transfa API in TypeScript applications.
For more detailed information about the API, refer to the Node API documentation.
You can install the SDK via npm or yarn:
For yarn
users:
yarn add transfa-node-sdk
For npm
users:
npm install transfa-node-sdk
- Node.js 16.0 or higher
import { TransfaAPIClient } from 'transfa-node-sdk';
const transfaClient = new TransfaAPIClient("YOUR_API_KEY", "YOUR_WEBHOOK_SECRET");
When making a payment request to the Transfa API, ensure to provide a unique idempotency key in the header of each request. This key helps maintain uniqueness and prevents duplicate payment objects in the database.
Example:
transfaClient.Payment.requestPayment({
account_alias: "60201010",
amount: 5000,
mode: "mtn-benin",
webhook_url: "https://your_app_url.domain/your_webhook_endpoint/",
});
transfaClient.Payment.retrieve("your payment id");
transfaClient.Payment.status("your payment id");
transfaClient.Payment.refund("your payment id");
transfaClient.Payment.list();
To receive updates about your payments via webhook, ensure your organization supports the webhook feature and provide a webhook URL. Transfa sends data to this URL whenever there is an update regarding your payments. Before processing the payload of a webhook request, verify its authenticity using the X-Webhook-Transfa-Signature
parameter in the request headers.
The SDK provides a Webhook
class to handle verification. Here's an example of how to use it:
const requestHandler = (req, res) => {
let webhookPayload = req.body; // Get webhook payload
webhookPayload = transfaClient.Webhook.verify(req.body, req.headers);
if (!webhookPayload) {
res.status(401).json({ details: "Unauthorized" });
}
res.json({ details: true });
}
Ensure to integrate this verification process into your webhook endpoint handling logic.
This documentation provides essential guidance for integrating and utilizing the Transfa Node SDK in your TypeScript applications.