Passed
Push — master ( a1269b...b6838d )
by Songda
02:22
created

ApplyPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUri() 0 3 1
A getPartnerUri() 0 3 1
A doSomething() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Ecommerce\Refund;
6
7
use Yansongda\Pay\Exception\Exception;
8
use Yansongda\Pay\Exception\InvalidParamsException;
9
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
10
use Yansongda\Pay\Rocket;
11
12
class ApplyPlugin extends GeneralPlugin
13
{
14
    /**
15
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
16
     */
17
    protected function getUri(Rocket $rocket): string
18
    {
19
        throw new InvalidParamsException(Exception::NOT_IN_SERVICE_MODE);
20
    }
21
22
    protected function getPartnerUri(Rocket $rocket): string
23
    {
24
        return 'v3/ecommerce/refunds/apply';
25
    }
26
27
    /**
28
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
29
     * @throws \Yansongda\Pay\Exception\ContainerException
30
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
31
     */
32
    protected function doSomething(Rocket $rocket): void
33
    {
34
        $config = get_wechat_config($rocket->getParams());
35
        $payload = $rocket->getPayload();
36
37
        $wechatId = [
38
            'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id', '')),
39
            'sp_appid' => $config->get('mp_app_id', ''),
40
        ];
41
42
        if (!$payload->has('notify_url')) {
43
            $wechatId['notify_url'] = $config->get('notify_url');
44
        }
45
46
        $rocket->mergePayload($wechatId);
47
    }
48
}
49