Take cards, UPI, netbanking and wallets in India through PayU hosted checkout. The shopper pays on PayU's own page, and a hashed webhook reports when the payment is captured.
Before you start
- A PayU India merchant account. Test mode is fine.
- A Merchant Key and Salt from the Developers section of the PayU Dashboard. Test and live have separate pairs.
- Payments in INR. PayU India takes other currencies only when it enables them for your account, and BWH Payments refuses them.
Set up PayU
1. Fill in PayU Gateway Settings
| Field | Value |
|---|---|
| Merchant Key | The key from the PayU Dashboard |
| Merchant Salt | The Salt v2 (256-bit) shown with the key. PayU also signs its payment webhooks with it. |
| Test Mode | On for a test key: shoppers go to test.payu.in. Turn it off with live credentials. |
| Success URL | Your confirmation page. ?reference_id=… is added to it. Required, unless every payment sets redirect_to. |
| Failure URL | Your payment-failed page. PayU sends failed and cancelled payments here. Required, unless every payment sets redirect_to. |
| Cancelled URL | PayU never redirects here. BWH Payments passes it back to your app, so you can send the shopper there yourself. |
2. Create a Payment Gateway Profile named PayU, set Gateway Settings to PayU Gateway Settings, and tick Enabled.
3. Add the webhooks. In the PayU Dashboard, go to Developers → Webhooks → Create Webhook. Some dashboards show it as Settings → Webhook. Create one webhook for each event:
- URL:
https://your.site/api/v2/method/bwh_payments.bwh_payments.webhook.handle?gateway=PayU - Type: Payment
- Events: Successful, Failed, and Refund
How checkout works
PayU has no checkout link to hand out. The shopper's browser must post a signed form to PayU, so BWH Payments serves that form itself:
create_paymentmakes no call to PayU. It generates a 20-charactertxnid, stores it asorder_ref, and setsorder_urlto BWH Payments' ownstart_checkoutpage.- You redirect the shopper to
order_url. The page posts the signed form to PayU at once. It has a Continue to PayU button for browsers that block the automatic post. - The shopper pays on PayU's page.
- PayU posts the shopper back to BWH Payments, which redirects them to your Success URL or Failure URL. With
redirect_to, both go toreturn_from_gateway, which confirms the payment with PayU first.
The shopper stays signed in. PayU's post comes from another site, so the browser sends none of your site's cookies with it. BWH Payments drops the guest cookies that Frappe would otherwise set, so the shopper's own session survives.
How it behaves
PayU unmappedstatus |
Payment status |
|---|---|
captured |
Paid |
userCancelled |
Cancelled |
autorefund |
Not Paid |
failed, bounced, dropped |
Pending |
auth, pending, anything else |
Pending |
A failed attempt stays Pending on purpose. PayU lets the shopper try again on the same txnid, and a request that has left Pending ignores a later capture. Your app can't release an open PayU checkout either: release_if_unpaid() returns False, because PayU can't cancel a transaction.
- Amounts are sent as a decimal string in rupees, for example
"149.00". - Shopper details: PayU needs an email and a phone number.
create_paymentthrows without them, so the shopper doesn't reach a PayU error page. The first name iscustomer_forenames, orCustomerwhen it's empty. - Payment webhooks are checked with PayU's reverse hash (SHA-512 over the posted fields and your salt). The hash uses your own Merchant Key, so a delivery meant for another merchant fails.
- Refund webhooks aren't signed. BWH Payments reads only the refund id from the body, then asks PayU for that refund. It ignores the delivery when the id belongs to a capture, not a refund.
- Refunds go against the payment's PayU ID (
mihpayid), which is stored asgateway_transaction_ref. Partial refunds are supported. PayU queues every refund, so it startsPendingand settles from a refund webhook or fromsync_refunds. - Refunds raised on the PayU Dashboard are recorded by the refund webhook, or by the next
sync_refunds.
Test mode
Use PayU's test cards and UPI ids, for example Mastercard 5123 4567 8901 2346, expiry 05/30, CVV 123, OTP 123456.
PayU's test environment can take a long time to settle a refund, so a test refund can stay Pending for hours.
A webhook only reaches a public URL. To test on your own machine, expose your site through a tunnel, for example cloudflared tunnel --url http://127.0.0.1:8000 --http-host-header your.site, and use the tunnel's URL in step 3.
Next steps
- Return pages: the confirmation and payment-failed pages
- Webhooks and security: debug a delivery that isn't arriving