larva / laravel-pay
This is a pay.
1.0.6
2023-03-10 07:16 UTC
Requires
- php: ^8.0.2
- ext-json: *
- illuminate/bus: ^9.0|^10.0
- illuminate/database: ^9.0|^10.0
- illuminate/events: ^9.0|^10.0
- illuminate/http: ^9.0|^10.0
- illuminate/queue: ^9.0|^10.0
- illuminate/support: ^9.0|^10.0
- nyholm/psr7: ^1.5
- symfony/psr-http-message-bridge: ^2.1
- yansongda/pay: ^3.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- laravel/framework: ^9.0|^10.0
README
这是一个内部收单系统,依赖 yansongda/pay
这个组件,本收单系统,统一了调用。
备注,交易单位是分;2.x 和 3.x 版本对外接口一致,只是内部调用的第三方接口版本不同,本扩展拉齐了开发体验;
环境需求
- PHP ^8.0.2
安装
composer require "larva/laravel-pay"
事件
AppServiceProvider 的 boot 中注册 路由
\Larva\Pay\Pay::routes();
在中间件 App\Http\Middleware\VerifyCsrfToken
排除支付回调相关的路由,如:
protected $except = [ // ... 'pay', ];
你自己的订单关联
/** * @property Charge $change */ class Order extends Model { /** * Get the entity's charge. * 这里关联付款模型 * @return \Illuminate\Database\Eloquent\Relations\MorphOne */ public function charge() { return $this->morphOne(Charge::class, 'order'); } /** * 设置交易成功 */ public function markSucceeded() { $this->update(['channel' => $this->charge->trade_channel, 'status' => static::STATUS_PAY_SUCCEEDED, 'succeeded_at' => $this->freshTimestamp()]); } /** * 设置交易失败 */ public function markFailed() { $this->update(['status' => static::STATUS_FAILED]); } /** * 发起退款 * @param string $reason 退款描述 * @return Model|Refund * @throws Exception */ public function refund(string $reason) { if ($this->paid && $this->charge->allowRefund) { $refund = $this->charge->refund($reason); $this->update(['refunded' => true]); return $refund; } throw new Exception ('Not paid, no refund.'); } }