To integrate PayU (formerly PayUmoney) in CodeIgniter, create a controller that builds the payment fields and a SHA-512 hash from your merchant key and salt, a view that auto-submits them to PayU, and success and failure routes that verify PayU's response hash before updating the order.
This guide uses CodeIgniter 4 conventions (namespaced controllers, .env configuration, CSRF-safe routing) and PHP 8.x. The older CodeIgniter 3 approach of storing the salt in a database table and echoing it into a page is replaced here with server-side configuration, because a leaked key and salt let anyone forge payments.
orders table with at least id, txnid, amount, status and the customer's name and email.Add the credentials to the .env file, which must not be committed to Git.
For production, set the endpoint to https://secure.payu.in/_payment and use live credentials. Confirm both URLs in PayU's current documentation.
Register one route for each step in app/Config/Routes.php.
PayU posts back from another site, so these two routes must be excluded from CodeIgniter's CSRF filter. Add payu/success and payu/failure to the CSRF filter's except list in app/Config/Filters.php, and rely on the hash check for authenticity instead.
The amount comes from the orders row, never from the request. Create the order with a random txnid (for example bin2hex(random_bytes(10))) before the customer reaches this page.
Create app/Views/payu/redirect.php. The esc() helper escapes every value.
Add these methods to the same controller. They recompute the hash PayU describes for responses: the salt, the status, empty padding, the udf fields in reverse order, then email, first name, product info, amount, transaction id and key.
The update only runs for a pending order, so a repeated notification does not pay an order twice.
| Mistake | Why it hurts | Fix |
|---|---|---|
| Salt stored in a view or sent to the browser | Anyone can sign fake payments | Keep it in .env, hash on the server |
| Trusting a posted amount | A customer can pay 1 rupee for a 1000 rupee order | Read the amount from the order row |
| Skipping response hash checks | Forged success posts mark orders paid | Verify with hash_equals() |
| Marking paid only on the browser return | Customers who close the tab are never recorded | Enable PayU webhooks and reconcile |
| Using HTTP callback URLs | Data can be read or altered in transit | Use HTTPS everywhere |
The hash logic is identical. In CodeIgniter 3 use $this->input->post(), $this->load->view() and config.php instead of .env, and keep the same security rules.
In environment variables or a .env file outside the web root and out of Git. Do not keep them in a public view or an unprotected table.
Use the PayU test endpoint and the sandbox credentials from your merchant dashboard, then follow PayU's documented test card details.
Enable the PayU webhook in the dashboard and update orders from it, using the same hash verification and idempotent updates.
Build the hash on the server from your key, salt and order data, post the fields to PayU, and verify the response hash, amount and order state before marking anything paid. Keep credentials in .env, read amounts from your database, and back up the browser return with a webhook.