2.18.0 • Published 16 days ago
smartypay-node-sdk v2.18.0
SMARTy Pay Node SDK
Simple library for creating invoices on backend side
Installation
npm i smartypay-node-sdk
Usage
Create invoice
import {SmartyPayAPI} from 'smartypay-node-sdk';
async function createInvoice() {
// call API
const api = new SmartyPayAPI({
secretKey: 'YOUR_SECRET_KEY',
publicKey: 'YOUR_API_KEY',
});
const invoice = await api.invoices.createInvoice({
expiresAt: new Date(Date.now() + 1000 * 60 * 60), // after 1 hour from now
amount: '1.99',
token: 'bUSDT',
metadata: 'YOUR_PURCHASE_ID' // optional
});
// result invoice id
const invoiceId = invoice.id;
// params to open invoice
const params = new URLSearchParams();
params.set('invoice-id', invoiceId);
// additional params:
// params.set('name', 'Item Name to Buy');
// params.set('success-url', 'https://...');
// params.set('fail-url', 'https://...');
// final url be like "https://checkout.smartypay.io/invoice?invoice-id=XXXXXXX"
const urlToRedirect = 'https://checkout.smartypay.io/invoice?' + params.toString();
}
- expiresAt - date before invoice is active
- amount - amount for invoice (example 0.99)
- token - see valid tokens here: https://docs.smartypay.io/general/supported-tokens
- metadata - optional field for any custom metadata (usually it's your own purchase id for success webhook)
- secretKey - you can get it here: https://dashboard.smartypay.io/
- publicKey - you can get it here: https://dashboard.smartypay.io/
Create client's recharge address
import {SmartyPayAPI} from 'smartypay-node-sdk';
async function createRechargeAddress(customerId: string) {
// call API
const api = new SmartyPayAPI({
secretKey: 'YOUR_SECRET_KEY',
publicKey: 'YOUR_API_KEY',
});
const resp = await api.recharges.createRechargeAddress({
token: 'bUSDT',
customerId: customerId,
});
// recharge address for your customerId
const rechargeAddress = resp.address;
}
- token - see valid tokens here: https://docs.smartypay.io/general/supported-tokens
- customerId - customer's id from your own system
- secretKey - you can get it here: https://dashboard.smartypay.io/
- publicKey - you can get it here: https://dashboard.smartypay.io/
Check webhook signature
function isValidWebhook( resp: Respone){
// See: https://docs.smartypay.io/api/webhooks
const body: string = resp.body;
const signature: string = resp.heades['x-api-digest'];
return SmartyPayAPI.utils.isValidSignature(body, signature, 'YOUR_SECRET_KEY');
}
Full API docs
Checkout our TypeDocs
Build steps
Clone repository into your dir
cd your_dir
git clone https://github.com/smarty-pay/smartypay-node-sdk
Build
npm install
npm run build
2.18.0
16 days ago
2.17.0
2 months ago
2.16.1
5 months ago
2.16.0
6 months ago
2.15.0
9 months ago
2.13.0
10 months ago
2.12.1
10 months ago
2.14.0
10 months ago
2.12.0
10 months ago
1.2.0
1 year ago
1.1.1
1 year ago
2.3.0
1 year ago
2.2.0
1 year ago
2.4.0
1 year ago
1.0.10
1 year ago
2.0.0
1 year ago
1.0.7
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago