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


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.


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

<br />
$ npm install eway-rapid<br />


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

<br />
var rapid = require('eway-rapid');<br />

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

<br />$ npm install eway-rapid<br />

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:

<br />var rapid = require('eway-rapid');<br />

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.
<br />// eWAY Credentials<br />var key = 'A1001CTYCxgwTHvadCWKyV9m/ixKCimCqN/cv5/2+SiU0iNc267zZAdNMpqUkizVY9tG7J',<br />password = 's4nydboX',<br />endpoint = 'sandbox';// Create the eWAY Client<br />var client = rapid.createClient(key, password, endpoint);<br />
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:

<br />client.createTransaction(rapid.Enum.Method.RESPONSIVE_SHARED, {<br />"Payment": {<br />"TotalAmount": 100<br />},<br />// Change these to your server<br />"RedirectUrl": "",<br />"CancelUrl": "",<br />"TransactionType": "Purchase"<br />})<br />.then(function (response) {<br />if (response.getErrors().length == 0) {<br />var redirectURL = response.get('SharedPaymentUrl');<br />} else {<br />response.getErrors().forEach(function(error) {<br />console.log("Response Messages: " + rapid.getMessage(error, "en"));<br />});<br />}<br />})<br />.catch(function(reason) {<br />reason.getErrors().forEach(function(error) {<br />console.log("Response Messages: " + rapid.getMessage(error, "en"));<br />});<br />});<br />

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):

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

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.

<br />client.queryTransaction(accessCode)<br />

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:

<br />.then(function (response) {<br />if (response.get('Transactions[0].TransactionStatus')) {<br />console.log('Payment successful! ID: ' + response.get('Transactions[0].TransactionID'));<br />} else {<br />var errorCodes = response.get('Transactions[0].ResponseMessage').split(', ');<br />errorCodes.forEach(function(errorCode) {<br />console.log("Response Message: " + rapid.getMessage(errorCode, "en"));<br />});<br />}<br />})<br />.catch(function(reason) {<br />reason.getErrors().forEach(function(error) {<br />console.log("Response Messages: " + rapid.getMessage(error, "en"));<br />});<br />});<br />

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.

Become an eWAY merchant today.

With 24/7 support, over 250 integrations and 20+ years experience – the team at eWAY are here to provide you with the leading all-in-one payments solution.