krisnasw / faspay
一个用于 Faspay 支付网关的 Laravel 扩展包
v1.0.0
2017-08-28 06:49 UTC
Requires
- php: >=7.1.0
- guzzlehttp/guzzle: ^6.3
- illuminate/support: 5.4.*
- nesbot/carbon: ^1.22
- spatie/array-to-xml: ^2.6
This package is not auto-updated.
Last update: 2024-09-29 04:46:09 UTC
README
如果你的项目需要使用 Faspay 作为支付网关,那么这个扩展包就是为你准备的。这是一个用于与 Faspay 支付网关 API 通信的 Laravel 扩展包(目前仅支持 DEBIT API)
安装
要开始使用 Faspay,运行此命令或将其添加到你的 composer.json
composer require krisnasw/faspay dev-master
配置
安装 Faspay 扩展包后,在 config/app.php 文件中注册 Krisnasw\Faspay\FaspayServiceProvider。同时,将 Faspay 和 Payment 门面添加到 app 配置文件中的 aliases 数组
'Faspay' => Krisnasw\Faspay\Facades\Faspay::class, 'Payment' => Krisnasw\Faspay\Facades\Payment::class,
最后发布配置文件
php artisan vendor:publish --provider="Krisnasw\Faspay\FaspayServiceProvider"
并更改 config/faspay.php 中的 merchant_id、merchant_name、user_id 和 password 为你自己的信息。
使用方法
设置完成后,可以这样使用这个 Faspay 扩展包
// Customer class example. You can apply to any model you want. use Krisnasw\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 Krisnasw\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(\Krisnasw\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。请随意向我报告你发现的任何错误或发送 pull requests。