rick20/faspay

该软件包最新版本(0.1.0)没有可用的许可证信息。

Faspay 支付网关的 Laravel 软件包。

0.1.0 2017-04-19 03:19 UTC

This package is auto-updated.

Last update: 2024-09-05 19:57:08 UTC


README

如果你的项目需要使用 Faspay 作为支付网关,那么这个软件包就是为你准备的。这是一个用于与 Faspay 支付网关 API(目前仅支持 DEBIT API)通信的 Laravel 软件包

安装

要开始使用 Faspay,请运行此命令或将其添加到你的 composer.json

composer require rick20/faspay

配置

安装 Faspay 软件包后,在你的 config/app.php 文件中注册 Rick20\Faspay\FaspayServiceProvider。同时,将 FaspayPayment 门面添加到你的 app 配置文件中的 aliases 数组

'Faspay' => Rick20\Faspay\Facades\Faspay::class,
'Payment' => Rick20\Faspay\Facades\Payment::class,

最后发布配置文件

php artisan vendor:publish --provider="Rick20\Faspay\FaspayServiceProvider"

并更改 config/faspay.php 中的 merchant_idmerchant_nameuser_idpassword 为你的值。

如何使用

设置完成后,可以使用以下方式使用 Faspay 包

// Customer class example. You can apply to any model you want.

use Rick20\Faspay\CustomerInterface;

class Customer implements CustomerInterface
{
  public function getFaspayCustomerNumber()
  {
    return 'customer-number';
  }

  public function getFaspayCustomerName()
  {
    return 'customer-name';
  }

  public function getFaspayCustomerEmail()
  {
    return 'customer-email';
  }
  
  public function getFaspayCustomerPhone()
  {
    return 'customer-phone';
  }

  public function getFaspayPreferredCurrency()
  {
    return 'customer-currency';
  }
}
// Item class example. You can apply to any model you want.

use Rick20\Faspay\Payable;

class Item implements Payable
{
  public function getPayableName()
  {
    return 'Product Name';
  }

  public function getPayablePrice()
  {
    return 300000;
  }
}
// An example how to use the API.

Route::get('/', function () {

  $customer = new Customer();
  $payable = new Item();

  $payment = Payment::performedBy($customer)
    ->via('web')
    ->payWith('tcash')
    ->addTax(10)
    ->addMiscFee(1000);

  $payment->addItem($payable, 2);

  $response = Faspay::registerPayment($payment);

  return Faspay::redirectToPay($payment);
});

Route::get('/callback-notif', function(\Illuminate\Http\Request $request) {
  return Faspay::notified($request, function(\Rick20\Faspay\Notification $notification) {
    return $notification;
  });
});

要生成自定义的账单号码/代码,你可以创建一个实现了 BillingProfileInterface 的类,例如

class TopupBillingProfile implements BillingProfileInterface
{
  public function description()
  {
    return 'Topup Saldo'; 
  }

  public function generate(Payment $payment)
  {
    return str_random(15);
  }
}

然后将其作为 registerPayment() 方法的第二个参数传递。

错误 & 改进

这个软件包还远未完美。它还不支持 BCA KlikPay。它也不支持 Faspay Credit API。欢迎向我报告您发现的任何错误或发送拉取请求。