2Checkout Node.js Library
This library provides developers with a simple set of bindings to the 2Checkout Payment API, Hosted Checkout, Instant Notification Service and Admin API.
To use, download or clone the repository and install with npm.
git clone https://github.com/craigchristenson/2checkout-node.gitnpm install 2checkout-node
Then you can require the module and setup the 2Checkout object with a number of options shown below.
// Require the modulevar Twocheckout = ; // Pass in your private key and seller IDvar tco = apiUser: "APIuser1817037" // Admin API Username, required for Admin API bindings apiPass: "APIpass1817037" // Admin API Password, required for Admin API bindings sellerId: "1817037" // Seller ID, required for all non Admin API bindings privateKey: "3508079E-5383-44D4-BF69-DC619C0D9811" // Payment API private key, required for checkout.authorize binding secretWord: "tango" // Secret Word, required for response and notification checks demo: true // Set to true if testing response with demo sales sandbox: false // Uses 2Checkout sandbox URL for all bindings;
Example Purchase API Usage
Example Request:
// Setup the authorization objectvar params = "merchantOrderId": "123" "token": "MWQyYTI0ZmUtNjhiOS00NTIxLTgwY2MtODc3MWRlNmZjY2Jh" "currency": "USD" "total": "10.00" "billingAddr": "name": "Testing Tester" "addrLine1": "123 Test St" "city": "Columbus" "state": "Ohio" "zipCode": "43123" "country": "USA" "email": "example@2co.com" "phoneNumber": "5555555555" ; // Make the call using the authorization object and your callback functiontcocheckout;
Example Response:
Example Admin API Usage
Example Request:
tcosales;
Example Checkout Usage:
Example Request:
// Setup checkout paramsvar params = mode: '2CO' li_0_name: 'Test Product' li_0_price: '0.01'; // Get a URL encoded payment linkvar link = tcocheckoutlinkparams;
Example Response:
https://www.2checkout.com/checkout/purchase?mode=2CO&li_0_name=Test%20Product&li_0_price=0.01&sid=1817037
Example Return Usage:
Example Request (Using Express):
if tcoresponse 001 response; else response;
Example INS Notifications Usage:
Example Usage (Using Express):
if tconotification response; else response;
Exceptions:
Errors are returned as the first argument to your callback if they occur. It is best to always check for these before attempting to work with the response.
Example
tcocheckout;