Sep 15, 2020
0
Level 1
Create and Verify webhook shopify using laravel
ErrorException Undefined index: HTTP_X_SHOPIFY_HMAC_SHA256
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError C:\xampp\htdocs\handwritten\app\Http\Controllers\WebHookController.php:24 /**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
define('SHOPIFY_APP_SECRET', '**********my_shopify_secret***********');
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);
}
$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));
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
}
}
Controller
Please or to participate in this conversation.