JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 43
  • Score
    100M100P100Q84026F
  • License MIT

PayRex Node JS Library

Package Exports

  • payrex-node
  • payrex-node/src/Client.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (payrex-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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
}