Handle webhook

All things event

When a payment occurs, Bani sends a webhook event to the webhook URL that you saved on your dashboard.

It is highly recommended that you use webhooks or verify the payment transaction status before delivering value to your customers.

We advise you to verify the response before carrying out any further action.

Please note: if the payout_status value is 'system_closed', kindly wait until the status change to either 'failed' or 'completed' before taking action on your end.

To verify the response, you will have to form the signature and compare your result with the value of 'BANI-HOOK-SIGNATURE' sent to you. The signature is a combination of your merchant_private_key and request payload.

import hmac
import hashlib
import six

my_hook_signature = hmac.new(six.b(merchant_private_key), msg=str(request_payload).encode('utf-8'), digestmod=hashlib.sha256).hexdigest()
if not hmac.compare_digest(my_hook_signature, bani-hook-signature):
    content = {"message":"Invalid signature"}
    return JsonResponse(content, status=400)

Find sample request payload below.

{
  "event": "payin_mobile_money",
  "data": {
    "pay_ref": "BNPay-j6bva8xcesc2vrhhh4w1vs51t9xj96",
    "pay_ext_ref": "",
    "holder_first_name": "Star",
    "holder_last_name": "Lord",
    "custom_data": {
      "me": "userr"
    },
    "pay_amount": "30.88",
    "pay_method": "mobile_money",
    "holder_phone": "+254713674757",
    "holder_phone_carrier": "safke",
    "order_details": null,
    "holder_currency": "KES",
    "holder_country_code": "KE",
    "pay_status": "paid",
    "holder_account_number": "",
    "pub_date": "2022-04-07T11:32:24.084772Z",
    "modified_date": "2022-04-07T11:32:33.166011Z",
    "holder_bank_name": "",
    "merch_currency": "NGN",
    "merch_amount": "150.00"
  }
}

Last updated