1.2.0 • Published 5 months ago

payrex-node v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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
}
1.2.0

5 months ago

1.0.2

5 months ago

1.1.0

5 months ago

1.0.1

10 months ago

1.0.0

11 months ago

0.1.7

12 months ago

0.1.6

12 months ago

0.1.5

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago