{"id":391,"date":"2016-01-17T11:06:56","date_gmt":"2016-01-17T10:06:56","guid":{"rendered":"http:\/\/joost.vunderink.net\/blog\/?p=391"},"modified":"2016-01-17T11:06:56","modified_gmt":"2016-01-17T10:06:56","slug":"paybox-integration-using-node-js-with-example-html","status":"publish","type":"post","link":"https:\/\/joost.vunderink.net\/blog\/2016\/01\/17\/paybox-integration-using-node-js-with-example-html\/","title":{"rendered":"Paybox integration using node.js &#8211; with example HTML"},"content":{"rendered":"<p>This post will help you get <a href=\"http:\/\/www1.paybox.com\/\">Paybox<\/a> integration to work\u00a0using <a href=\"https:\/\/nodejs.org\/en\/\">node.js<\/a>.<\/p>\n<p>You can find a full working example\u00a0in the `src\/paybox-integration` dir of my <a href=\"https:\/\/github.com\/joostvunderink\/jvblog-node-samples\">blog code repository<\/a>.<\/p>\n<p>Paybox\u00a0is a French payment provider. Getting their integration to work can be quite a hassle.<\/p>\n<p>The simplest way to get payments to work, is to generate a form and post it to the paybox servers. This form must contain an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hash-based_message_authentication_code\">HMAC signature<\/a> based on your private HMAC key and the form data. It is rather tricky to get this right.<\/p>\n<p>Unfortunately, if you do anything wrong with your form, you get a generic &#8211; and totally unhelpful &#8211; error message.<\/p>\n<div id=\"attachment_455\" style=\"width: 263px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/joost.vunderink.net\/blog\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-15-at-22.41.21.png\" rel=\"attachment wp-att-455\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-455\" class=\"size-full wp-image-455\" src=\"http:\/\/joost.vunderink.net\/blog\/wp-content\/uploads\/2016\/01\/Screen-Shot-2016-01-15-at-22.41.21.png\" alt=\"This does not help you debug your code.\" width=\"253\" height=\"217\" \/><\/a><p id=\"caption-attachment-455\" class=\"wp-caption-text\">This does not help you debug your code.<\/p><\/div>\n<p>Fortunately, there is a permanent test user on the paybox test environment. This can help you get it up and running. The test user has this HMAC key:<\/p>\n<pre class=\"lang:default decode:true\">0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF<\/pre>\n<p>Here is a form that just works with the test user:<\/p>\n<pre class=\"lang:xhtml decode:true\" title=\"Paybox test form\">&lt;form method=\"POST\" action=\"https:\/\/preprod-tpeweb.paybox.com\/cgi\/MYchoix_pagepaiement.cgi\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_SITE\" value=\"1999888\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_RANG\" value=\"32\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_IDENTIFIANT\" value=\"107904482\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_TOTAL\" value=\"1000\"&gt;\r\n&lt;input type=\"hidden\" name= \"PBX_DEVISE\" value=\"978\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_CMD\" value=\"TEST Paybox\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_PORTEUR\" value=\"test@paybox.com\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_RETOUR\" value=\"Mt:M;Ref:R;Auto:A;Erreur:E\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_HASH\" value=\"SHA512\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_TIME\" value=\"2014-12-01T00:00:00+01:00\"&gt;\r\n&lt;input type=\"hidden\" name=\"PBX_HMAC\" value=\"213904D9F3C6000C2892F1FD77795C58D0365B281136B3FA3B7EC530E4731A6D87D93D2268C0945C5EF5DF6496EECA329147F00113C4058402A4A2C060828DAA\"&gt;\r\n&lt;input type=\"submit\" value=\"Send\"&gt;\r\n&lt;\/form&gt;<\/pre>\n<p>Using the data in this form, you can figure out whether your HMAC algorithm is working correctly. We used the <a href=\"https:\/\/github.com\/Ideolys\/node-paybox\">node-paybox module<\/a>, which looks not that well maintained, but it works well.<\/p>\n<p>This is how we use it:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Using the node-paybox module\">var transactionData = {\r\n  offer   : 'system', \/\/ always 'system'\r\n  isTest  : isTest,   \/\/ true to use the paybox test system\r\n  key     : process.env.PAYBOX_HMAC_KEY,\r\n  PBX_    : {\r\n    SITE       : process.env.PBX_SITE,\r\n    RANG       : process.env.PBX_RANG,\r\n    IDENTIFIANT: process.env.PBX_IDENTIFIANT,\r\n    TOTAL      : amountPayableInCents,\r\n    DEVISE     : '978', \/\/ currency in ISO 4217 - 978 is EUR\r\n\r\n    \/\/ Do not include colons (\":\") in the payment id (PBX_CMD).\r\n    \/\/ If you do, the node-paybox module will not succeed in verifying\r\n    \/\/ the signature of the message. It seems to have something to do\r\n    \/\/ with the : not properly being URL encoded.\r\n    CMD        : 'some unique identifier without :',\r\n    PORTEUR    : emailAddress,\r\n\r\n    \/\/ Make sure that 'sign:K' is the last parameter, otherwise the signature\r\n    \/\/ validation might fail!\r\n    RETOUR     : 'value:M;id:R;auth:A;error:E;transactionTime:Q;transactionDate:W;transactionNumber:S;sign:K',\r\n    HASH       : 'SHA512',\r\n    TIME       : transactionTime.toISOString(),\r\n    REPONDRE_A : baseUrl + '\/callback',\r\n    ANNULE     : baseUrl + '\/cancel',\r\n    ATTENTE    : baseUrl + '\/pending',\r\n    EFFECTUE   : baseUrl + '\/ok',\r\n    REFUSE     : baseUrl + '\/error',\r\n  }\r\n};\r\n\r\npaybox.createTransaction(transactionData, function(err, transaction) {\r\n  \/\/ Display a form using transaction.method, transaction.url and transaction.body\r\n});\r\n<\/pre>\n<p>Hopefully this will help you in getting Paybox integration to work. For a working example, see the `src\/paybox-integration` dir of my <a href=\"https:\/\/github.com\/joostvunderink\/jvblog-node-samples\">blog code repository<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will help you get Paybox integration to work\u00a0using node.js. You can find a full working example\u00a0in the `src\/paybox-integration` dir of my blog code repository. Paybox\u00a0is a French payment provider. Getting their integration to work can be quite a &hellip; <a href=\"https:\/\/joost.vunderink.net\/blog\/2016\/01\/17\/paybox-integration-using-node-js-with-example-html\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[176,177,10],"tags":[],"class_list":["post-391","post","type-post","status-publish","format-standard","hentry","category-javascript","category-node-js","category-software-development"],"_links":{"self":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts\/391"}],"collection":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/comments?post=391"}],"version-history":[{"count":6,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts\/391\/revisions"}],"predecessor-version":[{"id":459,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts\/391\/revisions\/459"}],"wp:attachment":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/media?parent=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/categories?post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/tags?post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}