Passed
Push — master ( b03ccb...9ada0f )
by Songda
02:05
created

InvokePrepayPlugin::getInvokeConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Pay\App;
6
7
use Yansongda\Pay\Rocket;
8
use Yansongda\Supports\Config;
9
use Yansongda\Supports\Str;
10
11
class InvokePrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokePrepayPlugin
12
{
13
    /**
14
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
15
     * @throws \Yansongda\Pay\Exception\ContainerException
16
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
17
     * @throws \Exception
18
     */
19
    protected function getInvokeConfig(Rocket $rocket, string $prepayId): Config
20
    {
21
        $config = new Config([
22
            'appid' => $this->getAppid($rocket),
23
            'partnerid' => get_wechat_config($rocket->getParams())->get('mch_id'),
24
            'prepayid' => $prepayId,
25
            'package' => 'Sign=WXPay',
26
            'noncestr' => Str::random(32),
27
            'timestamp' => time().'',
28
        ]);
29
30
        $config->set('sign', $this->getSign($config, $rocket->getParams()));
31
32
        return $config;
33
    }
34
35
    protected function getAppid(Rocket $rocket): string
36
    {
37
        $config = get_wechat_config($rocket->getParams());
38
39
        return $config->get('app_id', '');
40
    }
41
}
42