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

PrepayPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPartnerUri() 0 3 1
A getUri() 0 3 1
A getWechatId() 0 18 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