PHP code example of abraham-flutterwave / laravel-payment

1. Go to this page and download the library: Download abraham-flutterwave/laravel-payment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abraham-flutterwave / laravel-payment example snippets


return Flutterwave::redirect(['amount' => 5000, 'email' => '[email protected]']);

use Flutterwave\Payments\Facades\Flutterwave;

Route::post('/pay', function () {
    return Flutterwave::redirect([
        'amount' => 5000,
        'currency' => 'NGN',            // optional, defaults to FLW_DEFAULT_CURRENCY
        'email' => auth()->user()->email,
        'meta' => ['order_id' => 42],   // optional, returned in webhooks
    ]);
});

return Inertia::render('Checkout', [
    'checkout' => Flutterwave::inlineConfig(['amount' => $order->total, 'email' => $user->email, 'tx_ref' => 'ORDER-'.$order->id]),
]);

return Inertia::render('Checkout', [
    'order' => $order->only('id', 'paid'),
    'checkout' => Flutterwave::inlineConfig(['amount' => $order->total, 'email' => $order->email, 'tx_ref' => 'ORDER-'.$order->id]),
    'account' => Flutterwave::virtualAccounts()->dynamicFor($order->email, $order->total, 'ORDER-'.$order->id),
]);

Route::get('/flutterwave/payment/callback', function (Request $request) {
    $order = Order::where('reference', $request->tx_ref)->firstOrFail();

    if ($request->transaction_id && Flutterwave::isSuccessful($request->transaction_id, $order->amount, $order->currency, $order->reference)) {
        $order->markAsPaid();

        return redirect()->route('orders.show', $order);
    }

    return redirect()->route('checkout')->with('error', 'Payment was not completed.');
});

use Flutterwave\Payments\Events\ChargeCompleted;
use Illuminate\Support\Facades\Event;

// e.g. in AppServiceProvider::boot()
Event::listen(function (ChargeCompleted $event) {
    if (! $event->isSuccessful()) {
        return;
    }

    $order = Order::where('reference', $event->reference())->first();

    if ($order && $event->amount() >= $order->amount && $event->currency() === $order->currency) {
        $order->markAsPaid();
    }
});

// Look up the account name before sending money
$account = Flutterwave::banks()->resolveAccount('0690000032', '044');

$transfer = Flutterwave::transfers()->create([
    'account_bank' => '044',
    'account_number' => '0690000032',
    'amount' => 5500,
    'currency' => 'NGN',
    'narration' => 'Vendor payout',
]);

Flutterwave::transfers()->bulk([...], 'March payroll');
Flutterwave::transfers()->fee(5500, 'NGN');
Flutterwave::transfers()->rates(1000, 'NGN', 'USD');
Flutterwave::transfers()->find($id);
Flutterwave::transfers()->retry($id);

Flutterwave::banks()->resolveAccount('0690000032', '044');                // Nigerian bank account
Flutterwave::banks()->resolveAccount('0031625807099', 'GH190101', 'GH');  // Ghanaian bank account
Flutterwave::banks()->resolveAccount('233542773934', 'MTN', 'GH');        // Ghanaian mobile money: phone number + provider code
Flutterwave::banks()->resolveMerchant('7981223');                         // Flutterwave merchant ID

Flutterwave::transfers()->create([
    'account_bank' => '044',
    'account_number' => '0690000031',
    'amount' => 5500,
    'currency' => 'NGN',
    'test_outcome' => 'success',  // or 'failure'
    'test_resolve_after' => 1,    // minutes; Flutterwave's default is 10
]);

use Flutterwave\Payments\Data\Stablecoin;

// Check the fee first. For stablecoin-to-stablecoin sends it is deducted from the amount.
Flutterwave::stablecoins()->fee(50, Stablecoin::USDT);

// Pay from your USDC balance
Flutterwave::stablecoins()->send(Stablecoin::POLYGON, '0xd0c7...', 50, Stablecoin::USDC);

// Or convert from NGN and pay in one step (the fee is charged to your NGN balance)
Flutterwave::stablecoins()->send(Stablecoin::SOLANA, '7EcDh...', 50, Stablecoin::USDT, 'NGN');

