wychoong / lunarphp-mpgs
Lunar 的 MPGS 支付适配器
v0.1.2
2023-04-14 14:13 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
- illuminate/contracts: ^9.0 | ^10.0
- illuminate/support: ^9.0 | ^10.0
- livewire/livewire: ^2.0
- lunarphp/core: ^0.3.0-alpha.2
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-09-09 05:55:53 UTC
README
为 Lunar 提供的 MPGS 托管 checkout 集成
支持的操作
- 购买
不支持(欢迎提交 PR)
- 退款
- 授权/捕获
安装
您可以通过 composer 安装此包
composer require wychoong/lunarphp-mpgs
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="lunarphp-mpgs-config"
启用驱动程序
在 config/lunar/payments.php
中设置驱动程序
<?php return [ // ... 'types' => [ 'card' => [ 'driver' => 'stripe', 'authorized' => 'payment-received', # or any status key configured in lunar.orders.statuses ], ], ];
###添加您的 MPGS 凭证 在 .env
中设置 MPGS_ 变量
MPGS_MERCHANT_ID= MPGS_API_PASSWORD= MPGS_VERSION=
设置
我们使用闭包来返回您要传递给 API 的数据
use \WyChoong\Mpgs\Facades\Mpgs; // in service provider `boot` method Mpgs::initiateCheckoutUsing(function ($cart, $amount, $currency): array { if (!$order = $cart->order) { $order = $cart->createOrder(); } $reference = $order->reference . date('Ymdhis'); return [ // refer to the api spec for Initiate Checkout params 'order' => [ 'id' => $reference, 'currency' => $currency, 'amount' => $amount, 'description' => "Payment for #" . $order->reference, 'reference' => $reference, ], 'transaction' => [ 'reference' => $reference, ], 'interaction' => [ 'merchant' => [ 'name' => 'Lunar store', ], 'displayControl' => [ 'billingAddress' => 'HIDE', ] ] ]; });
后端使用
创建 PaymentIntent
use \WyChoong\Mpgs\Facades\Mpgs; Mpgs::createIntent(\Lunar\Models\Cart $cart);
此方法将启动一个用于 checkout.js
的结算会话。最新会话和订单 ID 存储在购物车的元数据中
'meta' => [ 'payment_intent' => `session`, 'order_id' => `order.id`, ],
前端使用
此包仅提供基本 blade 组件与 MPGS 交互,发布视图以适应您的店面设计
php artisan vendor:publish --tag="lunarphp-mpgs-views"
设置脚本和支付组件
在您的结账页面
@mpgsScripts @if ($paymentType == 'card') <livewire:mpgs.payment :cart="$cart" /> @endif
该组件将为您处理成功支付。要重定向或支付验证后添加处理,请设置您的路由或监听 livewire 事件
// config/lunar-mpgs.php 'route' => [ 'payment-success' => null, 'payment-failed' => null, ] // livewire events 'mpgsPaymentSuccess' 'mpgsPaymentFailed'
路线图
- 如果适用,支持捕获/退款
- 实现 omnipay-mpgs 适配器
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
贡献
有关详细信息,请参阅 CONTRIBUTING
安全漏洞
有关如何报告安全漏洞的信息,请参阅 我们的安全策略
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件