Completed
Push — master ( 5e8a98...722d19 )
by Songda
30s queued 25s
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\Collection;
11
use Yansongda\Supports\Config;
12
13
class PrepayPlugin extends GeneralPlugin
14
{
15
    protected function getUri(Rocket $rocket): string
16
    {
17
        return 'v3/pay/transactions/jsapi';
18
    }
19
20
    protected function getPartnerUri(Rocket $rocket): string
21
    {
22
        return 'v3/pay/partner/transactions/jsapi';
23
    }
24
25
    /**
26
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
27
     * @throws \Yansongda\Pay\Exception\ContainerException
28
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
29
     */
30
    protected function doSomething(Rocket $rocket): void
31
    {
32
        $config = get_wechat_config($rocket->getParams());
33
        $payload = $rocket->getPayload();
34
35
        $wechatId = $this->getWechatId($config, $payload);
0 ignored issues
show
Bug introduced by
It seems like $payload can also be of type null; however, parameter $payload of Yansongda\Pay\Plugin\Wec...ayPlugin::getWechatId() does only seem to accept Yansongda\Supports\Collection, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $wechatId = $this->getWechatId($config, /** @scrutinizer ignore-type */ $payload);
Loading history...
36
37
        if (!$payload->has('notify_url')) {
38
            $wechatId['notify_url'] = $config->get('notify_url');
39
        }
40
41
        $rocket->mergePayload($wechatId);
42
    }
43
44
    protected function getWechatId(Config $config, Collection $payload): array
45
    {
46
        if (Pay::MODE_SERVICE == $config->get('mode')) {
47
            return [
48
                'sp_appid' => $config->get('mp_app_id', ''),
49
                'sp_mchid' => $config->get('mch_id', ''),
50
                'sub_appid' => $payload->get('sub_appid', $config->get('sub_mp_app_id')),
51
                'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id')),
52
            ];
53
        }
54
55
        return [
56
            'appid' => $config->get('mp_app_id', ''),
57
            'mchid' => $config->get('mch_id', ''),
58
        ];
59
    }
60
}
61