> But would love to have it working the "correct" way - also would be
> nice to have a PHP example on the wiki too.
The PHP manual says hash_hmac() returns a "hexit" string if you leave
off the fourth argument, but you want a base64-encoded string. Try
changing the line in your computeSignature() function to this:
return base64_encode(hash_hmac('sha256', file_get_contents('php://
input'), SHOPIFY_SECRET, true));
Note the fourth argument to hash_hmac() -- this will make it return
raw binary data, which will then be fed to base64_encode().
Also I'm not sure if this line will work because your index is all-
lowercase:
$hmac = $headers['x-shopify-hmac-sha256'];
I think the indexes in $headers are going to be capitalized/uppercase/
lowercase exactly as Apache provides them. It might be easier and a
little more portable to use $_SERVER['X_SHOPIFY_HMAC_SHA256'].
Also a bit more logic there will help narrow down the failure point;
e.g.:
if (empty($_SERVER['X_SHOPIFY_HMAC_SHA256'])) {
die("header 'x-shopify-hmac-sha256' is blank or non-existent\n");
}
Ben