Passed
Pull Request — master (#753)
by Songda
01:51
created

PayPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 5 1
A doSomething() 0 10 1
A getUri() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Pay\Pos;
6
7
use function Yansongda\Pay\get_wechat_config;
8
9
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
10
use Yansongda\Pay\Rocket;
11
12
/**
13
 * @see https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1
14
 */
15
class PayPlugin extends GeneralPlugin
16
{
17
    protected function getHeaders(): array
18
    {
19
        return [
20
            'Content-Type' => 'application/xml',
21
            'User-Agent' => 'yansongda/pay-v3',
22
        ];
23
    }
24
25
    /**
26
     * @throws \Yansongda\Pay\Exception\ContainerException
27
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
28
     */
29
    protected function doSomething(Rocket $rocket): void
30
    {
31
        $config = get_wechat_config($rocket->getParams());
32
        $configKey = $this->getConfigKey($rocket->getParams());
33
34
        $rocket->mergeParams(['_version' => 'v2']);
35
36
        $rocket->mergePayload([
37
            'appid' => $config[$configKey] ?? '',
38
            'mch_id' => $config['mch_id'] ?? '',
39
        ]);
40
    }
41
42
    protected function getUri(Rocket $rocket): string
43
    {
44
        return 'pay/micropay';
45
    }
46
}
47