Subversion Repositories munaweb

Rev

Rev 131 | Details | Compare with Previous | 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'];
131 - 18
  $apiVersion = $config[$site]['apiVersion'];
2 - 19
  $apikey = $config[$site]['apiKey'];
20
  $password = $config[$site]['password'];
21
  $sharedSecret = $config[$site]['sharedSecret'];
144 - 22
  $shopifyAdminUrl = "https://" . $apikey . ":" . $password . '@' . $hostname . "/admin/";
2 - 23
 
24
  $fromEmail = $config['settings']['fromEmail'];
25
	$toEmail = $config['settings']['toEmail'];
26
}
27
 
28
function getShopifyAdminUrl() {
29
  global $shopifyAdminUrl;
30
 
31
  return $shopifyAdminUrl;
32
}
33
 
34
if (!function_exists('hash_equals')) {
35
    function hash_equals($a, $b) {
36
        $ret = strlen($a) ^ strlen($b);
37
        $ret |= array_sum(unpack("C*", $a^$b));
38
        return !$ret;
39
    }
40
}
41
 
42
// Verify Shopify Hash
43
function verify_webhook($data, $hmac_header) {
44
  global $sharedSecret;
45
 
46
  $calculated_hmac = base64_encode(hash_hmac('sha256', $data, $sharedSecret, true));
47
  return hash_equals($hmac_header, $calculated_hmac);
48
}
49
 
50
?>