Passed
Push — master ( df334d...db8528 )
by Songda
03:29 queued 01:21
created

PayPlugin::assembly()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 20
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Jsb\Pay\Scan;
6
7
use Closure;
8
use Yansongda\Artful\Contract\PluginInterface;
9
use Yansongda\Artful\Exception\ContainerException;
10
use Yansongda\Artful\Exception\InvalidConfigException;
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://github.com/yansongda/pay/pull/1002
20
 */
21
class PayPlugin implements PluginInterface
22
{
23
    /**
24
     * @throws InvalidConfigException
25
     * @throws ServiceNotFoundException
26
     * @throws ContainerException
27
     */
28
    public function assembly(Rocket $rocket, Closure $next): Rocket
29
    {
30
        Logger::debug('[Jsb][Pay][Scan][PayPlugin] 插件开始装载', ['rocket' => $rocket]);
31
32
        $params = $rocket->getParams();
33
        $config = get_provider_config('jsb', $params);
34
        $backUrl = $rocket->getPayload()['notify_url'] ?? $config['notify_url'] ?? null;
35
36
        if (!$backUrl) {
37
            throw new InvalidConfigException(Exception::CONFIG_JSB_INVALID, '配置异常: 缺少配置参数 -- [notify_url]');
38
        }
39
40
        $rocket->mergePayload([
41
            'service' => 'atPay',
42
            'backUrl' => $backUrl,
43
        ]);
44
45
        Logger::info('[Jsb][Pay][Scan][PayPlugin] 插件装载完毕', ['rocket' => $rocket]);
46
47
        return $next($rocket);
48
    }
49
}
50