farzin-dev / laravel-webmoney-merchant
Laravel 的 WebMoney 商户支付
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ^7.2
- laravel/framework: ^8.12
Requires (Dev)
- orchestra/testbench: ^6.7
- phpunit/phpunit: ^9.3.3
This package is auto-updated.
Last update: 2024-09-29 05:43:03 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
-
复制
Secret Key X20
和Secret Key
参数并将它们粘贴到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
发送到http://yourproject.com/webmoney/result
以检查您的网站是否可用。 - 请求从
merchant.webmoney.ru
发送到http://yourproject.com/webmoney/result
(带有参数)。 - 函数
ExampleController@payOrderFromGate
运行验证过程(自动验证请求参数)。 - 将调用静态函数
searchOrderFilter
(见config/webmoney-merchant.php
中的searchOrderFilter
)以通过唯一 id 搜索订单。 - 如果您的数据库中当前订单状态不是
paid
,则将调用静态函数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)。有关更多信息,请参阅许可证文件。