paypal-nvp-api
Node.js wrapper for the Paypal Name-Value Pair — NVP
Usage
import Paypal from 'paypal-nvp-api';
let config = {
mode: 'sandbox', // or 'live'
track: 'https://www.sandbox.paypal.com', // or 'https://www.paypal.com' if live
username: 'someone.itravellocal.com',
password: 'DYKNJZZE42ASN699',
signature: 'A0aEilikhBmwfK.NlduDjCbsdgXdA8VDPMDksDhGsHmLQECu80Qtru09'
}
let paypal = Paypal(config);
let query = {
'PAYMENTREQUEST_0_AMT': '20.00',
'PAYMENTREQUEST_0_CURRENCYCODE': 'USD',
'PAYMENTREQUEST_0_PAYMENTACTION': 'Sale'
}
paypal.request('SetExpressCheckout', query).then((result) => {
console.log(result);
}).catch((err) => {
console.trace(err);
});
Replace SetExpressCheckout with any available API operation that Paypal supports.
Replace username, password and signature with your Paypal app credential Set.
For more info:
API reference
request(String method, Object query)
In which:
-
method: one of API operations Paypal NVP supports, such as SetExpressCheckout, DoCapture, SetCustomerBillingAgreement, etc.
-
query: a set of parameters you want to send to Paypal API endpoint, relying on which method is being used.
formatCurrency(Number amount)
You can use this util to quickly convert a number to standard currency format that fits Paypal convention.
Return: a string in the format of X,XXX,XX.XX (used in United States, Canada).
paypal.formatCurrency(123456); // = '123,456.00'
paypal.formatCurrency(12345); // = '12,345.00'
paypal.formatCurrency(1234); // = '1,234.00'
paypal.formatCurrency(12); // = '12.00'
paypal.formatCurrency(12.5); // = '12.50'
paypal.formatCurrency('12.00'); // = '12.00'
Test
Module has not been fully tested yet.