CreatePlugin   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 18 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\V3\Marketing\Transfer\ReceiptDetail;
6
7
use Closure;
8
use JetBrains\PhpStorm\Deprecated;
9
use Yansongda\Artful\Contract\PluginInterface;
10
use Yansongda\Artful\Exception\ContainerException;
11
use Yansongda\Artful\Exception\InvalidParamsException;
12
use Yansongda\Artful\Exception\ServiceNotFoundException;
13
use Yansongda\Artful\Logger;
14
use Yansongda\Artful\Rocket;
15
use Yansongda\Pay\Exception\Exception;
16
use Yansongda\Pay\Pay;
17
18
use function Yansongda\Pay\get_provider_config;
19
20
/**
21
 * @see https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/electronic-receipt-api/create-electronic-receipt.html
22
 */
23
#[Deprecated(reason: '由于微信支付变更,自 v3.7.12 开始废弃, 并将在 v3.8.0 移除')]
24
class CreatePlugin implements PluginInterface
25
{
26
    /**
27
     * @throws InvalidParamsException
28
     * @throws ContainerException
29
     * @throws ServiceNotFoundException
30
     */
31
    public function assembly(Rocket $rocket, Closure $next): Rocket
32
    {
33
        Logger::debug('[Wechat][Marketing][Transfer][ReceiptDetail][CreatePlugin] 插件开始装载', ['rocket' => $rocket]);
34
35
        $config = get_provider_config('wechat', $rocket->getParams());
36
37
        if (Pay::MODE_SERVICE === ($config['mode'] ?? Pay::MODE_NORMAL)) {
38
            throw new InvalidParamsException(Exception::PARAMS_PLUGIN_ONLY_SUPPORT_NORMAL_MODE, '参数异常: 受理转账明细电子回单,只支持普通商户模式,当前配置为服务商模式');
39
        }
40
41
        $rocket->mergePayload([
42
            '_method' => 'POST',
43
            '_url' => 'v3/transfer-detail/electronic-receipts',
44
        ]);
45
46
        Logger::info('[Wechat][Marketing][Transfer][ReceiptDetail][CreatePlugin] 插件装载完毕', ['rocket' => $rocket]);
47
48
        return $next($rocket);
49
    }
50
}
51