Simple SDKs

eWAY is the easiest way to accept payments in your app or on your website. Get integrated and start selling more, faster - in a range of languages using the eWAY SDKs, helpful documentation, and 24/7 support from real humans. eWAY - with you every step of the way.

Node.js SDK


Accept payments quickly and easily with eWAY and Node.js using the eWAY Rapid Node.js SDK. Using the eWAY Node.js SDK provides convenient access to all the features of eWAY’s Rapid API, so you can create transactions, process refunds, query transactions, create token customers, and more!


Getting Started


Requirements

The eWAY Node.js SDK requires Node version 0.10 and requires bluebird, express-uri-template, lodash and request-promise. We recommend installing using the npm package manager to install it.

To make development and testing with eWAY easy, get a free partner account which provides access to the eWAY Sandbox.

Install

Using npm, the eWAY Node.js SDK can be installed with the following command:

  1. $ npm install eway-rapid

Build

Once installed, the eWAY Node.js SDK can be included in your project by requiring it:

  1. var rapid = require('eway-rapid');

Now you are all set to build your eWAY integration! You can find code samples for integrating various eWAY functions as part of the eWAY Rapid API reference 


Example Integration


To demonstrate adding the eWAY ​​Node.js SDK, this example will show how to accept a payment with the Responsive Shared Page

1. Add the eWAY Node.js SDK

In the project directory, run the npm command to install the eWAY Node.js SDK

  1. $ npm install eway-rapid

Once completed, the SDK and its dependencies will be downloaded and added to your project’s node_modules directory.

2. Load the eWAY Node.js SDK

In the file where you wish to initiate your eWAY transaction, add the eWAY SDK:

  1. var rapid = require('eway-rapid');

Now the eWAY client can be created with your Rapid API key & password. These can be found in Sandbox or Live MYeWAY – remember that different credentials are needed for sandbox to production.

  1. // eWAY Credentials
  2. var key     = 'A1001CTYCxgwTHvadCWKyV9m/ixKCimCqN/cv5/2+SiU0iNc267zZAdNMpqUkizVY9tG7J',
  3.     password = 's4nydboX',
  4.     endpoint = 'sandbox';

  5. // Create the eWAY Client
  6. var client = rapid.createClient(key, password, endpoint);

3. Create a Shared Payment URL


In order to send a customer to the Responsive Shared Page, a URL must be generated using the createTransaction function. This accepts a JSON object – more details of the variables that can be passed can be found in the
Rapid API reference

This step would usually take place after collecting the customer’s information in a checkout process. For this example, just some dummy data will be used:
 
  1. client.createTransaction(rapid.Enum.Method.RESPONSIVE_SHARED, {
  2.     "Payment": {
  3.         "TotalAmount": 100
  4.     },
  5.     // Change these to your server
  6.     "RedirectUrl": "http://www.eway.com.au",
  7.     "CancelUrl": "http://www.eway.com.au",
  8.     "TransactionType": "Purchase"
  9. })
  10. .then(function (response) {
  11.     if (response.getErrors().length == 0) {
  12.         var redirectURL = response.get('SharedPaymentUrl');
  13.     } else {
  14.         response.getErrors().forEach(function(error) {
  15.             console.log("Response Messages: " + rapid.getMessage(error, "en"));
  16.         });
  17.     }
  18. })
  19. .catch(function(reason) {
  20.     reason.getErrors().forEach(function(error) {
  21.         console.log("Response Messages: " + rapid.getMessage(error, "en"));
  22.     });
  23. });


4. ​Redirect the Customer


​Usually once the shared page URL has been created, the customer can be immediately redirected. Alternatively, you can display the URL (how this is displayed will depend on your Node.js framework):

  1. '<a href="' + $sharedURL + '">Pay with our secure payment page</a>'

Now a link will be displayed which goes to the Responsive Shared Page created with the details submitted in the previous step.

5. ​​Fetch the Result

Once the customer has gone to the Responsive Shared Page and submitted their payment information, they will be redirected back to the RedirectUrl specified in the request. This page should use the AccessCode (passed as a query variable) to fetch the result of the transaction. 

  1. client.queryTransaction(accessCode)

Key information such as the success of the transaction and the transaction ID can be found in the response. If the transaction wasn’t successful, the reason can be found in the ResponsiveMessage. An example of handling this information would be: 

  1. .then(function (response) {
  2.     if (response.get('Transactions[0].TransactionStatus')) {
  3.         console.log('Payment successful! ID: ' + response.get('Transactions[0].TransactionID'));
  4.     } else {
  5.         var errorCodes = response.get('Transactions[0].ResponseMessage').split(', ');
  6.         errorCodes.forEach(function(errorCode) {
  7.         console.log("Response Message: " + rapid.getMessage(errorCode, "en"));
  8.     });
  9.     }
  10. })
  11. .catch(function(reason) {
  12.     reason.getErrors().forEach(function(error) {
  13.         console.log("Response Messages: " + rapid.getMessage(error, "en"));
  14.     });
  15. });


That’s it – a complete Responsive Shared Page integration! 

For more information on the functions available in the eWAY Node.js SDK, check out the eWAY Rapid API Reference

 

eWAY makes it easy for us to process and manage payments. They have an SDK that my developers liked working with and their payment management tools are very easy to use.

Dean Van Es, Managing Director FastCover