fahipaydev/gateway-laravel
Laravel 13+ integration for the FahiPay payment gateway (Maldives). Create and query transactions, handle redirects and callbacks, verify signatures, track payments via migrations/models, and use events/facades. Includes test mode and install artisan command.
composer require fahipaydev/gateway-laravel
php artisan vendor:publish --provider="FahiPay\Gateway\GatewayServiceProvider" --tag="config"
.env:
FAHIPAY_MERCHANT_ID=your_merchant_id
FAHIPAY_SECRET_KEY=your_secret_key
FAHIPAY_CALLBACK_URL=https://yourdomain.com/fahipay/callback
routes/web.php):
Route::post('/fahipay/callback', [FahiPayCallbackController::class, 'handleCallback']);
use FahiPay\Gateway\Facades\FahiPay;
$transaction = FahiPay::createTransaction([
'amount' => 1000, // MVR (e.g., 1000 = MVR 10.00)
'currency' => 'MVR',
'description' => 'Order #12345',
'customer_email' => 'user@example.com',
'customer_name' => 'John Doe',
'redirect_url' => route('payment.success'),
'cancel_url' => route('payment.cancel'),
]);
$transaction->payment_url.// 1. Initiate transaction (returns payment_url)
$txn = FahiPay::createTransaction($data);
// 2. Redirect user to $txn->payment_url
return redirect()->away($txn->payment_url);
// 3. Handle callback (automatically verifies signature)
public function handleCallback(Request $request) {
$response = FahiPay::handleCallback($request);
if ($response->isSuccessful()) {
// Update order status, send confirmation, etc.
}
}
For high-security scenarios (e.g., subscriptions), use silent post by:
FAHIPAY_SILENT_POST_URL in .env.signature in the callback payload:
$isValid = FahiPay::validateCallbackSignature($request->all());
// Poll transaction status (e.g., for async workflows)
$status = FahiPay::getTransactionStatus($transactionId);
if ($status->status === 'completed') {
// Process payment
}
transaction_id and status in your orders table.FahiPay\Events\TransactionCreated, FahiPay\Events\TransactionUpdated) to trigger actions:
// In EventServiceProvider
protected $listen = [
'FahiPay\Events\TransactionCreated' => [
OrderPaid::class,
],
];
FahiPay facade with mock responses:
$this->mock(FahiPay::class)->shouldReceive('createTransaction')
->once()
->andReturn((object) ['payment_url' => 'https://test.fahipay.mv']);
php artisan vendor:publish --provider="FahiPay\Gateway\GatewayServiceProvider" --tag="views"
resources/views/vendor/fahipay/redirect.blade.php for branding.Signature Mismatch:
FAHIPAY_SECRET_KEY..env.$request->all() and compare with FahiPay’s expected payload.Amount Formatting:
1000).amount field is an integer, not a float.Redirect URLs:
redirect_url/cancel_url must be HTTPS and publicly accessible.https://yourdomain.com/payment/success).Idempotency:
idempotency_key in createTransaction():
$txn = FahiPay::createTransaction([
'amount' => 1000,
'idempotency_key' => 'unique_order_123',
]);
.env:
FAHIPAY_LOG_ENABLED=true
FAHIPAY_LOG_LEVEL=debug
FAHIPAY_ENVIRONMENT=sandbox).Custom Fields: Add metadata to transactions:
$txn = FahiPay::createTransaction([
'amount' => 1000,
'custom_fields' => [
'order_id' => 123,
'user_id' => 456,
],
]);
Retrieve via getTransactionStatus():
$status = FahiPay::getTransactionStatus($txn->transaction_id);
$orderId = $status->custom_fields['order_id'];
Webhook Overrides:
Extend FahiPay\Services\CallbackHandler to add custom logic:
FahiPay::extend(function ($service) {
$service->onCallback(function ($payload) {
// Custom logic (e.g., log to third-party system)
});
});
Rate Limiting: Throttle API calls to avoid hitting FahiPay’s limits:
use Illuminate\Cache\RateLimiting\Limit;
RateLimiter::for('fahipay', function (Request $request) {
return Limit::perMinute(10)->by($request->user()?->id);
});
How can I help you explore Laravel packages today?