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:
transactionIdtype
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 orderimport express from "express";
const router = express.Router();
router.post(
"/webhooks/digetpay",
express.raw({ type: "application/json" }),
(req, res) => {
const payload = JSON.parse(req.body.toString());
res.status(200).send("OK");
const {
transactionId,
orderId,
status,
type
} = payload;
// TODO:
// Verify signature
// Check idempotency
// Update order
}
);
export default router;from flask import Blueprint, request
webhooks = Blueprint("webhooks", __name__)
@webhooks.route("/webhooks/digetpay", methods=["POST"])
def digetpay():
payload = request.get_json(force=True)
transaction_id = payload.get("transactionId")
order_id = payload.get("orderId")
status = payload.get("status")
event_type = payload.get("type")
# TODO:
# Verify signature
# Check idempotency
# Update order
return "OK", 200@RestController
@RequestMapping("/webhooks")
public class DigetPayWebhookController {
@PostMapping("/digetpay")
public ResponseEntity<String> webhook(
@RequestBody Map<String,Object> payload) {
String transactionId =
(String) payload.get("transactionId");
String orderId =
(String) payload.get("orderId");
String status =
(String) payload.get("status");
String type =
(String) payload.get("type");
// TODO:
// Verify signature
// Check idempotency
// Update order
return ResponseEntity.ok("OK");
}
}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
Updated about 1 month ago
