How to integrate Flutterwave v3 Payment Gateway in PHP » Fulloaded      
           



promote

Developers

How to integrate Flutterwave v3 Payment Gateway in PHP



How to integrate Flutterwave v3 Payment Gateway in PHP – Fulloaded




Welcome to Fulloaded Developers (FL Dev) i believe you landed here because you have been Searching/ Looking for How to integrate Flutterwave v3 Payment Gateway in PHP  # Tutorial

In this simple article i will have to take you through the Fluttervave document to easily implement the system into your PHP project.

So Let Get Started!

How to integrate Flutterwave to my website

 

Throughout this process we create just 3 files in our project named: index, pay and process

Index.php

 

<!DOCTYPE html> <html> <head> <meta charset=“utf-8”> <meta http-equiv=“X-UA-Compatible” content=“IE=edge”> <title>Rave payment Gateway</title> <meta name=“description” content=“”> <meta name=“viewport” content=“width=device-width, initial-scale=1”> <link rel=“stylesheet” href=“”> </head> <body> <form action=“pay.php” method=“POST”> <label>Email</label> <input type=“email” name=“email”> <br> <label>Amount</label> <input type=“number” name=“amount”> <br> <input type=“submit” name=“pay” vlaue=“Send Payment”> </form> </body> </html>

 

pay.php

 

<?php if(isset($_POST[‘pay’])) { $email = $_POST[’email’]; $amount = $_POST[‘amount’]; //* Prepare our rave request $request = [ ‘tx_ref’ => time(), ‘amount’ => $amount, ‘currency’ => ‘NGN’, ‘payment_options’ => ‘card’, ‘redirect_url’ => ‘http://localhost/yt/rave/process.php’, ‘customer’ => [ ’email’ => $email, ‘name’ => ‘Zubdev’ ], ‘meta’ => [ ‘price’ => $amount ], ‘customizations’ => [ ‘title’ => ‘Paying for a sample product’, ‘description’ => ‘sample’ ] ]; //* Ca;; f;iterwave emdpoint $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => ‘https://api.flutterwave.com/v3/payments’, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => , CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => ‘POST’, CURLOPT_POSTFIELDS => json_encode($request), CURLOPT_HTTPHEADER => array( ‘Authorization: Bearer FLWSECK_TEST-eee25be1b44ef9a132a872075b3a0910-X’, ‘Content-Type: application/json’ ), )); $response = curl_exec($curl); curl_close($curl); $res = json_decode($response); if($res->status == ‘success’) { $link = $res->data->link; header(‘Location: ‘.$link); } else { echo ‘We can not process your payment’; } } ?>

 

process.php

 

<?php if(isset($_GET[‘status’])) { //* check payment status if($_GET[‘status’] == ‘cancelled’) { // echo ‘YOu cancel the payment’; header(‘Location: index.php’); } elseif($_GET[‘status’] == ‘successful’) { $txid = $_GET[‘transaction_id’]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => “https://api.flutterwave.com/v3/transactions/{$txid}/verify”, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => “”, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => “GET”, CURLOPT_HTTPHEADER => array( “Content-Type: application/json”, “Authorization: Bearer FLWSECK_TEST-eee25be1b44ef9a132a872075b3a0910-X” ), )); $response = curl_exec($curl); curl_close($curl); $res = json_decode($response); if($res->status) { $amountPaid = $res->data->charged_amount; $amountToPay = $res->data->meta->price; if($amountPaid >= $amountToPay) { echo ‘Payment successful’; //* Continue to give item to the user } else { echo ‘Fraud transactio detected’; } } else { echo ‘Can not process payment’; } } } ?>

 

If you have any issue or problem base on this please use the comment below to nofify me i will surly get back as soon as possible.

watch the video tutorial by www.codewigs.com

 

How to integrate Flutterwave to my website

Flutterwave mobile money

Flutterwave API

Flutterwave laravel

Leave a Comment

Do you find Fulloaded useful? Click here to give us five stars rating!





No one has commented yet. Be the first!
Leave a Reply