artisanpay / artisanpay-laravel
用于在 Laravel 中进行支付的 Laravel 扩展包
0.4.8
2022-02-21 18:08 UTC
Requires
- php: ^7.4|^8.0|^8.1
- illuminate/support: ^7.0|^8.0|^9.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.0.1
- nunomaduro/larastan: ^0.7.12
- orchestra/testbench: ^6.0|^7.0
- phpunit/phpunit: ^9.0
README
安装
您可以通过 composer 安装此包
composer require artisanpay/artisanpay-laravel
安装包
php artisan artisanpay:install
在 .env 配置文件中添加 artisanpay API 令牌
ARTISANPAY_TOKEN=xxxxxxxxxxxxxxxxxx
生成处理支付的作业
php artisan make:job ArtisanpayHookHandleJob
将作业添加到配置文件中的调度器部分
<?php return [ /** * ------------------------------------------- * Api Token provide buy ArtisanPay * ------------------------------------------- */ 'token' => env('ARTISANPAY_TOKEN'), 'base_url' => env('ARTISANPAY_BASE_URL', 'https://app.artisanpay.com/api/v1'), /** * -------------------------------------------- * A Job to Handler Hook Payment * --------------------------------------------- */ 'job' => \App\Jobs\ArtisanpayHookChargeJob::class, // ArtisanWebookHandler::class , /** * ---------------------------------------------- * URL route to handle payment * ---------------------------------------------- * */ 'url_webhook' => env('ARTISANPAY_WEBHOOK', 'api/artisanpay/hooks'), 'process_manuelly' => false // indicate if you to define your own controller and route ];
用法
创建支持本版本 2 操作员的 artisanpay 支付
注意:没有前缀的电话 ( 691131446) OrangeMoney ==> 'om' MTN Mobile Money ==> 'momo'
$data = $request->validate([ 'phone' => 'required', // 6911131446, 651881356 'amount' => 'required', 'operator' => 'required' ]); // for operator you can use const class Operator try{ $chargeResponse = ArtisanPay::charge( (new ChargeRequest($request->phone, $request->amount, $request->operator , "my-internal-id")) ); }catch(Exception $exception){ }
无异常
$chargeResponse = ArtisanPay::withoutException()->charge(ChargeRequest("691131446", 500, Operator::OM, "my-internal-id"));
处理支付钩子的作业
<?php namespace App\Jobs; use ChargeHookResponse; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; class ArtisanpayHookChargeJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; private ChargeHookResponse $chargeHookResponse /** * Create a new job instance. * @param ChargeHookResponse $name * @return void */ public function __construct(ChargeHookResponse $chargeHookResponse) { $this->chargeHookResponse = $chargeHookResponse; } /** * Execute the job. * * @return void */ public function handle() { $myInternalId = $this->getRefId(); $artisanPayId = $this->getId(); $amount = $this->getAmount(); $amountCharge = $this->getAmountCharge(); // etc ... if($this->chargeHookResponse->getStatus() === ChargeStatus::SUCCESS){ $this->proccessSuccess(); }else{ $this->proccessFailed(); } } private function proccessSuccess() { // make operation in case success } private function proccessFailed() { // make operation in case failed } }
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件 artisanpay@gmail.com 反馈,而不是使用问题跟踪器。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。