// Top up your USDC wallet from NGN, USD, GBP, EUR or GHS (needs FLW_MERCHANT_ID)
Flutterwave::stablecoins()->fund(100, Stablecoin::USDC, 'USD');

Flutterwave::stablecoins()->balances();   // ['USDC' => [...], 'USDT' => [...]]
Flutterwave::stablecoins()->find($transferId);

$plan = Flutterwave::plans()->create('Pro', 5000, 'monthly');

// Subscribe a customer by checking out against the plan
return Flutterwave::redirect([
    'amount' => 5000,
    'email' => $user->email,
    'payment_plan' => $plan['data']['id'],
]);

Flutterwave::subscriptions()->all(['email' => $user->email]);
Flutterwave::subscriptions()->cancel($subscriptionId);

use Flutterwave\Payments\Billable;

class User extends Authenticatable
{
    use Billable;
}

Event::listen(function (ChargeCompleted $event) {
    if ($event->isSuccessful() && ($event->transaction['payment_type'] ?? null) === 'card') {
        User::where('email', $event->customerEmail())->first()?->saveFlutterwaveCard($event->transaction);
    }
});

$user->flutterwaveCard()?->label();        // "MASTERCARD ending 2950"
$charge = $user->chargeSavedCard(5000, ['narration' => 'October plan']);

$hold = $user->preauthorizeSavedCard(20000);
$ref = $hold['data']['flw_ref'];

Flutterwave::preauth()->capture($ref, 15000);  // charge part or all of it, once or several times
Flutterwave::preauth()->void($ref);            // or release the hold
Flutterwave::preauth()->refund($ref, 5000);    // give back money you captured

$account = Flutterwave::virtualAccounts()->create([
    'email' => $user->email,
    'is_permanent' => true,
    'bvn' => '12345678901',
    'narration' => $user->name,
]);

$account['data']['account_number']; // your customer pays into this account

$account = Flutterwave::virtualAccounts()->dynamicFor($order->email, $order->total, 'ORDER-'.$order->id, ['expires' => 1800]);

// ['account_number' => '9519802749', 'bank_name' => 'Flutterwave MFB', 'amount' => '5070.00', 'currency' => 'NGN',
//  'tx_ref' => 'ORDER-42', 'expires_at' => '2026-10-14T12:30:00+00:00', 'expires_in' => 1800, 'note' => '...', ...]

return Inertia::render('Checkout', ['account' => $account]);

$wallet = Flutterwave::payoutSubaccounts()->create('Jane Doe', '[email protected]', 'NG', '08100000000');
$reference = $wallet['data']['account_reference'];   // store this on the customer

$wallet['data']['nuban'];                            // the account number to fund it
Flutterwave::payoutSubaccounts()->balance($reference);
Flutterwave::payoutSubaccounts()->transactions($reference, '2026-10-01', '2026-10-31');

$open = Flutterwave::chargebacks()->all(['status' => 'initiated']);
Flutterwave::chargebacks()->find($flwRef);  // one chargeback with its history

// The customer didn't get what they paid for: refund them
Flutterwave::chargebacks()->accept($chargebackId, 'Order was never shipped.');

// You have evidence they did: upload it and dispute
Flutterwave::chargebacks()->declineWithProof($chargebackId, 'Delivered on 3 October and signed for.', $request->file('proof'));

Event::listen(function (ChargebackUpdated $event) {
    if ($event->needsResponse()) {
        Notification::route('mail', '[email protected]')->notify(new ChargebackRaised($event->data));
    }
});

$quote = Flutterwave::fx()->quote('NGN', 'USD', 2_000_000, 'FX-ORDER-7');  // spend NGN 2,000,000 on dollars

// When the quote is ready (usually seconds later), check the rate and trade it
$ready = Flutterwave::fx()->findQuote($quote['data']['id'])['data'];
// $ready['status'] === 'READY'; $ready['quote']['best_available_rate'], ['approved_quantity'], ['total_value']

$trade = Flutterwave::fx()->tradeIfReady($ready['id'], 'Supplier payment');
Flutterwave::fx()->findTrade($trade['data']['id']);  // NEW, PENDING, then SETTLED or FAILED

