Webhooks Code Examples

Receive and process DigetPay payment notifications in your preferred programming language.


DigetPay sends HTTP POST requests to your configured webhook endpoint whenever a payment event occurs. Your endpoint should acknowledge the request immediately, then process the event asynchronously.

📘

See the complete implementation guides:

🚧

DigetPay may deliver the same event more than once.

Always implement idempotency by deduplicating using:

  • transactionId
  • type
❗️

Return HTTP 200 OK within a few seconds.

Heavy processing should happen asynchronously to avoid retries and duplicate notifications.


Webhook Flow

sequenceDiagram
participant DigetPay
participant Merchant

DigetPay->>Merchant: POST JSON payload
Merchant-->>DigetPay: HTTP 200 OK
Note over Merchant: Process event asynchronously

Code Examples

<?php
declare(strict_types=1);

$raw = file_get_contents('php://input');

if ($raw === false) {
    http_response_code(400);
    exit;
}

$payload = json_decode($raw, true);

if (!is_array($payload)) {
    http_response_code(400);
    exit;
}

http_response_code(200);
echo 'OK';

$transactionId = $payload['transactionId'] ?? null;
$orderId = $payload['orderId'] ?? null;
$status = $payload['status'] ?? null;
$type = $payload['type'] ?? null;

// TODO:
// Verify signature
// Check idempotency
// Update order

Example Webhook Payload

{
  "transactionId": "2232e99b-0257-47d5-bbfd-022c8951767f",
  "orderId": "PAY-1781872369616",
  "amount": 0.2,
  "currencyCode": "682",
  "status": "Approved",
  "type": "Sale",
  "cardScheme": "Mada",
  "channel": "Payment Gateway"
}

Best Practices

Return 200 OK immediately.

Verify the webhook signature.

Process events asynchronously.

Implement idempotency.

Store every received webhook for auditing.

Use webhooks as the primary source of payment confirmation.


Related Documentation



Did this page help you?