Passed
Pull Request — master (#1002)
by
unknown
02:06
created

PrepayPlugin::assembly()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 23
rs 9.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Epay\Pay\Scan;
6
7
use Closure;
8
use Yansongda\Artful\Contract\PluginInterface;
9
use Yansongda\Artful\Exception\InvalidConfigException;
10
use Yansongda\Artful\Logger;
11
use Yansongda\Artful\Rocket;
12
use Yansongda\Pay\Exception\Exception;
13
14
use function Yansongda\Pay\get_provider_config;
15
16
class PrepayPlugin implements PluginInterface
17
{
18
    public function assembly(Rocket $rocket, Closure $next): Rocket
19
    {
20
        Logger::debug('[Epay][Pay][Scan][PrepayPlugin] 插件开始装载', ['rocket' => $rocket]);
21
22
        $backUrl = $rocket->getPayload()['notify_url'] ?? null;
23
        if (empty($backUrl)) {
24
            $params = $rocket->getParams();
25
            $config = get_provider_config('epay', $params);
26
27
            $backUrl = $config['notify_url'] ?? null;
28
        }
29
30
        if (!$backUrl) {
31
            throw new InvalidConfigException(Exception::CONFIG_EPAY_INVALID, 'Missing Epay Config -- [notify_url]');
32
        }
33
        $rocket->mergePayload([
34
            'service' => 'atPay',
35
            'backUrl' => $backUrl,
36
        ]);
37
38
        Logger::info('[Epay][Pay][Scan][PrepayPlugin] 插件装载完毕', ['rocket' => $rocket]);
39
40
        return $next($rocket);
41
    }
42
}
43