Subversion Repositories munaweb

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
<?php
2
// be sure include path contains current directory
3
ini_set('include_path', ini_get('include_path') . ':.');
4
 
5
$shopifyAdminUrl = "";
6
$sharedSecret = "";
7
$fromEmail = "";
8
$toEmail = "";
9
 
10
// Load configuration data from shopify ini file
11
function getShopifyConfig() {
12
  global $shopifyAdminUrl, $sharedSecret;
13
  global $fromEmail, $toEmail;
14
 
15
  $config = parse_ini_file('shopify.ini', true);
16
  $site = $config['settings']['site'];
17
  $hostname = $config[$site]['hostName'];
18
  $apikey = $config[$site]['apiKey'];
19
  $password = $config[$site]['password'];
20
  $sharedSecret = $config[$site]['sharedSecret'];
21
  $shopifyAdminUrl = "https://" . $apikey . ":" . $password . '@' . $hostname . "/admin/";
22
 
23
  $fromEmail = $config['settings']['fromEmail'];
24
	$toEmail = $config['settings']['toEmail'];
25
}
26
 
27
function getShopifyAdminUrl() {
28
  global $shopifyAdminUrl;
29
 
30
  return $shopifyAdminUrl;
31
}
32
 
33
if (!function_exists('hash_equals')) {
34
    function hash_equals($a, $b) {
35
        $ret = strlen($a) ^ strlen($b);
36
        $ret |= array_sum(unpack("C*", $a^$b));
37
        return !$ret;
38
    }
39
}
40
 
41
// Verify Shopify Hash
42
function verify_webhook($data, $hmac_header) {
43
  global $sharedSecret;
44
 
45
  $calculated_hmac = base64_encode(hash_hmac('sha256', $data, $sharedSecret, true));
46
  return hash_equals($hmac_header, $calculated_hmac);
47
}
48
 
49
?>