cyvelnet / laravel-billplz
Billplz为laravel提供的灵活的计费和支付解决方案
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ~5.3|~6.0
- illuminate/support: ^5.0
Requires (Dev)
- orchestra/testbench: 3.1.*
This package is auto-updated.
Last update: 2024-09-08 22:26:46 UTC
README
Laravel-billplz 是一个简单的服务提供者和生成器,可以将您的 laravel 驱动的应用程序连接到 Billplz api v3。
在开始之前,请访问 https://www.billplz.com/enterprise/signup 注册账户,并阅读 https://www.billplz.com/api#v3 以更好地了解。
安装
使用以下命令通过 composer 安装此包
composer require cyvelnet/laravel-billplz
更新并安装后,将服务提供者添加到 config/app.php
文件中的 providers
数组
Cyvelnet\LaravelBillplz\LaravelBillplzServiceProvider::class
最后,将外观添加到 config/app.php
中的 aliases
数组部分
Cyvelnet\LaravelBillplz\Facades\Billplz::class
如何使用
账单API
创建账单
创建Billplz账单
\Billplz::issue(function (Cyvelnet\LaravelBillplz\Messages\BillMessage $bill) { // bill with a amount RM50 $bill->to('name', 'email', 'mobile') ->amount(50) // will multiply with 100 automatically, so a RM500 bill, you just pass 500 instead of 50000 ->callbackUrl('http://foorbar.com/foo/bar/webhook/') ->description('description'); });
对于任何缺少参数的调用,将抛出一个 UnacceptableRequestException。
或者,您可以使用 artisan 命令 php artisan make:bill MonthlyManagementBill
生成可重复使用的账单
\Billplz::send(new MonthlyManagementBill()) ->to('foobar') ->viaEmail('foo@bar.com') // you may use viaSms('mobile no') or viaEmailAndSms('email', 'mobile no')
删除现有账单
$request = \Billplz::delete('bill_id'); if($request->isSuccess()) { // perform after deletion operation }
检索账单
$bill = \Billplz::get('bill_id')->toArray();
对于任何缺失的账单,将抛出一个 BillNotFoundException。
集合API
创建集合
$request = \Billplz::collection('collection title'); if($request->isSuccess()) { $collection = $request->toArray() // you can call getRawBillplzResponse(false) to get response in POPO }
要进一步自定义您的集合,请作为第二个参数传递一个匿名函数
$request = \Billplz::collection('collection title', function (\Cyvelnet\LaravelBillplz\Messages\CollectionMessage $collection) { // split a payment by RM50 $collection->logo(storage_path('/billplz/my-logo.jpg')) ->splitPaymentByFixed('foo@bar.com', 50) // will convert into 5000 cents automatically });
创建具有固定金额的开放集合
// create a open collection with a fixed amount RM500 $request = \Billplz::openCollection('collection title', 'collection description', 500); if($request->isSuccess()) { $collection = $request->toArray() // you can call getRawBillplzResponse(false) to get response in POPO }
创建具有任何金额和数量的开放集合,请作为第三个参数传递一个闭包
// create a open collection with a fixed amount RM500 $request = \Billplz::openCollection('collection title', 'collection description', function (\Cyvelnet\LaravelBillplz\Messages\OpenCollectionMessage $collection) { $collection->anyAmountAndQty(); // ->splitPaymentByVariable('foo@bar.com', 50); // split payment by 50% // ->tax(6) // 6% tax // ->photo(storage_path('/billplz/my-photo.jpg')) // ->reference1('your references') }); if($request->isSuccess()) { $collection = $request->toArray() // you can call getRawBillplzResponse(false) to get response in POPO }
沙盒
Billplz api v3 启用了沙盒功能,允许开发者在沙盒中隔离 API 请求并按需触发支付完成。
默认情况下,沙盒是禁用的,要启用沙盒模式,请添加一个 BILLPLZ_ENABLE_SANDBOX = true
条目到 .env 文件,并确保您已正确配置了生产环境和沙盒的 api_key 和 collection_id。