edwardmuss/flutterwave-laravel

Flutterwave Rave 的 Laravel 扩展包

v1.0.3 2023-01-22 16:17 UTC

This package is auto-updated.

Last update: 2024-09-23 21:00:25 UTC


README

Latest Version on Packagist Software License Total Downloads

使用 Laravel 框架轻松实现 Flutterwave Rave 支付网关

文档

安装

先决条件

PHP、Laravel 和 composer

要获取 Flutterwave 的最新版本,只需使用 composer

composer require edwardmuss/flutterwave-laravel

配置

使用以下命令发布配置文件

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

名为 flutterwave.php 的配置文件将放置在您的 config 目录

打开您的 .env 文件并添加您的 public keysecret keysecret hash,如下所示

这里 获取您的密钥

FLW_PUBLIC_KEY=FLWPUBK-xxxxxxxxxxxxxxxxxxxxx-X
FLW_SECRET_KEY=FLWSECK-xxxxxxxxxxxxxxxxxxxxx-X
FLW_SECRET_HASH='My_lovelysite123'
  • FLW_PUBLIC_KEY - 这是您的仪表板中获取的 API 公钥(必需)
  • FLW_SECRET_KEY - 这是您的仪表板中获取的 API 私钥(必需)
  • FLW_SECRET_HASH - 这是您的 webhook 的密钥哈希

用法

1. 设置路由

// The page that displays the payment form
Route::get('/', function () {
    return view('welcome');
});
// The route that the button calls to initialize payment
Route::post('/pay', [FlutterwaveController::class, 'initialize'])->name('paynow');
// The callback url after a payment
Route::get('/rave/callback', [FlutterwaveController::class, 'callback'])->name('callback');
  1. 设置支付页面

一个示例支付按钮将看起来像这样

welcome.blade.php
<h3>Buy me Coffee</h3>
<form method="POST" action="{{ route('paynow') }}">
    {{ csrf_field() }}

    <input name="name" placeholder="Name" />
    <input name="email" type="email" placeholder="Your Email" />
    <input name="phone" type="tel" placeholder="Phone number" />

    <input type="submit" value="Buy me Coffee" />
</form>

  1. 设置您的控制器

    设置您的控制器以处理路由。我创建了 FlutterwaveController。使用 Rave 作为 Flutterwave 门面。

示例

<?php

namespace App\Http\Controllers;

use EdwardMuss\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' => "KES",
            'redirect_url' => route('callback'),
            'customer' => [
                'email' => request()->email,
                "phone_number" => request()->phone,
                "name" => request()->name
            ],

            "customizations" => [
                "title" => 'Buy Me Coffee',
                "description" => "Let express love of coffee"
            ]
        ];

        $payment = Flutterwave::initializePayment($data);


        if ($payment['status'] !== 'success') {
            // notify something went wrong
            return;
        }

        return redirect($payment['data']['link']);
    }

    /**
     * Obtain Rave callback information
     * @return void
     */
    public function callback()
    {
        
        $status = request()->status;

        //if payment is successful
        if ($status ==  'successful') {
        
        $transactionID = Flutterwave::getTransactionIDFromCallback();
        $data = Flutterwave::verifyTransaction($transactionID);

        dd($data);
        }
        elseif ($status ==  'cancelled'){
            //Put desired action/code after transaction has been cancelled here
        }
        else{
            //Put desired action/code after transaction has failed here
        }
        // 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

    }
}

鸣谢

贡献

请随意分叉此包并通过提交拉取请求来贡献以增强功能。我将非常感激。同时,请将您的姓名添加到鸣谢中。

请在 Instagram 上关注我!

功能

当前功能已实现

  • 支付
  • 验证
  • 转账
  • 银行
  • 受益人

如果您迫切需要某些功能,我愿意优先考虑它们,请通过我的推特账号联系我

许可

MIT 许可证 (MIT)。请参阅 许可文件 以获取更多信息。