npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

agile-pay

v1.0.0-beta

Published

AgilePay node sdk

Downloads

14

Readme

AgilePay Node.js SDK

The AgilePay Node node.js SDK provides a convenient access to the AgilePay API from applications written in server-side JavaScript.

This package is promise based with promises in mind instead of callback approach.

You can use the promise style or async await style.

Please keep in mind that this package is for use with server-side Node that uses AgilePay secret keys. This package should not be used on the client side. Also note that this package is still in development.

Documentation

See the Node API docs.

Installation

Install the package with:

npm install agile-pay --save

Usage

  • Register for an account and get your key and secret at AgilePay.
  • Add dependency 'agile-pay' in your package.json file.
  • Require 'agile-pay' in your file
const agilePay = require('agile-pay')

const client = new agilePay({
  'api_key': 'key',
  'api_secret': 'secret'
});

Gateways

To create a new gateway :

promise example:

agilePay.gateway().create('stripe', { 'secret_key': 'stripe-secret-key' })
  .then(res => res.getBody())
  .catch(err => err.getStatusCode()));

async await examples:

(async function () {
  try {
    const response = await agilePay.gateway().create('stripe', { 'secret_key': 'stripe-secret-key' });
    console.log(response.getStatusCode());
  } catch (error) {
    console.log(error.getStatusCode());
  }
})();

or

async function gateway() {
  try {
    const response = await agilePay.gateway().create('stripe', { 'secret_key': 'stripe-secret-key' });
    console.log(response.getStatusCode());
  } catch (error) {
    console.log(error.getStatusCode());
  }
}

gateway();

Payment methods

To create a new payment method type of gateway token:

In this case the payment method will be retained with the provided gateway, please check the availability of transaction store in the gateways

Gateways list -> http://docs.agilepay.io/#!/gateway

Gateway token -> http://docs.agilepay.io/#!/payment-method-create-gateway-token

promise example:

agilePay.paymentMethod().createGatewayToken('gateway-reference', {
  number: '4111111111111111',
  expiry_year: 17,
  expiry_month: 12,
  cvv: 123,
  holder_name: 'John Smith',
})
  .then(res => res.getBody().token)
  .catch(res => {
  // something went wrong
  });

async await examples:

(async function () {
  try {
    const gatewayToken = await agilePay.paymentMethod().createGatewayToken('gateway-reference', {
      number: '4111111111111111',
      expiry_year: 17,
      expiry_month: 12,
      cvv: 123,
      holder_name: 'John Smith',
    });

// The response will contain a payment method **token** which is used to perform transactions against the payment method
  const token = gatewayToken.getBody().token;

  } catch (err) {
    // something went wrong
  }
})();

or

async function gatewayToken() {
  try {
    const gatewayToken = await agilePay.paymentMethod().createGatewayToken('gateway-reference', {
      number: '4111111111111111',
      expiry_year: 17,
      expiry_month: 12,
      cvv: 123,
      holder_name: 'John Smith',
    });

// The response will contain a payment method **token** which is used to perform transactions against the payment method
    const token = gatewayToken.getBody().token;
    return token;

  } catch (err) {
    // something went wrong
  }
}

gatewayToken();

Transactions

Auth (Charge a credit card with a payment method type of gateway token):

promise example:

agilePay.transaction()
  .setPaymentMethod('payment-method-token')
  .auth(5000, 'GBP')
  .then(res => {

    if (res.getBody().successful) {
      // the authorisationwas successful
    } else {
      // the gateway responded with some errors
      res.getBody().errors;
    }

  })
  .catch(res => {
  // something went wrong
  });

async await example:

async function transactionReference() {
  try {
    const transaction = await agilePay.transaction()
    .setPaymentMethod('payment-method-token')
    .auth(5000, 'GBP');

    if (transaction.getBody().successful) {
      const transaction = transaction.getBody().successful;
      return transaction;
    } else {
      const error = transaction.getBody().errors;
      return error
    }

  } catch (err) {
    // something went wrong
  }
}

// The response will contain a **reference** which can be used for second steps transactions such as **void**, **capture** and **refund**
transactionReference();

Void (Cancel an authorized transaction):

agilePay.transaction('authorised-transaction-reference').void()
  .then(res => {
    if (res.getBody().successful) {
    // the pre-authorisation has been successfully cancelled
    }
  }).catch(res => {
  // something went wrong
  });

Capture (Settle an authorized transaction):

agilePay.transaction('authorised-transaction-reference').capture()
  .then(res => {
    if (res.getBody().successful) {
    // the pre-authorisation has been successfully cancelled
    }
  }).catch(res => {
  // something went wrong
  });

Credit (Refund a settled transaction):

agilePay.transaction('authorised-transaction-reference').credit()
  .then(res => {
    if (res.getBody().successful) {
    // the pre-authorisation has been successfully cancelled
    }
  }).catch(res => {
  // something went wrong
  });

Response methods

Below the response object available methods.

getRaw()

Retrieves the entire response

getBody()

Retrieves the response body

getStatusCode()

Retrieves the response status code

Credits

A big thanks to Ary Homebrew for the huge contribution he has given to this package.