SDK for PayPal REST APIs
Continuous integration 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.
v1.0.0 notice: If upgrading from paypal rest sdk 0.*, Please view Breaking Changes in release_notes.md
Before starting to use the sdk, please be aware of the existing issues and currently unavailable or upcoming features for the REST APIs. (which the sdks are based on)
npm install paypal-rest-sdk
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).
paypalconfigure'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: store a credit card) with required parameters (eg: data, config_options, callback).
var card_data ="type": "visa""number": "4417119669820331""expire_month": "11""expire_year": "2018""cvv2": "123""first_name": "Joe""last_name": "Shopper";paypalcreditCardcreatecard_dataif errorconsole.logerror;throw error;elseconsole.log"Create Credit-Card Response";console.logcredit_card;
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.
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.
To use OpenID Connect
// OpenID configurationpaypalconfigure'openid_client_id': 'CLIENT_ID''openid_client_secret': 'CLIENT_SECRET''openid_redirect_uri': '' ;// Authorize urlpaypalopenIdConnectauthorizeUrl'scope': 'openid profile';// Get tokeninfo with Authorize codepaypalopenIdConnecttokeninfocreate"Replace with authorize code"console.logtokeninfo;;// Get tokeninfo with Refresh codepaypalopenIdConnecttokeninforefresh"Replace with refresh_token"console.logtokeninfo;;// Get userinfo with Access codepaypalopenIdConnectuserinfoget"Replace with access_code"console.loguserinfo;;// Logout urlpaypalopenIdConnectlogoutUrl"Replace with tokeninfo.id_token";
Instructions for running samples are located in the sample directory. Try these samples in a live sandbox environment:
To run the test suite first invoke the following command within the repo
If mocha is not installed
npm install -g mocha
and then to install the development dependencies:
then run the tests:
[REST API Reference] (https://developer.paypal.com/webapps/developer/docs/api/)