Skip to content

IPN — Instant Payment Notification

PayDunya can POST payment transaction data to a callback URL (callback_url) that you specify when creating an invoice. This is the most reliable way to confirm payments, especially when they complete asynchronously (e.g., customer confirming on their phone).

The Callback Data

PayDunya POSTs application/x-www-form-urlencoded data to your endpoint with the payment information nested under the data key.

Verifying the IPN Hash

Every IPN response includes a hash field which is the SHA-512 hash of your Master Key. You must compute this hash yourself and compare it to verify the data genuinely comes from PayDunya.

from paydunya import verify_ipn_hash

def ipn_handler(request):
    data = request.POST["data"]
    received_hash = data["hash"]

    if not verify_ipn_hash(master_key="your-master-key", received_hash=received_hash):
        return "Unauthorized", 403

    status = data["status"]
    if status == "completed":
        # Process the successful payment
        print(f"Payment {data['invoice']['token']} completed")

    return "OK", 200

IPN Data Structure

{
    "data": {
        "response_code": "00",
        "response_text": "Transaction Found",
        "hash": "8c6666a27fe5daeb76dae6abc7308a557...",
        "status": "completed",
        "mode": "test",
        "invoice": {
            "token": "test_jkEdPY8SuG",
            "total_amount": 42300,
            "description": "...",
            "items": { "item_0": { ... }, "item_1": { ... } },
            "taxes": { "tax_0": { ... } }
        },
        "customer": {
            "name": "Alioune Faye",
            "phone": "774563209",
            "email": "alioune@example.com"
        },
        "custom_data": { ... },
        "receipt_url": "https://paydunya.com/.../receipt/pdf/...pdf"
    }
}