Flutterwave::bills()->categories();          // AIRTIME, MOBILEDATA, CABLEBILLS, UTILITYBILLS...
Flutterwave::bills()->billers('CABLEBILLS'); // DSTV is BIL119
Flutterwave::bills()->items('BIL119');       // DSTV Premium is CB140, with its price and fee

$payment = Flutterwave::bills()->payValidated('BIL119', 'CB140', $smartcardNumber, 14600);

Flutterwave::bills()->status($payment['data']['tx_ref']);
Flutterwave::bills()->history(['status' => 'Failed']);

$consent = Flutterwave::bvn()->requestConsent($bvn, $firstName, $lastName, route('kyc.done'));
// Store $consent['data']['reference'], then send the customer to $consent['data']['url'] to consent.

// When they come back:
Flutterwave::bvn()->matches($reference, $firstName, $lastName);  // true once consented and the names match

// routes/web.php
Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
    Route::flutterwaveAdmin();  // POST admin/flutterwave/chargebacks/{id}/accept|decline, admin/flutterwave/fx/quotes|trades
});

// AppServiceProvider::boot()
Gate::define('flutterwave.manage', fn (User $user) => $user->is_admin);

return Inertia::render('Admin/Payments', [
    'chargebacks' => Flutterwave::chargebacks()->panel(['status' => 'initiated']),
    'fx' => Flutterwave::fx()->panel($request->query('fx_quote'), $request->query('fx_trade')),
]);

return Inertia::render('Admin/Money', [
    'transactions' => Flutterwave::transactions()->panel($request->query()),
    'refunds' => Flutterwave::refunds()->panel($request->query()),
    'settlements' => Flutterwave::settlements()->panel($request->query()),
    'beneficiaries' => Flutterwave::beneficiaries()->panel($request->query()),
]);

use Flutterwave\Payments\Notifications\ChargebackRaised;

$admin->notify(new ChargebackRaised($event->data, ['mail', 'database']));

$vendor = Flutterwave::subaccounts()->create([
    'account_bank' => '044',
    'account_number' => '0690000037',
    'business_name' => 'Jane Store',
    'business_mobile' => '09087930450',
    'country' => 'NG',
    'split_type' => 'percentage',
    'split_value' => 0.1,
]);

Flutterwave::redirect([
    'amount' => 10000,
    'email' => '[email protected]',
    'subaccounts' => [['id' => $vendor['data']['subaccount_id']]],
]);

Flutterwave::transactions()->all(['status' => 'successful', 'from' => '2026-10-01']);  // last 30 days when no dates are given
Flutterwave::transactions()->timeline($transactionId);    // every step the customer took
Flutterwave::transactions()->fee(10000, 'NGN', 'card');   // what Flutterwave charges on a payment
Flutterwave::transactions()->resendFailedHooks($transactionId);

Flutterwave::refund($transactionId);                                  // full refund
Flutterwave::refund($transactionId, 1000, ['comments' => 'Damaged']); // partial, with a reason
Flutterwave::refunds()->all(['status' => 'completed']);
Flutterwave::refunds()->find($refundId);

Flutterwave::settlements()->all(['from' => '2026-10-01']);
Flutterwave::settlements()->find($settlementId);          // 

use Flutterwave\Payments\Exception\FlutterwaveException;

try {
    Flutterwave::transfers()->create($payload);
} catch (FlutterwaveException $e) {
    $e->getMessage();     // "Insufficient wallet balance"
    $e->getStatusCode();  // 400
    $e->getResponse();    // full Flutterwave response body
}

use Flutterwave\Payments\Facades\Flutterwave;

it('starts a checkout for the order total', function () {
    $flutterwave = Flutterwave::fake();

    $this->post('/orders/42/pay')->assertRedirect();

    $flutterwave->assertCheckoutCreated(fn (array $payment) => $payment['amount'] === 5000);
});

Flutterwave::fake()->transaction(4975363, ['amount' => 5000, 'currency' => 'NGN', 'tx_ref' => 'ORDER-42']);

use Flutterwave\Payments\Testing\FlutterwaveFake;

$this->postJson('/flutterwave/webhook', ['event' => 'charge.completed', 'data' => ['id' => 4975363]], FlutterwaveFake::webhookHeaders());
shell
php artisan vendor:publish --tag=flutterwave-views
shell
php artisan flutterwave:install --billable
php artisan migrate