Skip to content

Transfa/transfa-node-sdk

Repository files navigation

transfa-node-sdk

The Transfa Node SDK provides methods and resources for interacting with the Transfa API in TypeScript applications.

Documentation

For more detailed information about the API, refer to the Node API documentation.

Installation

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

Requirements

  • Node.js 16.0 or higher

Getting Started

Initialize Transfa Node SDK Instance

import { TransfaAPIClient } from 'transfa-node-sdk';

const transfaClient = new TransfaAPIClient("YOUR_API_KEY", "YOUR_WEBHOOK_SECRET");

Request a Payment

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/",
});

Retrieve a Single Payment

transfaClient.Payment.retrieve("your payment id");

Get the Status of a Payment

transfaClient.Payment.status("your payment id");

Refund a Payment

transfaClient.Payment.refund("your payment id");

List All Payments

transfaClient.Payment.list();

Verify Webhook

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.

About

Official Node SDK that makes integration with the Transfa API easier.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •