actionm / laravel-webmoney-merchant
Laravel 的 WebMoney 商户支付
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ~6.2
- laravel/framework: ^5.3.10
Requires (Dev)
- orchestra/testbench: ^3.3.3
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-28 18:42:36 UTC
README
通过使用此 Laravel 框架包(Laravel)接受 WebMoney 商户支付(merchant.webmoney.ru)。
- 只需添加两个回调即可接收付款
- 通过您的电子邮件或 Slack 接收付款通知
您可以通过 WebMoney、信用卡等方式通过 WebMoney 商户接收付款
Laravel 5.3, 5.4, PHP >= 5.6.4
安装
您可以通过 Composer 安装此包
composer require actionm/laravel-webmoney-merchant
将服务提供者添加到 config/app.php
中的 providers
数组
'providers' => [ ActionM\WebMoneyMerchant\WebMoneyMerchantServiceProvider::class, ]
将 WebMoneyMerchant
门面添加到您的门面数组
'WebMoneyMerchant' => ActionM\WebMoneyMerchant\Facades\WebMoneyMerchant::class,
发布配置文件和视图
php artisan vendor:publish --provider="ActionM\WebMoneyMerchant\WebMoneyMerchantServiceProvider"
只发布配置文件
php artisan vendor:publish --provider="ActionM\WebMoneyMerchant\WebMoneyMerchantServiceProvider" --tag=config
只发布视图
php artisan vendor:publish --provider="ActionM\WebMoneyMerchant\WebMoneyMerchantServiceProvider" --tag=views
配置
一旦您已发布配置文件,请编辑 config/webmoney-merchant.php
中的配置文件。
-
在 merchant.webmoney.ru 上创建一个账户
-
设置您的项目设置
- 商户名称;
- 密钥;
- 密钥 X20;
- 结果 URL;
- 控制签名生成方法 =
SHA256
; - 必需要求签名付款表单 =
ON
; - 仅处理具有唯一 lmi_payment_no 的付款 =
ON
;
-
配置发布后,编辑
config/webmoney-merchant.php
-
复制
密钥 X20
和密钥
参数,并将其粘贴到config/webmoney-merchant.php
-
为
searchOrderFilter
和paidOrderFilter
设置回调静态函数 -
设置通知渠道(电子邮件和/或 Slack)和 Slack
webhook_url
使用方法
- 生成启用付款方式的 HTML 付款表单
$payment_amount = Order amount $payment_no = Unique order number in your project, numbers only from 1 to 2147483647 $item_name = Name of your order item, only latin characters.
WebMoneyMerchant::generatePaymentForm($payment_amount, $payment_no, $item_name);
在发布的视图中自定义 HTML 付款表单
app/resources/views/vendor/webmoney-merchant/payment_form.blade.php
- 处理来自 WebMoneyMerchant 的请求
WebMoneyMerchant::payOrderFromGate(Request $request)
重要
您必须在 config/webmoney-merchant.php
中定义回调来搜索订单并保存已付款订单。
'searchOrderFilter' => null // ExampleController:searchOrderFilter($request)
'paidOrderFilter' => null // ExampleController::paidOrderFilter($request,$order)
示例
处理方案
- 请求来自
merchant.webmoney.ru
的GET
请求http://yourproject.com/webmoney/result
以检查您的网站是否可用。 - 请求来自
merchant.webmoney.ru
的POST
请求http://yourproject.com/webmoney/result
(带有参数)。 - 函数
ExampleController@payOrderFromGate
执行验证过程(自动验证请求参数)。 - 将调用静态函数
searchOrderFilter
(请参阅config/webmoney-merchant.php
中的searchOrderFilter
)以通过唯一 ID 搜索订单。 - 如果当前订单状态在您的数据库中不是
已支付
,则将调用静态函数paidOrderFilter
(请参阅config/webmoney-merchant.php
中的paidOrderFilter
)。
将路由添加到 routes/web.php
Route::post('/webmoney/result', 'ExampleController@payOrderFromGate'); Route::get('/webmoney/result', 'ExampleController@payOrderFromGateOK');
注意:不要忘记在 merchant.webmoney.ru 上保存您的完整路由 URL(例如,http://example.com/webmoney/result)以供您的项目使用。
创建以下控制器: /app/Http/Controllers/ExampleController.php
class ExampleController extends Controller { /** * Search the order if the request from WebMoney Merchant is received. * Return the order with required details for the webmoney request verification. * * @param Request $request * @param $order_id * @return mixed */ public static function searchOrderFilter(Request $request, $order_id) { // If the order with the unique order ID exists in the database $order = Order::where('unique_id', $order_id)->first(); if ($order) { $order['WEBMONEY_orderSum'] = $order->amount; // from your database // if the current_order is already paid in your database, return strict "paid"; // if not, return something else $order['WEBMONEY_orderStatus'] = $order->order_status; // from your database return $order; } return false; } /** * When the payment of the order is received from WebMoney Merchant, you can process the paid order. * !Important: don't forget to set the order status as "paid" in your database. * * @param Request $request * @param $order * @return bool */ public static function paidOrderFilter(Request $request, $order) { // Your code should be here: YourOrderController::saveOrderAsPaid($order); // Return TRUE if the order is saved as "paid" in the database or FALSE if some error occurs. // If you return FALSE, then you can repeat the failed paid requests on the WebMoney Merchant website manually. return true; } /** * Process the request from the WebMoney Merchant route. * searchOrderFilter is called to search the order. * If the order is paid for the first time, paidOrderFilter is called to set the order status. * If searchOrderFilter returns the "paid" order status, then paidOrderFilter will not be called. * * @param Request $request * @return mixed */ public function payOrderFromGate(Request $request) { return WebMoneyMerchant::payOrderFromGate($request); } /** * Returns the service status for WebMoney Merchant request */ public function payOrderFromGateOK() { return "YES"; } }
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
测试
$ composer test
贡献
有关详细信息,请参阅 CONTRIBUTING
安全
如果您发现任何安全问题,请通过发送电子邮件至 actionmanager@gmail.com 来告诉我,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。