Coder Social home page Coder Social logo

paypal-node-sdk-v2's Introduction

PayPal Node SDK

NPM status:

NPM version Dependency Status

Repository for PayPal's Node SDK V2 and Node samples for REST API. For a full working app and documentation, have a look at the PayPal Node SDK V2 Page.

Resource support

###V1

Notification (webhooks) ✅

###V2

Order ✅

Notice: All other resources work with v1 that might be deprecated.

Releases

2.0

  • Uses async functions, so you can use await or Promises
  • Now supports the subscription API

Installation

npm install paypal-node-sdk-v2

Usage

To write an app using the SDK

  • Register for a developer account and get your client_id and secret at PayPal Developer Portal.

  • Add dependency paypal-node-sdk-v2 in your package.json file.

  • Require paypal-node-sdk-v2 in your file

    var paypal = require('paypal-node-sdk-v2');
  • Create config options, with parameters (mode, client_id, secret).

    paypal.configure({
      'mode': 'sandbox', //sandbox or live
      'client_id': 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
      'client_secret': 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'
    });
  • For multiple configuration support, have a look at the sample

  • Invoke the rest api (eg: create a PayPal payment) with required parameters (eg: data, config_options).

    var newPayment = {
        "intent": "sale",
        "payer": {
            "payment_method": "paypal"
        },
        "redirect_urls": {
            "return_url": "http://return.url",
            "cancel_url": "http://cancel.url"
        },
        "transactions": [{
            "item_list": {
                "items": [{
                    "name": "item",
                    "sku": "item",
                    "price": "1.00",
                    "currency": "USD",
                    "quantity": 1
                }]
            },
            "amount": {
                "currency": "USD",
                "total": "1.00"
            },
            "description": "This is the payment description."
        }]
    };
    
    var payment = await paypal.payment.create(newPayment);
  • For creating Subscription Payments, check out the samples for creating planned sets of future recurring payments at periodic intervals.

  • To create Future Payments, check out this sample for executing future payments for a customer who has granted consent on a mobile device.

  • For exploring additional payment capabilites, such as handling discounts, insurance, soft_descriptor and invoice_number, have a look at this example. These bring REST payment functionality closer to parity with older Merchant APIs.

  • Customizing a PayPal payment experience is available as of version 1.1.0 enabling merchants to provide a customized experience to consumers from the merchant’s website to the PayPal payment. Get started with the supported rest methods and samples.

  • For creating and managing Orders, i.e. getting consent from buyer for a purchase but only placing the funds on hold when the merchant is ready to fulfill the order, have a look at samples.

  • For creating batch and single payouts, check out the samples for payouts and payout items. The Payouts feature enables you to make PayPal payments to multiple PayPal accounts in a single API call.

  • For Invoicing, check out the samples to see how you can use the node sdk to create, send and manage invoices.

  • To receive notifications from PayPal about Payment events on your server, webhook support is now available as of version 1.2.0. For creating and managing Webhook and Webhook Events, check out the samples to see how you can use the node sdk to manage webhooks, webhook events and verify that the response unaltered and is really from PayPal. Please follow the Webhook Validation sample to understand how to verify the authenticity of webhook messages. It is also important to note that simulated messages generated using the Webhook simulator would not be compatible with the verification process since they are only mock data.

  • To use OpenID Connect

    // OpenID configuration
    paypal.configure({
      'openid_client_id': 'CLIENT_ID',
      'openid_client_secret': 'CLIENT_SECRET',
      'openid_redirect_uri': 'http://example.com' });
    
    // Authorize url
    paypal.openIdConnect.authorizeUrl({'scope': 'openid profile'});
    
    // Get tokeninfo with Authorize code
    paypal.openIdConnect.tokeninfo.create("Replace with authorize code", (error, tokeninfo) => {
      console.log(tokeninfo);
    });
    
    // Get tokeninfo with Refresh code
    paypal.openIdConnect.tokeninfo.refresh("Replace with refresh_token", (error, tokeninfo) => {
      console.log(tokeninfo);
    });
    
    // Get userinfo with Access code
    paypal.openIdConnect.userinfo.get("Replace with access_code", (error, userinfo) => {
      console.log(userinfo);
    });
    
    // Logout url
    paypal.openIdConnect.logoutUrl("Replace with tokeninfo.id_token");

Running Samples

Instructions for running samples are located in the sample directory.

Running Tests

To run the test suite first invoke the following command within the repo

If Grunt is not installed:

npm install -g grunt-cli

If Mocha is not installed:

npm install -g mocha

To install the development dependencies (run where the package.json is):

npm install

Run the tests:

grunt test (timeout is specified in milliseconds eg: 15000ms)

To run the tests without the mocks:

NOCK_OFF=true mocha -t 60000

Debugging

  • Full request/response are logged for non production environments with PAYPAL_DEBUG set

    You can set the environment variable on the command line by running PAYPAL_DEBUG=1 node <path of script> or by executing export PAYPAL_DEBUG=1 and then running your Node.js script. Please see your command terminal/shell's manual pages for specific information.

  • It is recommended to provide Paypal-Debug-Id if requesting PayPal Merchant Technical Services for support. You can get access to the debug id by setting environment variable PAYPAL_DEBUG=1.

  • The error object returned for any bad request has error.response populated with details. PAYPAL_DEBUG=1 setting also gives you access to stringfied response in error messages.

Reference

REST API Reference

Contribution

  • If you would like to contribute, please fork the repo and send in a pull request.
  • Please ensure you run grunt before sending in the pull request.

License

Code released under SDK LICENSE

Contributions

Pull requests and new issues are welcome. See CONTRIBUTING.md for details.

paypal-node-sdk-v2's People

Contributors

avidas avatar prannamalai avatar siddick avatar tkanta avatar bluk avatar benbucksch avatar lvairamani avatar ganeshx avatar sankarbhavanib avatar braebot avatar jcleblanc avatar braintreeps avatar xiaoleih41 avatar jaypatel512 avatar bulkan avatar ppmtscory avatar impanda-cookie avatar dshaw avatar dasmall avatar jkingyens avatar krisbarrett avatar lathavairamani avatar night avatar neuralviva avatar prayagverma avatar rse avatar sahat avatar

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.