Passed
Pull Request — master (#772)
by Songda
01:56
created

InvokePrepayV2Plugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigKey() 0 3 1
A getInvokeConfig() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Pay\App;
6
7
use Exception;
8
use Yansongda\Pay\Exception\ContainerException;
9
use Yansongda\Pay\Exception\ServiceNotFoundException;
10
use Yansongda\Pay\Rocket;
11
use Yansongda\Supports\Config;
12
use Yansongda\Supports\Str;
13
14
use function Yansongda\Pay\get_wechat_config;
15
use function Yansongda\Pay\get_wechat_sign_v2;
16
17
/**
18
 * @see https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5
19
 */
20
class InvokePrepayV2Plugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokePrepayPlugin
21
{
22
    /**
23
     * @throws ContainerException
24
     * @throws ServiceNotFoundException
25
     * @throws Exception
26
     */
27
    protected function getInvokeConfig(Rocket $rocket, string $prepayId): Config
28
    {
29
        $params = $rocket->getParams();
30
31
        $config = new Config([
32
            'appId' => $this->getAppId($rocket),
33
            'partnerId' => get_wechat_config($params)['mch_id'] ?? null,
34
            'prepayId' => $prepayId,
35
            'package' => 'Sign=WXPay',
36
            'nonceStr' => Str::random(32),
37
            'timeStamp' => time().'',
38
        ]);
39
40
        $config->set('sign', get_wechat_sign_v2($params, $config->all()));
41
42
        return $config;
43
    }
44
45
    protected function getConfigKey(): string
46
    {
47
        return 'app_id';
48
    }
49
}
50