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 =const client ='api_key': 'key''api_secret': 'secret';
Gateways
To create a new gateway :
promise
example:
agilePay);
async
await
examples:
{tryconst response = await agilePay;console;catch errorconsole;};
or
{tryconst response = await agilePay;console;catch errorconsole;};
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;
async
await
examples:
{tryconst gatewayToken = await agilePay;// The response will contain a payment method **token** which is used to perform transactions against the payment methodconst token = gatewayTokentoken;catch err// something went wrong};
or
{tryconst gatewayToken = await agilePay;// The response will contain a payment method **token** which is used to perform transactions against the payment methodconst token = gatewayTokentoken;return token;catch err// something went wrong};
Transactions
Auth (Charge a credit card with a payment method type of gateway token):
promise
example:
agilePay;
async
await
example:
{tryconst transaction = await agilePay;if transactionsuccessfulconst transaction = transactionsuccessful;return transaction;elseconst error = transactionerrors;return errorcatch err// something went wrong}// The response will contain a **reference** which can be used for second steps transactions such as **void**, **capture** and **refund**;
Void (Cancel an authorized transaction):
agilePay;
Capture (Settle an authorized transaction):
agilePay;
Credit (Refund a settled transaction):
agilePay;
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.