Passed
Push — master ( 09a431...e6f462 )
by Songda
02:33
created

PrepayPlugin::getWechatId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 18
rs 9.9
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Pay\H5;
6
7
use Yansongda\Pay\Pay;
8
use Yansongda\Pay\Rocket;
9
use Yansongda\Supports\Config;
10
11
class PrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\PrepayPlugin
12
{
13
    protected function getUri(Rocket $rocket): string
14
    {
15
        return 'v3/pay/transactions/h5';
16
    }
17
18
    protected function getPartnerUri(Rocket $rocket): string
19
    {
20
        return 'v3/pay/partner/transactions/h5';
21
    }
22
23
    protected function getWechatId(Config $config, Rocket $rocket): array
24
    {
25
        $payload = $rocket->getPayload();
26
27
        $key = ($rocket->getParams()['_type'] ?? 'mp').'_app_id';
28
29
        if (Pay::MODE_SERVICE == $config->get('mode')) {
30
            return [
31
                'sp_appid' => $config->get($key, ''),
32
                'sp_mchid' => $config->get('mch_id', ''),
33
                'sub_appid' => $payload->get('sub_appid', $config->get('sub_'.$key)),
34
                'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id')),
35
            ];
36
        }
37
38
        return [
39
            'appid' => $config->get($key, ''),
40
            'mchid' => $config->get('mch_id', ''),
41
        ];
42
    }
43
}
44