Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@digitregroup/paypal-rest-sdk

paypal54SEE LICENSE IN https://github.com/paypal/PayPal-node-SDK/blob/master/LICENSE1.8.2

SDK for PayPal REST APIs

paypal, rest, api, sdk

readme

PayPal REST SDK

Continuous integration status:

Build Status Coverage Status Gitter chat

NPM status:

NPM version Dependency Status

Repository for PayPal's Node SDK (node.js version >=0.6.x) and Node samples for REST API. For a full working app and documentation, have a look at the PayPal Node SDK Page.

2.0 Beta: We now have a 2.0 beta available, featuring promise support, and a revamped integration. Check out the 2.0-beta branch for details, or run npm install paypal-rest-sdk@beta.

v1.0.0 notice: If upgrading from paypal rest sdk 0.*, Please view Breaking Changes in release_notes.md

The Payment Card Industry (PCI) Council has mandated that early versions of TLS be retired from service. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, PayPal is updating its services to require TLS 1.2 for all HTTPS connections. At this time, PayPal will also require HTTP/1.1 for all connections. See the PayPal TLS Update repository for more information.

**TLSv1_2 warning: Due to PCI compliance, merchant servers using a version of TLS that does not support TLSv1_2 will receive a warning.

**To verify that your server supports PCI compliant version of TLS, test against the PayPal sandbox environment which uses TLS 1.2.

Direct Credit Card Support

Important: The PayPal REST API no longer supports new direct credit card integrations. Please instead consider Braintree Direct; which is, PayPal's preferred integration solution for accepting direct credit card payments in your mobile app or website. Braintree, a PayPal service, is the easiest way to accept credit cards, PayPal, and many other payment methods.

PayPal Checkout v2

Please note that if you are integrating with PayPal Checkout, this SDK and corresponding API v1/payments are in the process of being deprecated.

We recommend that you integrate with API v2/checkout/orders and v2/payments. Please refer to the Checkout Node.js SDK to continue with the integration.

2.0 Release Candidate!

We're releasing a brand new version of our SDK! 2.0 is currently at release candidate status, and represents a full refactor, with the goal of making all of our APIs extremely easy to use. 2.0 includes all of the existing APIs (except payouts), and includes the new Orders API (disputes and Marketplace coming soon). Check out the FAQ and migration guide, and let us know if you have any suggestions or issues!

Installation

