adelowo/laravel-gbowo

Laravel 对 Gbowo 支付库的桥接器

1.0.0 2017-03-31 18:25 UTC

This package is auto-updated.

Last update: 2024-09-21 22:50:55 UTC


README

Latest Version on Packagist Software License Build Status

安装

$ composer require adelowo/laravel-gbowo
  • GbowoServiceProvider 添加到 config/app.php 文件的 provider 键中
Gbowo\Bridge\Laravel\GbowoServiceProvider::class
  • config/services.php 中设置默认适配器
<?php
//...other config values
"gbowo" => [
    "default" => "paystack"
];
 

此步骤是可选的,但在你确定不会在应用程序的多个地方切换适配器时,这可能很有帮助。

目前仅支持 paystackamplifypay

  • 可选,你还可以通过在 config/app.php 中的 aliases 键中添加来使用外观
"Gbowo" : Gbowo\Bridge\Laravel\Facades::class
使用

Gbowo的官方文档强烈推荐。

class BillingController extends Controller
{
    public function chargeCustomer(Request $request)
    {
        $adapter = app("gbowo")->adapter("paystack");
        // $adapter = app("gbowo")->adapter("amplifypay");

        
        $data = ["email" => $request->get('email') , "amount" => $request->get('amount')];
        
        return redirect($adapter->charge($data));
    }
}

不传递适配器名称调用 adapter 方法将返回在配置文件中设置的默认适配器的实例。

添加自定义适配器

如果你编写了自定义适配器,你可以通过在所选 ServiceProvider 中执行以下操作将其包含在你的应用程序中。

$config = ["key" => "value", "other" => "stuff"]; //some bootstrap options your adapter might need.

$this->app["gbowo"]->extend("voguepay" , function() use ($config)){
    return new VoguePayAdapter($config);
});

你可以在代码中的任何位置通过以下方式访问这个新的适配器:

$voguePay = app("gbowo")->adapter("voguePay");

$voguePay->charge(['c' => 'd']);

外观

use Gbowo\Bridge\Laravel\Facades

Gbowo::adapter("paystack")->charge([])

//You can call any method on the facade as you would in the normal instance. Do check the api methods

API 方法

  • createPaystackAdapter()
  • createAmplifyPayAdapter()
  • extend(string $adapterName, Closure $callback)
  • adapter(string $name = null)

如果 $name 留为 null,将通过检查 config.services.gbowo.default 的值来获取默认适配器

许可

MIT