MiniPayPlugin   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 24 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\V3\Pay\Combine;
6
7
use Closure;
8
use Yansongda\Artful\Contract\PluginInterface;
9
use Yansongda\Artful\Exception\ContainerException;
10
use Yansongda\Artful\Exception\InvalidParamsException;
11
use Yansongda\Artful\Exception\ServiceNotFoundException;
12
use Yansongda\Artful\Logger;
13
use Yansongda\Artful\Rocket;
14
use Yansongda\Pay\Exception\Exception;
15
16
use function Yansongda\Pay\get_provider_config;
17
18
/**
19
 * @see https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/orders/mini-program-prepay.html
20
 * @see https://pay.weixin.qq.com/docs/partner/apis/combine-payment/orders/mini-program-prepay.html
21
 */
22
class MiniPayPlugin implements PluginInterface
23
{
24
    /**
25
     * @throws ContainerException
26
     * @throws InvalidParamsException
27
     * @throws ServiceNotFoundException
28
     */
29
    public function assembly(Rocket $rocket, Closure $next): Rocket
30
    {
31
        Logger::debug('[Wechat][Pay][Combine][MiniPayPlugin] 插件开始装载', ['rocket' => $rocket]);
32
33
        $params = $rocket->getParams();
34
        $config = get_provider_config('wechat', $params);
35
        $payload = $rocket->getPayload();
36
37
        if (is_null($payload)) {
38
            throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: Mini合单 下单,参数为空');
39
        }
40
41
        $rocket->mergePayload([
42
            '_method' => 'POST',
43
            '_url' => 'v3/combine-transactions/jsapi',
44
            '_service_url' => 'v3/combine-transactions/jsapi',
45
            'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''),
46
            'combine_appid' => $payload->get('combine_appid', $config['mini_app_id'] ?? ''),
47
            'combine_mchid' => $payload->get('combine_mchid', $config['mch_id'] ?? ''),
48
        ]);
49
50
        Logger::info('[Wechat][Pay][Combine][MiniPayPlugin] 插件装载完毕', ['rocket' => $rocket]);
51
52
        return $next($rocket);
53
    }
54
}
55