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

PayPlugin::getUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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