Command line example scripts and Notification handler examples using the hypercharge SDK.
Tested on OSX
Hypercharge support creates a test-account and sends you login, password and channel. channel is only needed for Transactions. channel is not needed for WPF or mobile.
In the root folder copy the file credentials.json.example to credentails.json
$ cp credentials.json.example credentails.jsoncredentails.json then looks like.
{
"login" : "f8ea102f4f998dda3261e413baa912f3bc65a6fb",
"password": "1891ad4891010903fea7d0349e3622072473c09b",
"channel" : "a5f82d1f7eb0d4ff2ff76120462a51dd1039e1af",
"myShopBaseUrl": "https://abcd1234.ngrok.com"
}The 40 char hex strings are just dummies.
Replace them with your login, password and channel.
channel value can be left blank if you do WPF or mobile Payments only.
myShopBaseUrl see Notifications bellow.
Note: your credentials.json file is secret! Never push it to git, svn or any other version control system!
notifications are a key part of async workflows (wpf, mobile, sale_3d, ...). Hypercharge server notifies your server when a payment was processed. We recomment using ngrok to receive notifications from Hypercharge at your local dev maschine. ngrok even can replay the notifications so you don't have to click through frontend parts over and over when developing your notification handler.
Register at ngork. You will see install instructions - easy btw. Download the ngork binary for your platform. You might like to put the ngork executable into a directory in your $PATH e.g. /usr/local/bin or $HOME/local/bin.
enable internet forwarding to 127.0.0.1:80
$ ngrok 80ngork starts and says something like
ngrok
Tunnel Status online
Version 1.7/1.6
Forwarding http://2bc69ef.ngrok.com -> 127.0.0.1:80
Forwarding https://2bc69ef.ngrok.com -> 127.0.0.1:80
Web Interface 127.0.0.1:4040
# Conn 55
Avg Conn Time 113.49ms
Take the https://....ngork.com url an replace it into your myShopBaseUrl in credentials.json:
{
...
"myShopBaseUrl": "https://2bc69ef.ngrok.com"
}Your local webserver is now accessible from the internet via e.g. http://2bc69ef.ngrok.com
To replay notifications with ngork use the ngork Web Interface http://127.0.0.1:4040.
At first setup your credentials.json as described in general setup.
All php stuff is in the /php directory.
So go there
$ cd phpinstall dependencies
/php$ composer installshow installed packages
/php$ composer show -iYou should be able to run an example script now:
/php$ php src/wpf_create.phpThe hypercharge WFP (Web Payment Form) should be shown in your webbrowser now.
To receive notifications, install and start ngork (s. Notifications).
$ ngrok 8080Start the built in php webserver from the php/src directory (php-cli >= 5.4 required)
php/src$ php -S 127.0.0.1:8080now let's see if the notification forwarding works.
php/src$ php wpf_create.phpfill out the form and submit (test) payment. You will see the notification in the 127.0.0.1:8080 console a few seconds later.
Note: If php -S 127.0.0.1:8080 doesn't work for you, ngork can forward to your local apache as well. Simply start ngork with the port of your apache (80) and serve the php/src directory.
$ ngork 80At first setup your credentials.json as described in general setup.
All node.js stuff is in the /nodejs directory.
So go there
$ cd nodejsinstall dependencies
/nodejs$ npm installshow installed packages
/nodejs$ npm listYou should be able to run the (simple) example script now.
/nodejs$ node lib/main.js
validate with sale schema...
{ instance: { transaction_type: 'sale', transaction_id: '23423423423' },
schema:
{ description: 'Hypercharge sale Transaction request',
type: 'object',
'$schema': 'http://json-schema.org/draft-03/schema',
additionalProperties: false,
properties: { payment_transaction: [Object] } },
propertyPath: 'instance',
errors:
[ { property: 'instance',
message: 'Property transaction_type does not exist in the schema',
schema: [Object],
instance: [Object],
stack: 'instance Property transaction_type does not exist in the schema' },
{ property: 'instance',
message: 'Property transaction_id does not exist in the schema',
schema: [Object],
instance: [Object],
stack: 'instance Property transaction_id does not exist in the schema' },
{ property: 'instance.payment_transaction',
message: 'is required',
schema: [Object],
stack: 'instance.payment_transaction is required' } ],
throwError: undefined }TODO: add more examples