All articles

Bangladesh Payment gateway

Laravel bKash Payment Gateway Integration: Step-by-Step Guide to Accept bKash, Nagad & Bank Payments

2 December 20264 min read

Laravel bKash Payment Gateway Integration: Step-by-Step Guide to Accept bKash, Nagad & Bank Payments

Laravel is one of the most popular PHP frameworks among Bangladeshi developers, and one of the first features clients ask for is bKash checkout. This guide walks you through Laravel bKash payment gateway integration the practical way: how the payment flow works, how to structure routes, controllers and callbacks, and how to use a single gateway such as KarentPay so the same code also accepts Nagad, Rocket, Upay, Cellfin and internet banking.

Why Use a Payment Gateway Instead of Separate Wallet Integrations?

You can integrate each wallet separately, but every provider has its own onboarding, credentials, callback format and sandbox. For most Laravel projects, especially e-commerce sites, booking systems, SaaS dashboards and edtech platforms, a unified gateway saves weeks of work:

  • One API for bKash, Nagad, Rocket, Upay, Cellfin and bank payments.
  • One webhook/callback format to verify all payments.
  • One merchant dashboard for reports and reconciliation.
  • Support for automatic and manual payment methods.

How the Laravel bKash Payment Flow Works

Almost every hosted payment flow in Bangladesh follows the same pattern:

  1. Your Laravel app creates an order with status pending.
  2. Your server calls the gateway API to create a payment and receives a payment URL.
  3. The customer is redirected to the payment page and pays with bKash (or another method).
  4. The gateway redirects the customer back to your success/cancel URL and/or calls your webhook.
  5. Your server verifies the payment with the gateway and only then marks the order paid.

The most important rule: never trust the redirect alone. Always verify on the server side before delivering goods or access.

Step-by-Step Laravel bKash Payment Gateway Integration

Step 1: Get your merchant credentials

Create a merchant account at karentpay.com, complete KYC and collect your API credentials from the dashboard. Read the official API reference at karentpay.com/documentations for exact endpoint names, parameters and response fields.

Step 2: Store credentials in .env

Never hard-code keys. Add them to your .env file and read them through a config file such as config/karentpay.php, for example keys like KARENTPAY_API_KEY and KARENTPAY_BASE_URL. Keep .env out of version control.

Step 3: Create the orders table

Your orders (or payments) table should store at least: order ID, amount, currency, status (pending, paid, failed, cancelled), the gateway's transaction or invoice ID, the payment method used and timestamps. Saving the gateway reference is essential for verification and refunds.

Step 4: Define routes

  • POST /checkout/pay creates the payment and redirects the customer.
  • GET /payment/success and GET /payment/cancel handle the customer's return.
  • POST /payment/webhook receives server-to-server notifications (exclude it from CSRF protection in your middleware configuration).

Step 5: Build a PaymentService class

Keep gateway logic out of controllers. Create a PaymentService that uses Laravel's Http client to call the gateway: one method to create a payment (sending amount, order ID, customer details and your callback URLs) and one to verify a payment by its reference. Wrap calls in try/catch, set a timeout and log failures with Log::error().

Step 6: Handle the callback and verify

In your success and webhook handlers, look up the order, call the verify method and check three things: the payment status is successful, the amount matches the order, and the order is not already marked paid. Update the order inside a database transaction so a duplicate webhook cannot process the same payment twice.

Step 7: Test, then go live

Test successful, cancelled and failed payments, a webhook arriving before the redirect, and a duplicate webhook. Only then switch to live credentials.

Security Checklist for Laravel Payment Integration

  • Serve your whole site over HTTPS.
  • Verify every payment server-side; never mark an order paid from URL parameters.
  • Compare paid amount and currency with your stored order.
  • Make webhook handling idempotent.
  • Validate webhook authenticity using the method described in the gateway documentation.
  • Keep credentials in .env and rotate them if exposed.
  • Log payment events without storing sensitive customer credentials.

Using WordPress Instead of Laravel?

If part of your business runs on WordPress, you do not need custom code there: KarentPay offers a WooCommerce plugin, available on WordPress.org under the name "KarentPay". You can run the plugin on your store and the API in your Laravel app, all under one merchant account.

Why KarentPay for Laravel Developers

  • A Bangladeshi payment gateway with bKash, Nagad, Rocket, Upay, Cellfin and internet banking in one integration.
  • Automatic and manual payment methods.
  • Developer API with documentation at karentpay.com/documentations.
  • SSL-secured processing and real-time payment notifications.

FAQ: Laravel bKash Payment Gateway

Is there a Laravel bKash package?

Community packages exist for individual wallets, but they usually cover only one provider. Using a gateway's REST API with Laravel's built-in HTTP client gives you bKash plus other methods with one integration.

How do I integrate bKash payment gateway in Laravel?

Create a pending order, call the gateway API to create a payment, redirect the customer, then verify the payment server-side on callback before marking the order paid.

Can I accept Nagad and bKash in the same Laravel checkout?

Yes. With KarentPay the customer chooses the method on the payment page, so your Laravel code stays the same.

Do I need a trade licence?

Merchant onboarding requires KYC. Check KarentPay's KYC requirements on its website for the current document list.

Start Your Integration

Ready to add bKash, Nagad and bank payments to your Laravel project? Create your KarentPay merchant account and read the API documentation to get started.






More guides and news

Payments in Bangladesh, explained for businesses.

All articles