Development discussions around Shopify APIs
so i'm using two php code one is webhook.php inside that i'm taking response from shopify via providing the path inside app setup in shop webhook field and delete.php to delete db data whenever the app is uninstall but somehow it didn't work can anyone check and tell me where is the issue. i,m attaching both file here
WEBHOOK.PHP>>>>>>
<?php
require_once("../inc/connect.php");
require_once("../inc/functions.php");
echo "deleted";
define('SHOPIFY_APP_SECRET', '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');
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return hash_equals($hmac_header, $calculated_hmac);
}
$res = '';
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$topic_header = $_SERVER['HTTP_X_SHOPIFY_TOPIC'];
$shop_header = $_SERVER['HTTP_X_SHOPIFY_SHOP_DOMAIN'];
$data = file_get_contents('php://input');
$decoded_data = json_decode($data, true);
$newFileName = "file.txt";
file_put_contents($newFileName, $decoded_data);
$verified = verify_webhook($data, $hmac_header);
if( $verified == true ) {
if( $topic_header == 'app/uninstalled' || $topic_header == 'shop/update') {
if( $topic_header == 'app/uninstalled' ) {
$sql = "DELETE FROM shopify_access_token WHERE store_url='$shop_header' LIMIT 1";
$result = mysqli_query($conn, $sql);
$response->shop_domain = $decoded_data['shop_domain'];
$res = $decoded_data['shop_domain'] . ' is successfully deleted from the database';
} else {
$res = $data;
}
}
} else {
$res = 'The request is not from Shopify';
}
error_log('Response: '. $res); //check error.log to see the result
?>
Hi,
you must specify the protocol and domain when creating the webhooks:
$array = array(
'webhook' => array(
'topic' => 'app/uninstalled',
'address' => 'https://example.hostname.com/web-hooks/delete.php?shop=' . $shop_url,
'format' => 'json'
)
);
be careful not to expose your SHOPIFY_APP_SECRET you must generate a new one from the application's control panel
User | RANK |
---|---|
8 | |
7 | |
3 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By