Giter VIP home page Giter VIP logo

paypal-nvp-api's Introduction

paypal-nvp-api

Node.js wrapper for the Paypal Name-Value Pair โ€” NVP

NPM CI test Coverage Status Quality Gate Status

Usage

Import module and init an instance with given config:

const Paypal = require('paypal-nvp-api');


const config = {
  mode: 'sandbox', // or 'live'
  username: 'someone.itravellocal.com',
  password: 'DYKNJZZE42ASN699',
  signature: 'A0aEilikhBmwfK.NlduDjCbsdgXdA8VDPMDksDhGsHmLQECu80Qtru09'
}

const paypal = Paypal(config);

Build query and send to Paypal server:

paypal.request('GetBalance', {}).then((result) => {
  console.log(result);
}).catch((err) => {
  console.trace(err);
});

The 'result' looks like this:

{
  L_AMT0: '71084.27',
  L_CURRENCYCODE0: 'USD',
  TIMESTAMP: '2016-03-18T09:48:16Z',
  CORRELATIONID: 'e3de6137ce65c',
  ACK: 'Success',
  VERSION: '124',
  BUILD: '18316154'
}

Another example with "SetExpressCheckout" operation:

const query = {
  'PAYMENTREQUEST_0_AMT': '20.00',
  'PAYMENTREQUEST_0_CURRENCYCODE': 'USD',
  'PAYMENTREQUEST_0_PAYMENTACTION': 'Sale',
  'RETURNURL': 'http://google.com/test/onreturn',
  'CANCELURL': 'http://google.com/test/oncancel'
};

paypal.request('SetExpressCheckout', query).then((result) => {
  console.log(result);
}).catch((err) => {
  console.trace(err);
});

In this case, it returns something like this:

{
  TOKEN: 'EC-5Y171147E8077933D',
  TIMESTAMP: '2016-03-18T09:58:38Z',
  CORRELATIONID: 'e8289e4235624',
  ACK: 'Success',
  VERSION: '124',
  BUILD: '18316154'
}

APIs

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.

For more info:

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

git clone https://github.com/ndaidong/paypal-nvp-api.git
cd paypal-nvp-api
npm install
npm test

License

The MIT License (MIT)

paypal-nvp-api's People

Contributors

bells17 avatar ndaidong avatar ruprict avatar ssowonny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

paypal-nvp-api's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.