npm install paypal-rest-sdk

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-rest-sdk' in your package.json file.
  • Require 'paypal-rest-sdk' in your file

    var paypal = require('paypal-rest-sdk');
  • 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, callback).

    `js var create_payment_json = {

    "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."
    }]

    };

paypal.payment.create(create_payment_json, function (error, payment) {
    if (error) {
        throw error;
    } else {
        console.log("Create Payment Response");
        console.log(payment);
    }
});
```
  • 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", function(error, tokeninfo){
      console.log(tokeninfo);
    });
    
    // Get tokeninfo with Refresh code
    paypal.openIdConnect.tokeninfo.refresh("Replace with refresh_token", function(error, tokeninfo){
      console.log(tokeninfo);
    });
    
    // Get userinfo with Access code
    paypal.openIdConnect.userinfo.get("Replace with access_code", function(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

  • As of version 1.6.2, 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] (https://developer.paypal.com/webapps/developer/docs/api/)

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.

changelog

PayPal Node SDK release notes

v1.8.1

  • Revert HTTP config host precedence order change due to issue with some configs.

v1.8.0

  • Use PAYPAL_DEBUG instead of NODE_ENV to print debug messages #289.
  • Handler whitespaces only for response body #286.
  • Validate mode to be either sandbox or live #269.
  • HTTP config host precedence order set as other configs #231.
  • Remove unnecessary setting of PayPal-Request-Id.
  • Remove deprecated samples, and other minor bug fixes.

v1.7.1

  • Update credit card vault URL to /v1/vault/credit-cards/ #222.
  • Fix access token caching when using refresh token config #226.

v1.7.0

  • Updated Webhooks Verify event.
  • Invoicing API updates #204.
  • Minor bug fixes.

v1.6.9

  • Added new Third Party Invoicing sample #157.
  • Use default headders for OAuth calls #155.
  • Modify default start_date for Billing Agrement create sample #138.
  • Fix a typo in inline documentation #135.

v1.6.8

  • Deprecate webhookEvent.getAndVerify(). Instead, it is recommended that the webhook event handler issue a GET to retrieve the event data from the PayPal servers directly. See the Webhook Validation wiki.

v1.6.7

v1.6.6

  • Update warning message.

v1.6.5

  • Check OpenSSL version is 1.0.1 or above.

v1.6.4

  • Security test sandbox endpoint avaiable as a configuration.
  • Warn if merchant server has below 1.0 version of OpenSSL.
  • Update User Agent with crypto lib version.

v1.6.3

  • Update to uuid module for #106.

v1.6.2

  • Full request/response logged for non production environments with NODE_ENV=development set.
  • Update travis to build for Node 4.0.

v1.6.1

  • Openid userinfo header patch.

v1.6.0

  • Webhook events have getAndVerify available for validation.
  • Fix for credential resolution.
  • Improve debug id triaging and json parse error handling message.
  • Vault list all credit cards feature.
  • Patches to make easier use with Browserify.

v1.5.3

  • Webhook validation update patch.

v1.5.2

  • Content-Type Header parsing fix.
  • Merge updated.
  • NODE_ENV=development provides stringified response.

v1.5.1

  • utils.merge patch for empty header, fixes #69 and #70.
  • Automate JSDoc generation via Travis.

v1.5.0

  • Payouts cancel feature added.
  • Execute billing agreements more configurable.
  • Consolidate configuration of tests and samples.
  • JSDocs for most resource functions.

v1.4.0

  • Access token persistance added for performance boost in multiple client scenerios.
  • Add JSDoc for modules and refactor mixin method for rest objects.

v1.3.1

  • Version read from package.json for User Agent.

v1.3.0

  • Payouts API support added.
  • Samples documentation updated.

v1.2.2

  • Search transactions for billing agreements patched.

v1.2.1

  • User Agent conforms to new naming conventions.

v1.2.0

  • Webhook and Webhook events creation and management supported.
  • Verification that webhook events are unaltered and originate from PayPal.

v1.1.0

  • Payment Experience customizaton feature added via API for Web Profiles.

v1.0.1

  • Update Paypal-Client-Metadata-Id header for future payments.
  • Subscription API changes for searching transactions and listing billing plans.

v1.0.0

Features

  • Subscription API support added.
  • Order/Auth/Capture support added.
  • Update credit card support added for vault.
  • Test/samples added for extra payment parameters.
  • activate method added for billing plans.

Breaking changes

  • Exported methods are now camelCased instead of underscored in 0.* versions.
  • delete is now del.
  • support still maintained for above changes for compatibility with 0.* versions.

Refactoring

  • Modularize into components api, client, config and utils.
  • Rest api resources separated into own functions/classes.
  • generate has the factory of rest methods attached to object literals e.g creditCard, reducing duplication.
  • Exported methods named and CamelCased across sdk, closer to JavaScript conventions, closes #34 and #35.
  • Test coverage increased.

v0.9.1

  • Fix for toggling host by using mode in config.

v0.9.0

  • Unit tests can run as mock mode.
  • Mode configuration for easier toggling between live/sandbox.
  • NODE_ENV=development can be added for getting debug-id.

v0.8.0

  • Invoicing API support added.
  • Added tests and samples for using the invoicing api via the sdk.
  • Modules pinned to versions for package.json.

v0.7.0

  • Future Payments support added.
  • Linting.

v0.6.4

  • Fixed content length to support utf-8 characters.

v0.6.3

  • Added support for Reauthorization.

v0.6.2

  • Update HTTP User-Agent.

v0.6.1

  • Allow payment.list with parameters.