<!doctype html>
<html>
<?php
function echonl($title,$data) {
echo '<br>'.$title.': '.$data;
}
$client_ip = $_SERVER['REMOTE_ADDR'];
//echonl('client_ip:',$client_ip);
?>
<dmx-value id="client_ip" value="<?php echo $client_ip; ?>"></dmx-value>
<?php
function clearCookies() {
setcookie("ecwid_store_id", "", time()-3600);
setcookie("fixed_amount", "", time()-3600);
setcookie("payer_first_name", "", time()-3600);
setcookie("payer_last_name", "", time()-3600);
setcookie("payer_company", "", time()-3600);
setcookie("payer_phone", "", time()-3600);
setcookie("payer_email", "", time()-3600);
setcookie("payer_reference_transaction_id", "", time()-3600);
setcookie("payer_address_line_1", "", time()-3600);
setcookie("payer_address_city", "", time()-3600);
setcookie("payer_address_state_code", "", time()-3600);
setcookie("payer_address_state_name", "", time()-3600);
setcookie("payer_address_zip_code", "", time()-3600);
}
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);
//echonl('$encryption_key', var_dump($encryption_key));
// Decrypt payload
$json_data = aes_128_decrypt($encryption_key, $data);
//echo '$json_data: ';
//var_dump($json_data);
//echonl('$json_data', var_dump($json_data));
// Decode json
$json_decoded = json_decode($json_data, true);
//echo '<br>$json_decoded: ';
//var_dump($json_decoded);
//echonl('$json_decoded', var_dump($json_decoded));
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_decrupt, if mcrypt is enabled in your system
return $json;
}
// qPgKzlOEq1nBPGfVaDoloNBvmJpwyBXu - Store 95642502
$client_secret = "qPgKzlOEq1nBPGfVaDoloNBvmJpwyBXu";
//$client_secret = "CurePayCurePay00";
// This is a dummy value. Place your client_secret key here.
// You received it from Ecwid team in email when registering the app
//$client_secret = "CurePayCurePay00"; Y
//$cipher = "AES-128-CBC";
// this can be generated random if you plan to store it for later
// but in this case e.g. openssl_random_pseudo_bytes($ivlen);
//$iv = "abcdefghijklmnopqrstuvwx";
$iv = "qPgKzlOEq1nBPGfV";
//$cipher = "aes-128-gcm";
$cipher = "aes-128";
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$tag = 0;
// If this is a payment request
if (isset($_POST["data"])) {
// Get payload from the POST and decrypt it
$ecwid_payload = $_POST['data'];
//echo $ecwid_payload;
//echonl('$ecwid_payload', var_dump($ecwid_payload));
// The resulting JSON from payment request will be in $order variable
$order = getEcwidPayload($client_secret, $ecwid_payload);
//var_dump($order);
//echonl('$order', var_dump($order));
$json_pretty = json_encode($order, JSON_PRETTY_PRINT);
//echonl('$json_pretty:',$json_pretty);
// Debug preview of the request decoded earlier
//echo "<h3>REQUEST DETAILS</h3>";
// Account info from merchant app settings in app interface in Ecwid CP
//$cureclickuid = "";
if (isset($order['merchantAppSettings']['apiKey'])) {
$cureclickuid = $order['merchantAppSettings']['apiKey'];
}
//$cureclickuid = "22222";
$storeid = $order['storeId'];
$fixed_amount = $order['cart']['order']['usdTotal'];
$payer_full_name = $order['cart']['order']['shippingPerson']['name'];
$payer_company = $order['cart']['order']['shippingPerson']['companyName'];
$payer_phone = $order['cart']['order']['shippingPerson']['phone'];
$payer_email = $order['cart']['order']['email'];
$payer_reference_transaction_id = $order['cart']['order']['referenceTransactionId'];
//$payer_address_line_1 = $order['cart']['order']['billingPerson']['street'];
//$payer_address_city = $order['cart']['order']['billingPerson']['city'];
//$payer_address_state_code = $order['cart']['order']['billingPerson']['stateOrProvinceCode'];
//$payer_address_state_name = $order['cart']['order']['billingPerson']['stateOrProvinceName'];
//$payer_address_zip_code = $order['cart']['order']['billingPerson']['postalCode'];
setcookie("ecwid_payment", 'true');
if (isset($cureclickuid)) {
setcookie("cureclickuid", $cureclickuid);
}
setcookie("ecwid_store_id", $storeid);
setcookie("fixed_amount", $fixed_amount);
setcookie("payer_first_name", substr(urldecode($payer_full_name), 0, strpos(urldecode($payer_full_name), ' ')));
setcookie("payer_last_name", substr(urldecode($payer_full_name), strpos(urldecode($payer_full_name), ' ')+1));
setcookie("payer_company", urldecode($payer_company));
setcookie("payer_phone", urldecode($payer_phone));
setcookie("payer_email", urldecode($payer_email));
setcookie("payer_reference_transaction_id", urldecode($payer_reference_transaction_id));
//setcookie("payer_address_line_1", urldecode($payer_address_line_1));
//setcookie("payer_address_city", urldecode($payer_address_city));
//setcookie("payer_address_state_code", urldecode($payer_address_state_code));
//setcookie("payer_address_state_name", urldecode($payer_address_state_name));
//setcookie("payer_address_zip_code", urldecode($payer_address_zip_code));
} else {
if (isset($_GET["cureclickuid"])) {
clearCookies();
setcookie("cureclickuid", $_GET["cureclickuid"]);
setcookie("ecwid_payment", "false");
} else {
if (isset($_COOKIE["ecwid_payment"]))
{
if ($_COOKIE["ecwid_payment"] == "false") {
clearCookies();
}
} else {
clearCookies();
}
}
}
?>
<head>
<base href="/cureclick">
<script src="dmxAppConnect/dmxAppConnect.js"></script>
<meta charset="UTF-8">
<title>CureClick by CurePay</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="css/style.css" />
</head>
<!--ADD PHP VARIABLE TO APP CONNECT VARIABLE-->
<!-- <dmx-value id="client_ip" value="<?php echo $client_ip; ?>"></dmx-value> -->
<!-- <dmx-value id="ecwid_payload" value="<?php echo $ecwid_payload; ?>"></dmx-value> -->
<!--CALL THE APP CONNECT VALUE TO DISPLAY IT-->
<!-- {{var1.value}} -->