Created
February 15, 2012 20:32
-
-
Save sandeepshetty/1838803 to your computer and use it in GitHub Desktop.
Verify Shopify webhook in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('SHOPIFY_APP_SECRET', 'my_shared_secret'); | |
function verify_webhook($data, $hmac_header) | |
{ | |
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true)); | |
return ($hmac_header == $calculated_hmac); | |
} | |
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256']; | |
$data = file_get_contents('php://input'); | |
$verified = verify_webhook($data, $hmac_header); | |
error_log('Webhook verified: '.var_export($verified, true)); //check error.log to see the result | |
?> |
i have use this code but error are accur
Notice: Undefined index: HTTP_X_SHOPIFY_HMAC_SHA256 in E:\wamp\www\vs_dev.sareeo.clothing\seller\paypal\hook.php on line 18
Warning: hash_equals(): Expected known_string to be a string, null given in E:\wamp\www\vs_dev.sareeo.clothing\seller\paypal\hook.php on line 14
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
php://input is a stream .ie standard input (stdin). That is the request body