bhekor/laravel-flutterwave

用于 flutterwave 的 Laravel 扩展包

v0.0.1 2022-03-08 12:18 UTC

This package is auto-updated.

Last update: 2024-09-30 01:19:45 UTC


README

Latest Version on Packagist Software License Total Downloads

使用 Laravel 实现Flutterwave Rave支付网关

要获取此 Flutterwave 扩展包的最新版本,只需使用 composer

composer require bhekor/laravel-flutterwave

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

php artisan vendor:publish --provider="Bhekor\LaravelFlutterwave\FlutterwaveServiceProvider"

打开您的 .env 文件,并添加公钥、私钥、环境变量和标志 URL,如下所示

FLW_PUBLIC_KEY=FLWPUBK-xxxxxxxxxxxxxxxxxxxxx-X
FLW_SECRET_KEY=FLWSECK-xxxxxxxxxxxxxxxxxxxxx-X
FLW_SECRET_HASH='awesome-project'
  • FLW_PUBLIC_KEY - 这是您的仪表板中获取的 API 公钥(必填)

  • FLW_SECRET_KEY - 这是您的仪表板中获取的 API 秘钥(必填)

  • FLW_SECRET_HASH - 这是您的 webhook 的密钥散列

welcome.blade.php

<h3>Buy Movie Tickets N500.00</h3>
<form method="POST" action="{{ route('pay') }}" id="paymentForm">
    {{ 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" />
</form>

设置控制器以处理路由。 FlutterwaveController。然后导入 Flutterwave 门面

<?php

namespace App\Http\Controllers;

use Bhekor\LaravelFlutterwave\Facades\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,
                "phone_number" => request()->phone,
                "name" => request()->name
            ],

            "customizations" => [
                "title" => 'Movie Ticket',
                "description" => "20th October"
            ]
        ];

        $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

    }
}

设置路由

// 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('pay');
// The callback url after a payment
Route::get('/rave/callback', [FlutterwaveController::class, 'callback'])->name('callback');

文档

有关本扩展包的友好文档可以在此处找到 这里

贡献

请随时fork此扩展包,通过提交拉取请求来增强功能。我会非常感激。另外,请将您的名字添加到致谢中。

请关注我的推特

功能

当前已实现的功能

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

接下来我将致力于此

  • 令牌化费用
  • 预授权费用

如果您需要的功能紧急,我将愿意优先处理,请通过我的推特账号联系我

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件