A NodeJS SDK for the UniPayment API.
This SDK provides a convenient abstraction of UniPayment's Gateway API and allows developers to focus on payment flow/e-commerce integration rather than on the specific details of client-server interaction using the raw API.
Before using the UniPayment API, sign up for your API key.
You can also use our test tokens for testing and integration. Documentation.
- Download the package and extract it into a local directory or clone the repo.
- copy unipaymentsdk
npm install unipayment-sdkconfiguration.json
{
"apiHost": "https://api.unipayment.io",
"clientId": "your client id",
"clientSecret": "you client secret",
"appId": "your app id",
"apiVersion": "1.0"
}const {BeneficiaryAPI, BillingAPI, CommonAPI, ExchangeAPI, PaymentAPI, WalletAPI} = require('unipayment-sdk');
Reference:https://unipayment.readme.io/reference/authentication
To authenticate your application, you need to obtain an access token by making a request to our OAuth 2.0 token endpoint. This request must include your client_id, client_secret, and the grant_type.
Reference:https://unipayment.readme.io/reference/create_invoice
const {v4: uuidv4} = require('uuid');
const {BillingAPI} = require('unipayment-sdk');
const billingAPI = new BillingAPI(configuration);
const createInvoiceRequest = {
'app_id': configuration.appId,
'order_id': uuidv4(),
'price_amount': 1.00,
'price_currency': 'USD',
'lang': 'en',
'ext_args': 'Merchant Pass Through Data'
};
billingAPI.createInvoice(createInvoiceRequest).then(response => {
printResponse(response);
assert.equal(response.data.code === 'OK', true);
done();
}).catch(error => {
done();
console.log(error);
}){
"msg": "",
"code": "OK",
"data": {
"app_id": "df01ae1f-8c31-4ecd-8ab1-9e31289d4823",
"payment_method_type": "UNKNOWN",
"invoice_id": "88144dSLPujPsUJYakkJdx",
"order_id": "ORDER_1721023791051",
"price_amount": 2.0,
"price_currency": "USD",
"network": null,
"address": null,
"pay_amount": 0.0,
"pay_currency": null,
"exchange_rate": 0.0,
"paid_amount": 0.0,
"refunded_price_amount": 0.0,
"create_time": "2024-07-15T06:09:54",
"expiration_time": "2024-07-15T06:29:54",
"confirm_speed": "Medium",
"status": "New",
"error_status": "None",
"invoice_url": "https://sandbox.api.unipayment.com/i/88144dSLPujPsUJYakkJdx"
}
}Invoice Status: https://unipayment.readme.io/reference/invoice-status
IPNs (Instant Payment Notifications) are sent to the notify_url when order status is changed to paid, confirmed and complete.
const {CommonAPI} = require('unipayment-sdk');
const commonAPI = new CommonAPI(configuration);
const notify = 'notify from unipayment'
commonAPI.checkIpn(notify).then(response => {
printResponse(response);
assert.equal(response.data.code === 'OK', true);
assert.equal(response.data.msg === 'IPN is verified.', true)
done();
}).catch(error => {
done();
console.log(error);
})IPN notify
{
"ipn_type": "invoice",
"event": "invoice_expired",
"app_id": "cee1b9e2-d90c-4b63-9824-d621edb38012",
"invoice_id": "3Q7fyLnB2YNhUDW1fFNyEz",
"order_id": "20",
"price_amount": 6.0,
"price_currency": "SGD",
"network": null,
"address": null,
"pay_currency": null,
"pay_amount": 0.0,
"exchange_rate": 0.0,
"paid_amount": 0.0,
"confirmed_amount": 0.0,
"refunded_price_amount": 0.0,
"create_time": "2022-09-12T03:36:03",
"expiration_time": "2022-09-12T03:41:03",
"status": "Expired",
"error_status": "None",
"ext_args": null,
"transactions": null,
"notify_id": "8ccd2b61-226b-48e5-99b8-acb1f350313e",
"notify_time": "2022-09-12T03:56:10.5852752Z"
}See https://unipayment.readme.io/reference/webhook
Use the below code to verify of the 'hmac_signature' which can extract from the request header
const {WebhookSignatureUtil} = require('unipayment-sdk');
//Use raw json payload (no formatting or pretty print)
const payload = 'json payload';
const secretKey = 'your secret key';
const signature = 'signature to verify';
const valid = WebhookSignatureUtil.isValid($payload, $secretKey, $signature);1.Get source code form GitHub
git clone https://github.com/UniCryptoLab/UniPaymentClient.Node.git3.Run test
npm testMIT License
Copyright (c) 2024 UniPayment
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.