Connect with us

How to Integrate Flutterwave Rave Payment System in your Laravel Applications

kizinho

Published

on

Follow
DEVELOPER PROGRAMMING: How to Integrate Flutterwave Rave Payment System in your Laravel Applications [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
site

Hi Folks, I know many laravel developers that have been using Paystack as their payment system have been finding it difficult to integrate Paystack Laravel Package from Laravel 6.0 - 7.0 versions. Today I have a beautiful solution by using Flutterwave Rave Payment System, this process will work on any laravel versions.

Requirements

  1. Running Exiting Project on Laravel
  2. Create Account on Flutterwave
  3. Then you are good to go

Lets Begin

composer require kingflamez/laravelrave

Once Flutterwave Rave for Laravel is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.

'providers' => [
 /* * Package Service Providers... */
 ... 
KingFlamez\Rave\RaveServiceProvider::class, 
...
]

Also add this to the aliases

'aliases' => [
 ... 
'Rave' => KingFlamez\Rave\Facades\Rave::class, 
...
]

Configuration

Publish the configuration file using this command:

php artisan vendor:publish
 --provider="KingFlamez\Rave\RaveServiceProvider"

Usage

Open your .env file and add your public key, secret key, environment variable and logo url like so:

RAVE_PUBLIC_KEY=FLWPUBK_TEST
-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-X
RAVE_SECRET_KEY=FLWSECK_TEST-xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx-XRAVE_TITLE="Naijacrawl"
RAVE_ENVIRONMENT="staging"
RAVE_LOGO="https://rave.flutterwave.com/
static/img/[email protected]"
RAVE_PREFIX="rave"
  • RAVE_PUBLIC_KEY - This is the api public key gotten from your dashboard (compulsory)
  • RAVE_SECRET_KEY - This is the api secret key gotten from your dashboard (compulsory)
  • RAVE_TITLE - This is the title of the modal (optional)
  • RAVE_ENVIRONMENT - This can be staging or live. Staging API keys can be gotten here while live API keys can be gotten here (compulsory)
  • RAVE_LOGO - This is a custom logo that will be displayed on the modal (optional)
  • RAVE_PREFIX - This is a the prefix added to your transaction reference generated for you (optional)
  • SECRET_HASH - This is the secret hash for your webhook, this is necessary if you are setting up a recurrent payment


1. Setup Routes


Route::post('/pay', 'RaveController@initialize')
->name('pay');
Route::post('/rave/callback',
 'RaveController@callback')->name('callback');


2. Grant CSRF Access to Rave Callback


Go to app/Http/Middleware/VerifyCsrfToken.php 

and add your callback url to the $except array

protected $except = [ 'rave/callback'];

A sample form from your frontend will look like so:

@php
$array = array(array(
'metaname' => 'color',
 'metavalue' => 'blue'),
 array('metaname' => 'size',
 'metavalue' => 'big'));
@endphp
"POST" action="{{ route('pay') }}" id="paymentForm"> {{ csrf_field() }} type="hidden" name="amount" value="500" />type="hidden" name="payment_method" value="both" />type="hidden" name="description" value="Beats by Dre. 2017" />type="hidden" name="country" value="NG" />type="hidden" name="currency" value="NGN" />type="hidden" name="email" value="[email protected]" />type="hidden" name="firstname" value="Oluwole" />type="hidden" name="lastname" value="Adebiyi" />type="hidden" name="metadata" value="{{ json_encode($array) }}" >type="submit" value="Buy" />

In this implementation, we are expecting a form encoded POST request to this script. The request will contain the following parameters.

  • payment_method Can be card, account, both
  • description Your transaction description
  • logo Your logo url
  • title Your transaction title
  • country Your transaction country
  • currency Your transaction currency
  • email Your customer's email
  • firstname Your customer's firstname
  • lastname Your customer's lastname
  • phonenumber Your customer's phonenumber
  • ref Your transaction reference.
  • It must be unique per transaction.
  • By default, the Rave class generates
  • a unique transaction reference for each
  • transaction. Pass this parameter only if
  • you uncommented the related section in
  • the script below.

3. Setup your Controller

Setup your controller to handle the routes. I created the RaveController.

Use the Rave facade.


Example


namespaceApp\Http\Controllers;
use Illuminate\Http\Request;
//use the Rave Facadeuse Rave;class RaveController extends Controller{ 
/** * Initialize Rave payment process * @return void */ 
public function initialize() {
 //This initializes payment and redirects to the payment gateway 
//The initialize method takes the parameter of the redirect URL
 Rave::initialize(route('callback')); 
} 
/** * Obtain Rave callback information 
* @return void */public function callback() {
 $data =Rave::verifyTransaction(request()->txref);
dd($data); 
// view the data response 
 if ($data->status == 'success') {
 //do something to your database
}else
 {
//return invalid payment
}
 }
}



Click Here To Comment


site


kizinho

Adike Kizito is a top-rated software developer, blogger, sports, and entertainment lover. He is the CEO of these popular websites Naijacrawl.com and Mp3ager.com. He operates his software developing task through Kizzsoft.com,... Read More

Continue Reading
2 Comments

2 Comments

  1.   Felix

    This transaction reference already exists with a different amount or currency. Please use a new transaction reference.
    when i goes live , what might be the issue?

    •   Kizito

      Might don't understand you, can you follow the package latest instruction for the flutterwave


Leave a Reply

Your email address will not be published. Required fields are marked *

How to Upgrade Laravel Application from Version 5 to latest Version 8

kizinho

Published

on

DEVELOPER PROGRAMMING: How to Upgrade Laravel Application from Version 5 to latest Version 8 [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Hi, Folks, have you feels like Laravel continuous released of new versions has let you down and you can't cope with it any longer, don't worry this article is a quick guide for you, that has I upgrade naijacrawl from 5.8 to the latest 8 versions.All you need to know before upgrading your old laravel.External packages might fail to install, so isolate your packages firstInstall fresh laravel applicationThank me later.First, all you will do to be successful when upgra...
Continue Reading

Mastering Laravel MVC (Model View Controller) and Folder Structures

kizinho

Published

on

DEVELOPER PROGRAMMING: Mastering Laravel MVC (Model View Controller) and Folder Structures [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Hi, folks, we have successfully created the laravel project in the last class, if you missed it go back and create a new laravel project here.Before going to MVC (Model View Controller) let's serve up the project for development purposes using the following commandphp artisan serve output resultStarting Laravel development server: http://127.0.0.1:8000 incase if you want to serve your project from a different port number, use the following command belowphp artisan...
Continue Reading

Laravel 8 is now released!

kizinho

Published

on

DEVELOPER PROGRAMMING: Laravel 8 is now released! [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Laravel 8 is now released and includes many new features including Laravel Jetstream, a models directory, model factory classes, migration squashing, rate-limiting improvements, time testing helpers, dynamic blade components, and many more features.Before we jump into the new features, we’d like to point out that starting with version 6, Laravel now follows semver and will release a new major version every six months. You can see how the release process works here.L...
Continue Reading

Latest


Download Naijacrawl App today

Fastest way to read on the go

Download the Naijacrawl App.