payrex-node
v1.0.1
Published
PayRex Node JS Library
Downloads
33
Maintainers
Readme
PayRex Node.js
PayRex Node library provides Node applications an easy access to the PayRex API. Explore various classes that represents PayRex API resources on object instantiation.
Requirements
Node 12 or higher.
Installation
If you want to use the package, run the following command:
npm install payrex-node
# or
yarn add payrex-node
Getting Started
Simple usage looks like:
const payrex = require('payrex-node')('sk_test_...');
payrex.paymentIntents.retrieve('pi_...')
.then(paymentIntent => console.log(paymentIntent.id))
payrex.paymentIntents.create({
amount: 10000,
currency: 'PHP',
description: 'Dino Treat',
payment_methods: ['gcash', 'card']
})
.then(paymentIntent => console.log(paymentIntent.id))
Or using async/await:
const payrex = require('payrex-node')('sk_test_...');
const paymentIntent = await payrex.paymentIntents.retrieve('pi_...');
console.log(paymentIntent.id);
Handle errors
const payrex = require('payrex-node')('sk_test_...');
payrex.paymentIntents.create({
amount: 10000
})
.then(paymentIntent => console.log(paymentIntent.id))
.catch(error => {
// Handle errors
console.error(error.name);
console.error(error.errors);
});
Verify webhook signature
try {
payload = '{"id":"evt_...","resource":"event","type":"payment_intent.succeeded","data":{...';
signatureHeader = 't=1715236958,te=,li=...';
webhookSecretKey = 'whsk_...';
payrex.webhooks.parseEvent(payload, signatureHeader, webhookSecretKey);
} catch (error) {
// Handle invalid signature
}