ok
Direktori : /home2/selectio/www/myclassicfit.com-1/vendor/kingflamez/laravelrave/docs/verification/ |
Current File : /home2/selectio/www/myclassicfit.com-1/vendor/kingflamez/laravelrave/docs/verification/callback.md |
# Callbacks If the `redirect_url` is added to your payment data, Flutterwave redirects there after every payment request ## 1. Setup your callback route ```php // The callback url after a payment Route::get('/rave/callback', [FlutterwaveController::class, 'callback'])->name('callback'); ``` ## 2. Setup your Controller > Setup your controller to handle the routes. I created the `FlutterwaveController`. Use the `Flutterwave` > facade. ```php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use KingFlamez\Rave\Facades\Rave as Flutterwave; class FlutterwaveController extends Controller { /** * Obtain Flutterwave callback information * @return void */ public function callback() { $transactionID = Flutterwave::getTransactionIDFromCallback(); $data = Flutterwave::verifyTransaction($transactionID); dd($data); // 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 $data['data']['status'] is 'successful' // 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 } } ``` ## 3. Make sure to add `'redirect_url' => route('callback'),` to all your payment requests that will use the callback eg ```php <?php namespace App\Http\Controllers; use KingFlamez\Rave\Facades\Rave as Flutterwave; class FlutterwaveController extends Controller { /** * Initialize Rave payment process * @return void */ public function initialize() { //This generates a payment reference $reference = Flutterwave::generateReference(); // Enter the details of the payment $data = [ 'payment_options' => 'card,banktransfer', 'amount' => 500, 'email' => request()->email, 'tx_ref' => $reference, 'currency' => "NGN", 'redirect_url' => route('callback'), 'customer' => [ 'email' => request()->email, "phonenumber" => request()->phone, "name" => request()->name ], "customizations" => [ "title" => 'Movie Ticket', "description" => "20th October" ] ]; $payment = Flutterwave::initializePayment($data); if (!$payment) { // notify something went wrong return; } return redirect($payment['link']); } /** * Obtain Rave callback information * @return void */ public function callback() { $transactionID = Flutterwave::getTransactionIDFromCallback(); $data = Flutterwave::verifyTransaction($transactionID); dd($data); // 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 $data['data']['status'] is 'successful' // 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 } } ```