PHP code example of prevailexcel / laravel-flick

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

    

prevailexcel / laravel-flick example snippets


'providers' => [
    ...
    PrevailExcel\Flick\FlickServiceProvider::class,
    ...
]

'aliases' => [
    ...
    'Flick' => PrevailExcel\Flick\Facades\Flick::class,
    ...
]



return [
    
    /**
     * Public Key From FLICK Dashboard
     *
     */
    'secretKey' => getenv('FLICK_SECRET_KEY'),

    /**
     * You enviroment can either be live or stage.
     * Make sure to add the appropriate API key after changing the enviroment in .env
     *
     */
    'env' => env('FLICK_ENV', 'live'), // OR "sandbox"

    /**
     * FLICK Base URL
     *
     */
    'baseUrl' => env('FLICK_LIVE_URL', "https://flickopenapi.co"),

];

// Laravel 8 & above
Route::post('/pay', [PaymentController::class, 'createPayment'])->name('pay');
Route::flick_callback(PaymentController::class, 'handleGatewayCallback');
Route::flick_webhook(WebhookController::class, 'handleWebhook');



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use PrevailExcel\Flick\Facades\Flick;

class PaymentController extends Controller
{

    /**
     * Redirect the User to Flick Payment Page
     * @return Url
     */
    public function redirectToGateway()
    {
        try{
            return Flick::getLink()->redirectNow();
        }catch(\Exception $e) {
            return Redirect::back()->withMessage(['msg'=> $e->getMessage(), 'type'=>'error']);
        }        
    }

    /**
     * Obtain Flick payment information
     * @return void
     */
    public function handleGatewayCallback()
    {
        $paymentDetails = flick()->getPaymentData();

        dd($paymentDetails);
        // Now you have the payment details,
        // you can store the reference ID in your db.
        // you can then redirect or do whatever you want
    }
}

/**
 *  In the case where you need to pass the data from your
 *  controller or via your client or app instead of a form
 *  
 */
 $data = [       
        'email' => "[email protected]",
        'Phoneno' => "08100000000",
        'amount' => "9000", // in naira
    ];

    // if monolithic, do
    return Flick::getLink($data)->redirectNow();

    // if API, do
    return Flick::getLink($data, true);


 $data = [       
        'email' => "[email protected]",
        'Phoneno' => "08100000000",
        'amount' => "9000", // in naira

        'transactionId' => "Generate your own ID",
        'currency_collected' => "NGN", // USD, GBP, CAD
        'currency_settled' => 'NGN', // USD, GBP, CAD
    ];



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PrevailExcel\Flick\Facades\Flick;

class PaymentController extends Controller
{  
    /**
     * You collect data from your blade form
     * and this returns the Account details for payment
     */
    public function createPayment()
    {
        try {
            // You can use the global helper flick()->method() or the Facade Flick::method().
           
           
            $card = "eZl0T7elDC3VWefiqYT4RujW7t...";

            return Flick::chargeCard($card);
            
        } catch (\Exception $e) {
            return redirect()->back()->withMessage(['msg' => $e->getMessage(), 'type' => 'error']);
        }
    }
}

    public function handleWebhook()
    {
        // verify webhook and get data
        flick()->getWebhookData()->proccessData(function ($data) {
            // Do something with $data
            logger($data);
            $decodedData = json_decode($data, true);
            // Do Something with $decodedData
            
            // If you have heavy operations, dispatch your queued jobs for them here
            // OrderJob::dispatch($decodedData);
        });
        
        // Acknowledge you received the response
        return http_response_code(200);
    }

protected $except = [
    'flick/webhook',
];

->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: [
        'flick/webhook', 
    ]);
})


/**
 * OTP verification
 *
 * @param string $otp
 * @param string $ref transaction ref or id.
 * @return array
 */
Flick::verifyOtp($otp, $ref);
// Or
flick()->verifyOtp($otp, $ref);

/**
 * PIN verification
 *
 * @param string $pin
 * @param string $ref transaction ref or id.
 * @return array
 */
Flick::verifyPin($pin, $ref);
// Or
flick()->verifyPin($pin, $ref);

/**
 * Get Info About Card
 */
Flick::lookupCard($card_first_six_digits);


/**
 * Check your balance for the different currencies and categories available. Default is payouts.
 * 
 * @param null|string $category  Can be payouts, walletapi, or collections
 * @param null|string $currency  NGN, USD, GBP, or CAD. Default is NGN
 * @returns array
 */
Flick::checkBalance();

/**
 * Get Flick exchange rate. Either of the parameters must be NGN
 *
 * @param null|string $from  NGN, USD, GBP, or CAD. Default is NGN
 * @param null|string $to  NGN, USD, GBP, or CAD. Default is NGN
 *
 * @return array
 */
Flick::exchangeRate(?string $from = null, ?string $to = null);

/**
 * Generate transfer history statements with custom date ranges
 * @returns array
 */
Flick::transferHistory($data);

/**
 * Move funds from your Flick balance to a bank account.
 * @returns array
 */
Flick::transfer($data = null);

/**
 * Get all the bank codes for all existing banks in our operating countries.
 * @returns array
 */
Flick::banks();

/**
 * Verify the status of a transaction carried out on your Flick account
 * @returns array
 */
Flick::verifyTransaction(?string $ref = null);
// Or
request()->ref = "transactionId";
flick()->verifyTransaction();

/**
 * Resend webhook for a transaction.
 * @returns array
 */
Flick::resendWebhook(?string $ref = null);
// Or
request()->ref = "transactionId";
flick()->resendWebhook();

/**
 * Verify the status of a transfer carried out from your Flick account 
 * @returns array
 */
Flick::verifyTransfer(?string $ref = null);

/**
 * Verify the owner of a bank account using the bank code and the account uumber 
 * @returns array
 */
Flick::confirmAccount(?string $bank_code = null, ?string $account_number = null);

bash
php artisan vendor:publish --provider="PrevailExcel\Flick\FlickServiceProvider"