Passed
Push — master ( d1dcd3...a849c7 )
by Songda
01:59
created

QueryCallbackPlugin   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

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\Marketing\Coupon;
6
7
use Closure;
8
use Yansongda\Pay\Contract\PluginInterface;
9
use Yansongda\Pay\Exception\ContainerException;
10
use Yansongda\Pay\Exception\ServiceNotFoundException;
11
use Yansongda\Pay\Logger;
12
use Yansongda\Pay\Rocket;
13
14
use function Yansongda\Pay\get_wechat_config;
15
16
/**
17
 * @see https://pay.weixin.qq.com/docs/merchant/apis/cash-coupons/call-back-url/query-callback.html
18
 * @see https://pay.weixin.qq.com/docs/partner/apis/cash-coupons/call-back-url/query-callback.html
19
 */
20
class QueryCallbackPlugin implements PluginInterface
21
{
22
    /**
23
     * @throws ContainerException
24
     * @throws ServiceNotFoundException
25
     */
26
    public function assembly(Rocket $rocket, Closure $next): Rocket
27
    {
28
        Logger::debug('[Wechat][Marketing][Coupon][QueryCallbackPlugin] 插件开始装载', ['rocket' => $rocket]);
29
30
        $params = $rocket->getParams();
31
        $config = get_wechat_config($params);
32
        $mchId = $rocket->getPayload()?->get('mchid') ?? $config['mch_id'] ?? 'null';
33
34
        $rocket->setPayload([
35
            '_method' => 'GET',
36
            '_url' => 'v3/marketing/favor/callbacks?mchid='.$mchId,
37
            '_service_url' => 'v3/marketing/favor/callbacks?mchid='.$mchId,
38
        ]);
39
40
        Logger::info('[Wechat][Marketing][Coupon][QueryCallbackPlugin] 插件装载完毕', ['rocket' => $rocket]);
41
42
        return $next($rocket);
43
    }
44
}
45