nutandc / nepal-payment-gateway
Nepal payment gateway integration for Laravel: eSewa, Khalti, ConnectIPS, optional Stripe, idempotent and secure.
Requires
- php: ^8.2
- ext-curl: *
- ext-openssl: *
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.92
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpstan/phpstan: ^1.11
- phpstan/phpstan-phpunit: ^1.4
- phpunit/phpunit: ^10.0
- stripe/stripe-php: ^15.0
Suggests
- stripe/stripe-php: Required for Stripe gateway when enabled.
README
Laravel-first payment gateway package for Nepal gateways with optional Stripe support. Built for PHP 8.2+ and Laravel 10+ with clean, typed, and configurable services.
Features
- Nepal gateways: eSewa, Khalti, ConnectIPS
- Optional Stripe integration (Checkout Session)
- Config-driven endpoints and credentials (no hardcoded URLs)
- Idempotency support to prevent duplicate transactions
- PSR-3 logging and structured error handling
- SOLID, typed, and testable services
Gateway flags
| Gateway | Config Key | Default |
|---|---|---|
| eSewa | NEPAL_PAYMENT_ESEWA_ENABLED |
true |
| Khalti | NEPAL_PAYMENT_KHALTI_ENABLED |
true |
| ConnectIPS | NEPAL_PAYMENT_CONNECTIPS_ENABLED |
true |
| Stripe | NEPAL_PAYMENT_STRIPE_ENABLED |
false |
Requirements
- PHP 8.2+
- Laravel 10/11/12
- Extensions:
ext-curl,ext-openssl
Installation
composer require nutandc/nepal-payment-gateway
Publish config:
php artisan vendor:publish --tag=nepal-payment-suite-config
Configuration
Copy .env.example values into your Laravel .env file and update them for your gateway accounts.
Set .env values as needed (examples):
NEPAL_PAYMENT_GATEWAY=esewa NEPAL_PAYMENT_ESEWA_ENABLED=true NEPAL_PAYMENT_ESEWA_BASE_URL=your_esewa_base_url NEPAL_PAYMENT_ESEWA_ENDPOINT_INITIATE=your_esewa_initiate_path NEPAL_PAYMENT_ESEWA_ENDPOINT_VERIFY=your_esewa_verify_path NEPAL_PAYMENT_ESEWA_PRODUCT_CODE=your_product_code NEPAL_PAYMENT_ESEWA_SECRET_KEY=your_secret_key NEPAL_PAYMENT_KHALTI_ENABLED=true NEPAL_PAYMENT_KHALTI_BASE_URL=your_khalti_base_url NEPAL_PAYMENT_KHALTI_ENDPOINT_INITIATE=your_khalti_initiate_path NEPAL_PAYMENT_KHALTI_ENDPOINT_LOOKUP=your_khalti_lookup_path NEPAL_PAYMENT_KHALTI_SECRET_KEY=your_secret_key NEPAL_PAYMENT_CONNECTIPS_ENABLED=true NEPAL_PAYMENT_CONNECTIPS_BASE_URL=your_connectips_base_url NEPAL_PAYMENT_CONNECTIPS_ENDPOINT_INITIATE=your_connectips_initiate_path NEPAL_PAYMENT_CONNECTIPS_ENDPOINT_VERIFY=your_connectips_verify_path NEPAL_PAYMENT_CONNECTIPS_MERCHANT_ID=your_merchant_id NEPAL_PAYMENT_CONNECTIPS_APP_ID=your_app_id NEPAL_PAYMENT_CONNECTIPS_APP_NAME=your_app_name NEPAL_PAYMENT_CONNECTIPS_PRIVATE_KEY=/path/to/private.pem NEPAL_PAYMENT_CONNECTIPS_PRIVATE_KEY_PASSPHRASE=optional_passphrase NEPAL_PAYMENT_CONNECTIPS_PASSWORD=your_password NEPAL_PAYMENT_LOGGING_ENABLED=true NEPAL_PAYMENT_IDEMPOTENCY_ENABLED=true NEPAL_PAYMENT_IDEMPOTENCY_TTL=86400 NEPAL_PAYMENT_STRIPE_ENABLED=false NEPAL_PAYMENT_STRIPE_SECRET=your_stripe_secret
Usage
All gateways are accessed via the GatewayManager service.
eSewa (payment + verify)
use Nutandc\NepalPaymentSuite\Services\GatewayManager; $gateway = app(GatewayManager::class)->esewa(); $payment = $gateway->payment([ 'amount' => '1000', 'tax_amount' => '0', 'total_amount' => '1000', 'transaction_uuid' => 'txn_123', 'product_code' => 'YOUR_PRODUCT_CODE', 'success_url' => route('esewa.success'), 'failure_url' => route('esewa.failure'), ]); // Auto-submit HTML form: echo $payment->redirectForm(); $verify = $gateway->verify([ 'transaction_uuid' => 'txn_123', 'total_amount' => '1000', 'product_code' => 'YOUR_PRODUCT_CODE', ]); if ($verify->isSuccess()) { // handle success }
Khalti (payment + verify)
use Nutandc\NepalPaymentSuite\Services\GatewayManager; $gateway = app(GatewayManager::class)->khalti(); $payment = $gateway->payment([ 'return_url' => route('khalti.return'), 'website_url' => config('app.url'), 'amount' => 1000, 'purchase_order_id' => 'order_123', 'purchase_order_name' => 'Order #123', ]); return redirect()->away($payment->redirectUrl()); $verify = $gateway->verify([ 'pidx' => 'pidx_123', ]);
ConnectIPS (payment + verify)
use Nutandc\NepalPaymentSuite\Services\GatewayManager; $gateway = app(GatewayManager::class)->connectIps(); $payment = $gateway->payment([ 'transaction_id' => 'txn_123', 'transaction_amount' => 1000, 'remarks' => 'Order payment', 'particulars' => 'Order #123', 'reference_id' => 'ref_123', 'success_url' => route('connectips.success'), 'failure_url' => route('connectips.failure'), ]); echo $payment->redirectForm(); $verify = $gateway->verify([ 'reference_id' => 'ref_123', 'transaction_amount' => 1000, ]);
Stripe (optional)
Install the Stripe SDK and enable the gateway:
composer require stripe/stripe-php
NEPAL_PAYMENT_STRIPE_ENABLED=true NEPAL_PAYMENT_STRIPE_SECRET=sk_test_xxx
Usage (amount is in the smallest currency unit, e.g. cents):
use Nutandc\NepalPaymentSuite\Services\GatewayManager; $gateway = app(GatewayManager::class)->stripe(); $payment = $gateway->payment([ 'amount' => 1500, 'currency' => 'usd', 'product_name' => 'Subscription', 'success_url' => route('stripe.success'), 'cancel_url' => route('stripe.cancel'), ]); return redirect()->away($payment->redirectUrl());
Idempotency
Pass a custom idempotency key for any payment call:
$gateway->payment($payload, 'order-123');
Testing
composer install
composer test
composer analyse
composer fix:dry
License
MIT