đź“‘Webhook / Callback
Overview
Webhooks are powerful tools used to communicate events between different systems over the web. One common application of webhooks is in payment gateways, where they provide real-time notifications about transaction statuses. This page explains how you can use webhooks to know when a payment is completed in your application.
Setting Up a Webhook for Payment Notifications
Configuring the Webhook URL
Whenever you create a transaction you can specify a custom webhook url for the transaction. This helpful if you manage multiple shops.
Handling the Webhook Data
When a payment transaction completes, the payment gateway will send a POST request to your configured webhook URL. This request will include important details about the transaction, such as:
status: Indicates the outcome of the transaction (COMPLETED, FAILED).
txn: A unique identifier for the transaction.
amount: The amount that was requested in the transaction.
currency: The currency used for the transaction.
customer_id: A unique identifier for the customer involved in the transaction.
checkout: The amount that was requested by you but converted to USD.
timestamp: The exact time when the transaction was processed.
signature: md5(txn|timestamp|webhook_key)
Example Code Signature PHP:
<?php
$receivedWebhook = json_decode(file_get_contents('php://input'));
$webhook_key = 'Your_personal_webhook_key';
$timestamp = $receivedWebhook['timestamp'];
$txn = $receivedWebhook['txn'];
$signature = md5($txn . '|' . $timestamp . '|' . $webhook_key);
if($signature == $receivedWebhook['signature']){
// Execute your code on success
}
?>
You can find your webhook key here: https://malum.co/merchant/settings/api
Last updated