Passed
Pull Request — master (#479)
by Songda
02:04
created

PrepayPlugin::getPartnerUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
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\Common;
6
7
use Yansongda\Pay\Pay;
8
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
9
use Yansongda\Pay\Rocket;
10
use Yansongda\Supports\Config;
11
12
class PrepayPlugin extends GeneralPlugin
13
{
14
    protected function getUri(Rocket $rocket): string
15
    {
16
        return 'v3/pay/transactions/jsapi';
17
    }
18
19
    protected function getPartnerUri(Rocket $rocket): string
20
    {
21
        return 'v3/pay/partner/transactions/jsapi';
22
    }
23
24
    /**
25
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
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
33
        $payload = $this->getWechatId($config, $rocket);
34
35
        if (!$rocket->getPayload()->has('notify_url')) {
36
            $payload['notify_url'] = $config->get('notify_url');
37
        }
38
39
        $rocket->mergePayload($payload);
40
    }
41
42
    protected function getWechatId(Config $config, Rocket $rocket): array
43
    {
44
        if (Pay::MODE_SERVICE == $config->get('mode')) {
45
            return [
46
                'sp_appid' => $config->get('mp_app_id', ''),
47
                'sp_mchid' => $config->get('mch_id', ''),
48
                'sub_appid' => $rocket->getParams()['sub_appid'] ?? $config->get('sub_mp_app_id'),
49
                'sub_mchid' => $rocket->getParams()['sub_mchid'] ?? $config->get('sub_mch_id'),
50
            ];
51
        }
52
53
        return [
54
            'appid' => $config->get('mp_app_id', ''),
55
            'mchid' => $config->get('mch_id', ''),
56
        ];
57
    }
58
}
59