Webhooks

Instant Notifications (Webhooks)

The Webhooks system (or IPN) allows us to notify your server immediately when a payment status changes, ensuring that orders are updated even if the customer closes the browser.

Setup

  1. Go to the Merchant Dashboard.
  2. Navigate to the API Credentials section.
  3. Enter your Webhook URL and obtain the Webhook Secret.

Security Verification

To ensure that the notification is coming from MyPay, we send a digital signature in the X-MyPay-Signature header. You must verify this signature.

Verification Example (PHP)

$payload = file_get_contents('php://input');
$receivedSignature = $_SERVER['HTTP_X_MYPAY_SIGNATURE'];
$webhookSecret = 'your_webhook_secret_here';

// Calculate expected signature using HMAC SHA256
$calculatedSignature = hash_hmac('sha256', $payload, $webhookSecret);

if (hash_equals($calculatedSignature, $receivedSignature)) {
    // ✅ Signature is valid
    // Process the request and update order status in your database
} else {
    // ❌ Signature is invalid
    // Ignore the request
}

Data Structure (Payload)

You will receive a POST request containing JSON in the following format:

{
    "event": "payment.success",
    "type": "QR_PAY",
    "transaction_id": "ABC123XYZ789",
    "token": "ABC123XYZ789",
    "trx_ref": "REF_456789",
    "status": "success",
    "gateway": "MOAMALAT",
    "amount": 100.00,
    "currency": "LYD",
    "timestamp": "2024-01-12 14:30:00"
}

Events

  • payment.success: Payment successfully received

[!IMPORTANT] Your server must respond with status code 200 OK immediately upon receiving the notification to confirm receipt.