Passed
Push — master ( 4857dc...3e097b )
by Songda
03:57 queued 01:53
created

RefundPlugin::assembly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 2
dl 0
loc 27
rs 9.6
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Unipay\Open\Pay\QrCode;
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\Packer\QueryPacker;
13
use Yansongda\Pay\Rocket;
14
15
use function Yansongda\Pay\get_unipay_config;
16
17
/**
18
 * @see https://open.unionpay.com/tjweb/acproduct/APIList?acpAPIId=799&apiservId=468&version=V2.2&bussType=0
19
 */
20
class RefundPlugin implements PluginInterface
21
{
22
    /**
23
     * @throws ContainerException
24
     * @throws ServiceNotFoundException
25
     */
26
    public function assembly(Rocket $rocket, Closure $next): Rocket
27
    {
28
        Logger::debug('[Unipay][QrCode][RefundPlugin] 插件开始装载', ['rocket' => $rocket]);
29
30
        $params = $rocket->getParams();
31
        $config = get_unipay_config($params);
32
        $payload = $rocket->getPayload();
33
34
        $rocket->setPacker(QueryPacker::class)
35
            ->mergePayload([
36
                '_url' => 'gateway/api/backTransReq.do',
37
                'encoding' => 'utf-8',
38
                'signature' => '',
39
                'bizType' => $payload?->get('bizType') ?? '000000',
40
                'accessType' => $payload?->get('accessType') ?? '0',
41
                'merId' => $config['mch_id'] ?? '',
42
                'channelType' => $payload?->get('channelType') ?? '08',
43
                'signMethod' => '01',
44
                'txnType' => $payload?->get('txnType') ?? '04',
45
                'txnSubType' => $payload?->get('txnSubType') ?? '00',
46
                'backUrl' => $payload?->get('backUrl') ?? $config['notify_url'] ?? '',
47
                'version' => '5.1.0',
48
            ]);
49
50
        Logger::info('[Unipay][QrCode][RefundPlugin] 插件装载完毕', ['rocket' => $rocket]);
51
52
        return $next($rocket);
53
    }
54
}
55