Rev 2 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
// be sure include path contains current directory
ini_set('include_path', ini_get('include_path') . ':.');
$shopifyAdminUrl = "";
$sharedSecret = "";
$fromEmail = "";
$toEmail = "";
// Load configuration data from shopify ini file
function getShopifyConfig() {
global $shopifyAdminUrl, $sharedSecret;
global $fromEmail, $toEmail;
$config = parse_ini_file('shopify.ini', true);
$site = $config['settings']['site'];
$hostname = $config[$site]['hostName'];
$apikey = $config[$site]['apiKey'];
$password = $config[$site]['password'];
$sharedSecret = $config[$site]['sharedSecret'];
$shopifyAdminUrl = "https://" . $apikey . ":" . $password . '@' . $hostname . "/admin/";
$fromEmail = $config['settings']['fromEmail'];
$toEmail = $config['settings']['toEmail'];
}
function getShopifyAdminUrl() {
global $shopifyAdminUrl;
return $shopifyAdminUrl;
}
if (!function_exists('hash_equals')) {
function hash_equals($a, $b) {
$ret = strlen($a) ^ strlen($b);
$ret |= array_sum(unpack("C*", $a^$b));
return !$ret;
}
}
// Verify Shopify Hash
function verify_webhook($data, $hmac_header) {
global $sharedSecret;
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, $sharedSecret, true));
return hash_equals($hmac_header, $calculated_hmac);
}
?>