A lightweight Laravel package to integrate the GetPay Nepal payment gateway.
- PHP: ^8.0
- Laravel (Illuminate): 9.x, 10.x, 11.x, 12.x
- Package name:
neputertech/getpay-gateway
This package ships a Facade-first API, pre-wired routes, and publishable views/config to help you start accepting payments quickly.
composer require neputertech/getpay-gatewayLaravel package auto-discovery will register the service provider automatically.
- Config:
php artisan vendor:publish --provider="NeputerTech\GetpayGateway\GetpayServiceProvider" --tag=getpay-config- Views (if you want to customize the built-in screens):
php artisan vendor:publish --tag=getpay-viewsAdd the following to your .env (values provided by GetPay):
GETPAY_PAP_INFO=your-pap-info
GETPAY_OPR_KEY=your-operator-key # optional depending on your account
GETPAY_INS_KEY=your-ins-key # optional depending on your account
GETPAY_BASE_URL=https://api.getpay.example # e.g. https://api.getpay.com.np
GETPAY_BUNDLE_URL=https://widget.getpay.example/bundle.js # GetPay checkout bundle URLConfig keys live in config/getpay.php:
getpay.pap_infogetpay.opr_keygetpay.ins_keygetpay.base_urlgetpay.bundle_url
Import and use the Facade Getpay to kick off a checkout and to verify the payment on the callback.
<?php
use Illuminate\Http\Request;
use NeputerTech\GetpayGateway\Facades\Getpay;
class PaymentController
{
public function pay(Request $request)
{
$refID = 'ORD-'.now()->timestamp; // your unique order reference
// Redirects to the package's checkout route with all required details
return Getpay::init(
refID: $refID,
amount: 1000.00, // numeric value
currency: 'NPR', // currency code
callbackUrl: route('payments.getpay.callback'),
failUrl: route('payments.getpay.failed'),
businessName: 'Acme Inc', // optional
imageUrl: asset('images/logo.png'), // optional
themeColor: '#2F855A', // optional (hex)
orderInfoUi: null // optional (custom UI payload)
);
}
}This redirects to the built-in getpay.checkout page which loads the GetPay bundle and starts the checkout.
GetPay will redirect back to your callbackUrl with a token. Verify it using the Facade:
<?php
use Illuminate\Http\Request;
use NeputerTech\GetpayGateway\Exceptions\GetpayException;
use NeputerTech\GetpayGateway\Facades\Getpay;
class PaymentController
{
public function callback(Request $request)
{
$token = $request->query('token');
try {
$status = Getpay::verify($token); // returns the gateway response array
// Example success check
if (data_get($status, 'message') === 'SUCCESS') {
// TODO: mark order as paid using $status
return redirect()->route('thankyou')->with('status', 'Payment successful');
}
return redirect()->route('payments.getpay.failed')
->withErrors('Payment not successful.');
} catch (GetpayException $e) {
// 4001: Token decoding failed
// 4002: Invalid token data
// 4003: Gateway error
// 4004: Transaction failed
return redirect()->route('payments.getpay.failed')
->withErrors($e->getMessage());
}
}
public function failed()
{
return back()->withErrors('Payment cancelled/failed.');
}
}Example routes:
// routes/web.php
Route::get('/payments/getpay/callback', [PaymentController::class, 'callback'])
->name('payments.getpay.callback');
Route::get('/payments/getpay/failed', [PaymentController::class, 'failed'])
->name('payments.getpay.failed');- Service container binding: key
getpay(singleton) - Facade class:
NeputerTech\GetpayGateway\Facades\Getpay - Shipped routes (auto-loaded via the service provider):
GET /getpay/checkoutnamedgetpay.checkout– used byGetpay::init()for the handoff screenGET /getpay/paymentnamedgetpay.payment– basic payment view (optional)
- View namespace:
getpay-views::getpay-views::checkoutgetpay-views::payment
- Blade component namespace:
getpay-*(registered), e.g. you can render the checkout script component if customizing views:
{{-- Only if you customize/publish views --}}
<div id="checkout"></div>
<script src="{{ config('getpay.bundle_url') }}"></script>
<x-getpay-getpay-scripts
:refID="$refID"
:amount="$amount"
:callbackUrl="$callbackUrl"
:failUrl="$failUrl"
currency="NPR"
/>Note: The package defaults should work out of the box. Customize only if you need to fully control the UI.
You can fake the gateway verification call:
use Illuminate\Support\Facades\Http;
use NeputerTech\GetpayGateway\Facades\Getpay;
Http::fake([
config('getpay.base_url').'/merchant-status' => Http::response([
'message' => 'SUCCESS',
'id' => 'example-id',
], 200),
]);
$result = Getpay::verify(base64_encode(json_encode([
'id' => 'example-id',
'oprSecret' => 'secret',
])));
$this->assertSame('SUCCESS', data_get($result, 'message'));- Invalid or missing token → ensure your
callbackUrlreceives atokenquery param and pass it toGetpay::verify(). - 4003 "Gateway error" → verify
GETPAY_BASE_URLis reachable and correct. - "Transaction failed" → the gateway returned a non-success status; inspect the response array from
verify().
MIT © NeputerTech