CreateCardTemplatePlugin   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\V3\Marketing\Fapiao;
6
7
use Closure;
8
use Yansongda\Artful\Contract\PluginInterface;
9
use Yansongda\Artful\Exception\ContainerException;
10
use Yansongda\Artful\Exception\ServiceNotFoundException;
11
use Yansongda\Artful\Logger;
12
use Yansongda\Artful\Rocket;
13
14
use function Yansongda\Pay\get_provider_config;
15
16
/**
17
 * @see https://pay.weixin.qq.com/docs/merchant/products/fapiao/apilist.html
18
 */
19
class CreateCardTemplatePlugin implements PluginInterface
20
{
21
    /**
22
     * @throws ContainerException
23
     * @throws ServiceNotFoundException
24
     */
25
    public function assembly(Rocket $rocket, Closure $next): Rocket
26
    {
27
        Logger::debug('[Wechat][V3][Marketing][Fapiao][CreateCardTemplatePlugin] 插件开始装载', ['rocket' => $rocket]);
28
29
        $params = $rocket->getParams();
30
        $config = get_provider_config('wechat', $params);
31
        $payload = $rocket->getPayload();
32
33
        $rocket->mergePayload([
34
            '_method' => 'POST',
35
            '_url' => 'v3/new-tax-control-fapiao/card-template',
36
            'card_appid' => $payload?->get('card_appid') ?? $config['mp_app_id'],
37
        ]);
38
39
        Logger::info('[Wechat][V3][Marketing][Fapiao][CreateCardTemplatePlugin] 插件装载完毕', ['rocket' => $rocket]);
40
41
        return $next($rocket);
42
    }
43
}
44