PHP code example of opsofts / laravel-flutterwave

1. Go to this page and download the library: Download opsofts/laravel-flutterwave 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/ */

    

opsofts / laravel-flutterwave example snippets


use Opsofts\LaravelFlutterwave\Facades\Flutterwave;

// 1. Create a customer
$customer = Flutterwave::createCustomer([
    'email' => $user->email,
    'name' => ['first' => $user->first_name, 'last' => $user->last_name],
]);
$customerId = $customer['data']['id'];

// 2. Create a payment method (mobile money shown here -- no encryption needed).
// For cards, encrypt the card number/expiry/CVV client-side first; see
// "What this package deliberately does not do" below.
$paymentMethod = Flutterwave::createPaymentMethod([
    'type' => 'mobile_money',
    'mobile_money' => [
        'country_code' => '234',
        'network' => 'MTN',
        'phone_number' => '9012345678',
    ],
]);
$paymentMethodId = $paymentMethod['data']['id'];

// 3. Initiate the charge
$charge = Flutterwave::initiateCharge([
    'reference' => $orderReference,
    'currency' => 'NGN',
    'customer_id' => $customerId,
    'payment_method_id' => $paymentMethodId,
    'redirect_url' => route('payment.callback'),
    'amount' => $amount,
]);
$chargeId = $charge['data']['id'];

// 4. Handle data.next_action from step 3:
//    - redirect_url        -> redirect the payer to $charge['data']['next_action']['redirect_url']['url']
//    - payment_instruction -> show $charge['data']['next_action']['payment_instruction']['note']
//    -