Initial commit
[2ch-be.git] / melon / beta.php
blobafbdbf38b2d82e308133c6aed5df4104df857cfb
1 <?php
3 // new feb 29
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'];
11 // end new
13 $webhookContent = "";
15 $webhook = fopen('php://input' , 'rb');
16 while (!feof($webhook)) {
17 $webhookContent .= fread($webhook, 4096);
19 fclose($webhook);
21 // new feb 29
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");
27 fclose($file);
29 if(var_export($verified, true) == "false") { // var_export of $verified return string
30 exit;
33 // end new
35 $file = fopen("liveaccounts.txt",'a');
36 fwrite($file,$webhookContent);
37 fclose($file);
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'};
48 $pointsToAdd = 0;
50 foreach ($lineItems as $lineItem){
51 $quantity = $lineItem -> {'quantity'};
52 $quantity = (int) $quantity; // make sure $quantity is an int
53 $sku = $lineItem -> {'sku'};
55 $package = 0;
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) {
65 exit;
68 $customer = $account -> {'customer'};
69 $animal = "lobster";
70 system("php /home/auth/secure_html/melon/melon.php $username $pointsToAdd $animal");