Step 1. Decode and parse payment request from Ecwid
The first step after receiving a new payment request from Ecwid on your paymentUrl
is to decode and parse it. All payment requests ere encoded and contain all the order data some of which is essential for further steps.
What happens on the storefront
Upon clicking the “Go to Payment” button, a customer is redirected to your app paymentUrl
. For now, you can’t do anything with the storefront, so we recommend showing a loading placeholder until further steps.
What happens on the backend
The paymentUrl
endpoint of your app receives a POST request with encoded data in the request body.
Encoded request example
<form action="https://mycoolapp.com/integration" method="POST" accept-charset='utf-8'>
<input type='hidden' name='data' value="2sO2fxaXOZz9aZMxwuwvEpFSBFKd6yPTeyk3R3V6ieXIDc9romK5vpTv9kTCoMZVmxJd8kabS-bEJy7ON6vzpG4X8QMb3CYhl_WF2T7VAX883FfMverEo4jY9VlEUS9ZSJuuBVeUPnG5FE-bLTPNrMbWFXltyzt3cz5mHu8ha50oPXPDJ7mcihSH-H-i32LLTvwkfgqJa7CNd3n4XM985B1smvJEw4o6acsy1RO62eJVWJZ7k1_UTfa5S3AhrmcY0OxZuTQ3pTVVG0uKsnB73eZMhijPkPlx5Rehu_9IaMylrwOy2E15hzTnmAYActRgFVGSH8NevL9lGnTifYTp6thUqJn1HhiFjIvNQveEHIPIq5n-uOn9wkodVoDeEsuin_96t_eP5uJUFjHEpnXsDdtJpE9BVzCJrDEU2wprzYCGdc_p28f9J6jEyH4Ld2FrF0kRv_GacJwIKghGQixu_BlTlrBO1DZ1B3AhBS2IHmZVCj_U2Ux9s20-5ZTgJRgsMyeObj1I8byMPc29GGXXSJVbYfcWjk8PGtcToQu9tSFV-zYur9VB7T8ewdxst-_kTnnAPmIdKFfxHpaRIu3GYVpubytnvOMhsIuoeN3lmZ0scX_leX6w4ZE1iduEKQT3GWopZoHBTKF1-441PDY4MemDDSfUTHqkvr9LrOC4gxvXlB2EddTqUfpFFX1QZX_jpvxttQp0RXwyIi5WDVJ0pU6b-De69-QHkzeaaLbbTzJvpzkKDOmQq_TNgZnPY7sdCLpQ8ECgadWxdIxmRGCY8s-HP_sOB8Pbp5T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cq6WlSXmUPluqY"/>
</form>
The data is encoded with an AES-128 mechanism. The key for decoding is the first 16 characters of your app’s unique and unchangeable client_secret
. Get your clent_secret
value from the app dashboard page.
Request decoding examples in PHP and NodeJS:
<?php
function getEcwidPayload($app_secret_key, $data) {
// Get the encryption key (16 first bytes of the app's client_secret key)
$encryption_key = substr($app_secret_key, 0, 16);
// Decrypt payload
$json_data = aes_128_decrypt($encryption_key, $data);
// Decode json
$json_decoded = json_decode($json_data, true);
return $json_decoded;
}
function aes_128_decrypt($key, $data) {
// Ecwid sends data in url-safe base64. Convert the raw data to the original base64 first
$base64_original = str_replace(array('-', '_'), array('+', '/'), $data);
// Get binary data
$decoded = base64_decode($base64_original);
// Initialization vector is the first 16 bytes of the received data
$iv = substr($decoded, 0, 16);
// The payload itself is is the rest of the received data
$payload = substr($decoded, 16);
// Decrypt raw binary payload
$json = openssl_decrypt($payload, "aes-128-cbc", $key, OPENSSL_RAW_DATA, $iv);
// $json = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $payload, MCRYPT_MODE_CBC, $iv);
// You can use this instead of openssl_decrypt, if mcrypt is enabled in your system
return $json;
}
// Get payload from the POST and process it
$ecwid_payload = $_POST['data'];
$client_secret = "payment-app-secret-key"; // This is a dummy value. Place your client_secret key here. You received it from Ecwid team in email when registering the app
// The resulting JSON array will be in $result variable
$result = getEcwidPayload($client_secret, $ecwid_payload);
?>
var crypto = require("crypto");
var EncryptionHelper = (function () {
function decryptText(cipher_alg, key, text, encoding) {
var bText = Buffer.from(text, encoding);
var iv = bText.slice(0, 16);
var payload = bText.slice(16);
var decipher = crypto.createDecipheriv(cipher_alg, key, iv);
return Buffer.concat([
decipher.update(payload, encoding),
decipher.final()
]);
}
return {
CIPHERS: {
"AES_128": "aes128", //requires 16 byte key
"AES_128_CBC": "aes-128-cbc", //requires 16 byte key
"AES_192": "aes192", //requires 24 byte key
"AES_256": "aes256" //requires 32 byte key
},
decryptText: decryptText
};
})();
module.exports = EncryptionHelper;
let client_secret = 'CLIENT SECRET';
let data = 'ECWID PAYLOAD'
let encryption_key = client_secret.substr(0, 16);
var originalBase64 = data.replace(/-/g, "+").replace(/_/g, "/");
var algorithm = encryptionHelper.CIPHERS.AES_128_CBC;
var decrypted = encryptionHelper.decryptText(algorithm, encryption_key, originalBase64, "base64");
var payloadObject = JSON.parse(decrypted)
If you are using C# language, create additional padding to make the payload a multiple of 4:
base64 = base64.PadRight(base64.Length + (4 - (base64.Length % 4)), '=');
Quickstart with the payment integration template.
If you want to use Web Cryptography API / SublteCrypto for decoding payment requests, check out the code example created by our community developers: https://gist.github.com/manuelfdo/94a14c0314b07e311f07b240921eab86.
Last updated
Was this helpful?