Businesses add or switch payment gateways for ordinary reasons: EMI options for high-value sales, a better commercial offer, a backup during outages, or a provider that supports their category. The switch itself is where things go wrong. Orders get stuck between two systems, subscriptions break, refunds for old payments cannot be issued, and finance ends up reconciling two settlement files by hand.
This guide sets out a phased plan for moving to PayU or running it as a backup: how to structure your code so gateways are interchangeable, what is specific to PayU's hash-based integration, the parts that do not migrate easily, and how to fail over without charging a customer twice.
Quick answer: Run PayU alongside your existing gateway before switching. Put both behind one payment layer in your application, generate and verify PayU's SHA-512 hashes on the server, send a small share of traffic to PayU first and compare results on your own data. Keep the old gateway active for refunds and disputes on its payments, and plan separately for saved cards and recurring mandates.
Full switch, backup or routing: decide first
| Approach | Suits | Trade-offs |
|---|---|---|
| Full switch | One gateway is enough and the new provider covers every method you need | Simplest to run afterwards, but no fallback during an outage |
| Primary plus backup | Payments are critical and you want a manual or automatic fallback | Two KYCs, two settlement files and two sets of webhooks to maintain |
| Routing by rule | Higher volumes, where certain methods, amounts or EMI flows go to the gateway you prefer for them | Most flexible, but needs clean data and careful testing so customers are not confused |
Whichever you choose, the code underneath should be the same: a gateway-neutral payment layer.
Build a gateway-neutral payment layer
If gateway calls are scattered through your checkout, product and admin code, every change is risky. Structure it like this instead:
- Your own order ID: Every order has an internal ID that never changes, whichever gateway processes it.
- A payments table: Each attempt records the gateway, its transaction ID, amount, method and a normalised status such as pending, success, failed or refunded.
- One adapter per gateway: Each adapter handles that gateway's request format, signatures and status codes, and translates them into your normalised statuses.
- Refunds follow the payment: A refund always goes to the gateway that took the original payment.
- Separate webhook endpoints: One per gateway, each with its own verification.
With this in place, adding PayU means writing a new adapter, not rewriting checkout.
What is specific to PayU
PayU's standard integration protects requests and responses with a SHA-512 hash. Your server builds the request hash from a fixed sequence of fields, including your merchant key, a transaction ID, the amount, product information, the customer's first name and email, user-defined fields and your secret salt. PayU returns a response hash built in reverse order with the status, which your server recalculates and compares before trusting the result. Points that catch teams out:
- The salt stays on the server. If it appears in JavaScript or a mobile app, anyone can forge hashes.
- The field order, including empty user-defined fields, must match PayU's documented sequence exactly. One missing pipe character breaks the hash.
- The transaction ID (
txnid) must be unique for every attempt. Generate a new one for each retry and link it to your own order ID. - The success and failure URLs (
surlandfurl) are browser redirects. Treat them as a display step, and confirm the result through PayU's server-to-server notifications or its verify payment API before fulfilling. - A valid hash does not replace business checks. Compare the amount with your own order record.
Our PayU integration work covers this hash handling along with EMI, recurring payments and refunds.
The parts that do not migrate easily
- Saved cards: Under RBI's card tokenisation rules, saved cards are held as tokens linked to the merchant and the provider that created them. Expect customers to save cards again, and check with both providers what is possible.
- Recurring mandates: UPI AutoPay and card mandates registered through the old gateway generally stay there. Keep the old integration running for existing subscribers and register new ones on PayU, or ask customers to re-authorise at a convenient point such as renewal.
- Refunds and disputes on old payments: These can only be handled through the gateway that took the payment. Keep that account and its admin access active while refunds and chargebacks may still arrive.
- Payment links already sent: Links issued through the old gateway keep pointing there until they expire.
- Reports: For a period, settlements arrive from two providers, and your reconciliation must handle both.
A phased rollout plan
- Complete PayU onboarding and KYC on your own account, and confirm in writing which methods, EMI options and settlement terms apply to you.
- Build the PayU adapter and test it end to end in the sandbox, including failures, refunds and duplicate notifications.
- Go live internally: staff make small real payments through PayU with each method you plan to offer.
- Send a small share of customers to PayU, for example one product line or a percentage of checkouts, while the old gateway handles the rest.
- Compare on your own data: successful payments per attempt by method, settlement accuracy, refund handling and support tickets.
- Switch the default once the results and operations are satisfactory, keeping the old gateway for refunds, mandates and disputes.
- Decommission later: remove the old checkout code, revoke unused keys and close the account only when nothing is outstanding.
Failover without double charging
If you keep two gateways, the dangerous moment is a timeout. When the first gateway does not respond, the payment may still succeed, so charging the customer again on the second gateway can produce two successful payments. Safer rules:
- Fail over at checkout, not mid-payment: If a gateway is down or its error rate is high, offer only the healthy option for new attempts.
- Let the customer choose to retry: After an unclear result, show a clear message and a retry button rather than silently charging elsewhere.
- Detect duplicates: If two payments succeed for one order, refund the extra one automatically and notify the customer.
- Give operations a switch: A simple admin toggle to disable a gateway is often more reliable than complex automatic rules.
How EthicsComputer can help
We add PayU integration to websites and apps as a primary or backup gateway on your own PayU account, with server-side hashing, verified callbacks, refunds, EMI and multi-gateway routing. A standard checkout integration typically takes one to two weeks including testing, depending on your platform. If you are still comparing providers, start with our payment gateway integration overview, and if two settlement files are already causing trouble, see payment reconciliation software.
Planning to add PayU or move away from your current gateway?
Tell us which gateway you use today and how your payments flow, and we will outline a migration plan.
About the author
Vinay Grover founded EthicsComputer in Rohtak, Haryana in 2018 and leads its cybersecurity, software and AI work for clients across India and abroad. EthicsComputer is ISO 9001, ISO/IEC 27001 and ISO 20000-1 certified.