4 define('SHOPIFY_APP_SECRET', 'b5421c95b62f83cb49b319c5a18f93dc');
6 function verify_webhook($data, $hmac_header) {
7 $calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET
, true));
8 return ($hmac_header == $calculated_hmac);
10 $hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
15 $webhook = fopen('php://input' , 'rb');
16 while (!feof($webhook)) {
17 $webhookContent .= fread($webhook, 4096);
22 $verified = verify_webhook($webhookContent, $hmac_header);
23 error_log('Webhook verified: '.var_export($verified, true));
25 $file = fopen("liveaccounts.txt",'a');
26 fwrite($file,"\nVALID--".var_export($verified, true)."END-VALID");
29 if(var_export($verified, true) == "false") { // var_export of $verified return string
35 $file = fopen("liveaccounts.txt",'a');
36 fwrite($file,$webhookContent);
40 $account = json_decode($webhookContent);
42 $username = $account -> {'email'};
43 $username = (filter_var($username, FILTER_SANITIZE_EMAIL
));
44 $username = strtolower($username); // force username to be lowercase
46 $lineItems = $account -> {'line_items'};
50 foreach ($lineItems as $lineItem){
51 $quantity = $lineItem -> {'quantity'};
52 $quantity = (int) $quantity; // make sure $quantity is an int
53 $sku = $lineItem -> {'sku'};
56 if ($sku == "MP001") {$package = 5000;} // package is the amount of months
57 if ($sku == "MP002") {$package = 15000;}
58 if ($sku == "MP003") {$package = 25000;}
59 if ($package == 0) {exit;}
61 $pointsToAdd = $pointsToAdd +
($package * $quantity);
64 if ($package == null ||
$package == 0) {
68 $customer = $account -> {'customer'};
70 system("php /home/auth/secure_html/melon/melon.php $username $pointsToAdd $animal");