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


'businessName' => env('BUSINESS_NAME', 'Flutterwave Store'),
'transactionPrefix' => env('TRANSACTION_PREFIX', 'LARAVEL-'),
'logo' => env('BUSINESS_LOGO', 'https://res.cloudinary.com/decagon/image/upload/v1593642339/decagon-logo.png'),
'title' => env('TITLE', 'Flutterwave Store'),
'description' => env('DESCRIPTION', 'Flutterwave Store Description'),
'country' => env('COUNTRY', 'NG'),
'currency' => env('CURRENCY', Currency::NGN),
'paymentType' => [
    'card', 'account', 'banktransfer', 'mpesa', 'mobilemoneyrwanda', 'mobilemoneyzambia',
    'mobilemoneyuganda', 'ussd', 'qr', 'mobilemoneyghana', 'credit', 'barter',
    'payattitude', 'mobilemoneyfranco', 'mobilemoneytanzania', 'paga', '1voucher',
],

use Flutterwave\Payments\Facades\Flutterwave;
use Flutterwave\Payments\Data\Currency;

$payload = [
    "tx_ref" => Flutterwave::generateTransactionReference(),
    "amount" => 100,
    "currency" => Currency::NGN,
    "customer" => [
        "email" => "[email protected]"
    ],
];

$payment_details = Flutterwave::render('inline', $payload);

return view('flutterwave::modal', compact('payment_details'));


use Flutterwave\Payments\Facades\Flutterwave;
use Flutterwave\Payments\Data\Currency;

$payload = [
    "tx_ref" => Flutterwave::generateTransactionReference(),
    "amount" => 100,
    "currency" => Currency::NGN,
    "customer" => [
        "email" => "[email protected]"
    ],
];

$payment_link = Flutterwave::render('standard', $payload);

return redirect($payment_link);

'flutterwave' => [
    'driver' => 'single',
    'path' => storage_path('logs/flutterwave.log'),
    'level' => 'debug',
],


use Flutterwave\Payments\Facades\Flutterwave;
use Flutterwave\Payments\Data\Status;

Route::post('flutterwave/payment/webhook', function () {
    $method = request()->method();
    if ($method === 'POST') {
        //get the request body
        $body = request()->getContent();
        $webhook = Flutterwave::use('webhooks');
        $transaction = Flutterwave::use('transactions');
        //get the request signature
        $signature = request()->header($webhook::SECURE_HEADER);

        //verify the signature
        $isVerified = $webhook->verifySignature($body, $signature);

        if ($isVerified) {
            [ 'tx_ref' => $tx_ref, 'id' => $id ] = $webhook->getHook();
            [ 'status' => $status, 'data' => $transactionData ] = $transaction->verifyTransactionReference($tx_ref);

            $responseData = ['tx_ref' => $tx_ref, 'id' => $id];
            if ($status === 'success') {
                switch ($transactionData['status']) {
                    case Status::SUCCESSFUL:
                        // do something
                        //save to database
                        //send email
                        break;
                    case Status::PENDING:
                        // do something
                        //save to database
                        //send email
                        break;
                    case Status::FAILED:
                        // do something
                        //save to database
                        //send email
                        break;
                }
            }

            return response()->json(['status' => 'success', 'message' => 'Webhook verified by Flutterwave Laravel Package', 'data' => $responseData]);
        }

        return response()->json(['status' => 'error', 'message' => 'Access denied. Hash invalid'])->setStatusCode(401);
    }

    // return 404
    return abort(404);
})->name('flutterwave.webhook');
unit
shell
$ php artisan vendor:publish --provider="Flutterwave\Payments\Providers\FlutterwaveServiceProvider"