1.0.15 • Published 2 months ago

telebirr-sdk v1.0.15

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

Telebirr Mobile Wallet Payment API Integration

This npm package facilitates seamless integration with the Telebirr Mobile Wallet payment API, empowering developers to effortlessly incorporate Telebirr's payment capabilities into their Node.js applications.

Installation

You can install the package via npm:

npm install telebirr-sdk

Usage

Initialize

First, initialize the Telebirr payment API with your API credentials:

import { Telebirr } from 'telebirr-sdk';

const telebirr = new Telebirr(appId, appKey, shortCode, publicKey);

Encrypt Payload

Encrypt a payload using the provided encryption method:

const encryptedData = telebirr.encrypt({
  nonce: 'unique_nonce',
  outTradeNo: 'transaction_id',
  returnUrl: 'return_url',
  subject: 'payment_subject',
  timeoutExpress: 'timeout_express',
  timestamp: 'timestamp',
  totalAmount: 'total_amount',
  receiveName: 'receiver_name', // optional
  notifyUrl: 'notification_url', // optional
});

Sign Data

Sign the payload data for security purposes:

const signature = telebirr.signData({
  nonce: 'unique_nonce',
  outTradeNo: 'transaction_id',
  returnUrl: 'return_url',
  subject: 'payment_subject',
  timeoutExpress: 'timeout_express',
  timestamp: 'timestamp',
  totalAmount: 'total_amount',
  receiveName: 'receiver_name', // optional
  notifyUrl: 'notification_url', // optional
});

Initialize Web Payment

Initiate a web payment transaction:

Use signature as a value of sign and encryptedData as a value of ussd when you initiate payment.

telebirr.initWebPayment(url, sign, ussd)
  .then(response => {
    console.log("Response from Telebirr:", response);
    // Handle successful response here
  })
  .catch(error => {
    console.error("Error from Telebirr:", error);
    // Handle error here
  });

Example Response

Upon successful request, the API returns a response like this:

code 0 always indicates success

{
  "code": 0,
  "msg": "success",
  "data": {
    "toPayUrl": "https://h5pay.trade.pay/payId=RE9879T0972S"
  }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Variables and Types

VariableTypeRequiredDescription
appIdstringYesApplication ID provided by Telebirr
appKeystringYesApplication key provided by Telebirr
shortCodestringYesShort code provided by Telebirr
publicKeystringYesPublic key provided by Telebirr
noncestringYesUnique nonce for the transaction
outTradeNostringYesUnique identifier for the transaction
returnUrlstringYesURL to redirect after payment completion
subjectstringYesSubject of the payment
timeoutExpressstringYesTimeout duration for the payment
timestampstringYesTimestamp of the transaction
totalAmountstringYesTotal amount of the transaction
receiveNamestringNoName of the receiver (optional)
notifyUrlstringNoURL for receiving payment notifications (optional)

Please replace appId, appKey, shortCode, and publicKey with the actual values provided by Telebirr. Adjust the usage examples and descriptions according to your package's specific functionalities.

1.0.15

2 months ago