Node.js
The Node.js implementation for the Worldpay Within IoT payment SDK. This SDK enables smart devices to discover each other, negotiate a price for services, make a payment (through Worldpay) for services, and then consume services via a trusted trigger. For an overview, see Home.
Prerequisites¶
Before you get started:
- Install Node.js on your system. We've tested this wrapper with version 8.6.0 on Ubuntu and 4.8.4 on Raspberry Pi.
- If you do not have it, install git.
- Install npm on your machine. We've tested version 5.5.1 on Ubuntu and 2.5.11 on Raspberry Pi.
- Create an account with Worldpay Online so that you can generate your own test API key. You'll replace the Worldpay test keys with your own in the SDK.
Warning
Make sure you only use test API keys.
Get started¶
Once you've got Node.js and npm.js, you should be good to go.
- Clone or download the repository:
git clone https://github.com/WPTechInnovation/wpw-sdk-nodejs.git
- Change to the folder
cd wpw-sdk-nodejs
- Update the submodules:
git submodule update --init --recursive
- Download the required modules:
npm install
Note
If you are using a different package manager than npm, please adjust the command accordingly.
(If there are issues about access rights, add sudo
in front of the above command)
Run the examples¶
Now you can start testing to see if it works. We'd recommend using your own test API keys for this. We've left ours in the code, but you won't be able to see the payments with our keys.
- In one terminal/cmd (or on one device) run:
node example-producer-callbacks.js
- In another terminal/cmd, (or on another device, on the same network) run:
node example-consumer.js
- A payment should fire. If you see the
serviceDeliveryToken
returned within the producer terminal/cmd, you'll know that the payment was complete. This payment will happen with our test keys, so you won't be able to see the payment.
Creating your own keys¶
You can do this whenever you want, but you're going to need to create your own API keys. These keys allow you to simulate payments and see the outcome, rather than just using the keys Worldpay included in their SDKs.
Warning
Make sure you only use test keys.
To add your own test API keys:
- Login to Worldpay Online.
- Go to Settings.
- Then click API Keys.
- Grab your Service key and Client key. They'll look something like this:
T_S_fd00db67-b77b-4d6e-1a2a-45f65123f795
. - Find the config folder of the SDK and find the producer JSON files.
- Add your Service and Client keys:
- The
pspConfig.merchant_client_key
andpspConfig.hte_public_key
must have the same key. - The
pspConfig.merchant_service_key
andpspConfig.hte_private_key
must have the same keys.
- The
- Save your work.
Once you've added your own test keys, you'll be able to start testing your payments.
Seeing your payments¶
Now that you've added your own test keys to the producer config files, you can start testing your payments. Refer to the Run the examples topic for more information about this.
To see your test payments:
- Login to Worldpay Online.
- On the homepage, scroll down to the Recent Orders section.
- Your payments are here. You'll be able to see:
- Order Code - The order code
- Customer Order Code - The customer's order code
- Gross Amount - The gross amount of the order
- State - The state of the order. For example, SUCCESS or AUTHORIZED
- Payment type - The type of payment. For example, ECOM
- Order type - The type of order. For example, VISA_CREDIT or VISA_DEBIT
- Updated - The last time the payment state changed
For more information, refer to the Worldpay Online documentation.
Debugging¶
If you're having trouble, you can contact us at Innovation@Worldpay.com. Alternatively, you can raise an issue in GitHub.
OS-specific issues¶
On Debain 14, the default version of Node.JS is 0.10. Distributions based on it such as Raspbian and Ubuntu would be impacted as well. To install Node.JS 8.x:
- In a terminal, run
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
- Then do
sudo apt-get install -y nodejs
To install Node.JS 4.x (Long Time Support release):
- In a terminal, run
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash-
- Then do
sudo apt-get install -y nodejs
So what's happening?¶
You can see there are four phases; Discover, Select, Pay, and Release. For more information, see Home.
What IoT devices can I run this on?¶
Note
The devices need to be on the same network - and that network should allow for UDP broadcast traffic. Most mobile hotspots allow this; a lot of corporate networks do not...
Want to contribute?¶
If you want to contribute, clone the repository and create a branch. Once you've made your changes, create a pull request. We'll review your code, and if accepted it will be merged into the code base. It's worth checking out the Internal Structure of Worldpay Within and Sample Service Messaging pages if you want to learn more about how Worldpay Within works.
You can also raise an issue in GitHub, or contact us directly at Innovation@Worldpay.com.