Node.JS library for accepting Micropayments
Install through npm
or yarn
See the API reference below for further information. There are two main functions to use, one is to create a commodity, and another is to validate a payment.
const micro = new Micro(
// Replace <CLIENT_ID> with your accounts' client id.
"<CLIENT_ID>",
// Replace <CLIENT_SECRET> with your accounts' client secret.
"<CLIENT_SECRET>",
{ apiVersion: 'v2' },
);
An example creating a new commodity to send to the client:
const commodity = await micro.Commodity.createCommodity(
accessToken,
116, // twin id,
{
cost: 25,
descriptor: 'EXAMPLE.COMMODITY',
dq: '410ddbac7c8a259da8dfcc5f55bcb28b77d29be9c540a2c23444b416d584801c30',
}
);
const commodity = await micro.Commodity.createCommodity(
accessToken,
116, // twin id,
{
cost: 25,
descriptor: 'EXAMPLE.COMMODITY',
dq: '410ddbac7c8a259da8dfcc5f55bcb28b77d29be9c540a2c23444b416d584801c30',
}
);
if (micro.Payment.validPayment(accessToken, hash, nonce)) {
// Payment is valid, perform paid action.
}