Passed
Pull Request — master (#928)
by Songda
02:26
created

CreatePlugin::assembly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 0
loc 18
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\V3\Marketing\Coupon\Stock;
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
use function Yansongda\Pay\get_wechat_config;
14
15
/**
16
 * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/stock/create-coupon-stock.html
17
 * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/stock/create-coupon-stock.html
18
 */
19
class CreatePlugin 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][Coupon][Stock][CreatePlugin] 插件开始装载', ['rocket' => $rocket]);
28
29
        $params = $rocket->getParams();
30
        $config = get_wechat_config($params);
31
        $belongMerchant = $rocket->getPayload()?->get('belong_merchant') ?? $config['mch_id'];
32
33
        $rocket->mergePayload([
34
            '_method' => 'POST',
35
            '_url' => 'v3/marketing/favor/coupon-stocks',
36
            '_service_url' => 'v3/marketing/favor/coupon-stocks',
37
            'belong_merchant' => $belongMerchant,
38
        ]);
39
40
        Logger::info('[Wechat][V3][Marketing][Coupon][Stock][CreatePlugin] 插件装载完毕', ['rocket' => $rocket]);
41
42
        return $next($rocket);
43
    }
44
}
45