Passed
Pull Request — master (#513)
by Songda
02:06
created

FindPlugin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A doSomething() 0 3 1
A getUri() 0 3 1
A getPartnerUri() 0 15 3
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 FindPlugin 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
    /**
23
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
24
     * @throws \Yansongda\Pay\Exception\ContainerException
25
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
26
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
27
     */
28
    protected function getPartnerUri(Rocket $rocket): string
29
    {
30
        $payload = $rocket->getPayload();
31
        $config = get_wechat_config($rocket->getParams());
32
        $subMchId = $payload->get('sub_mchid', $config->get('sub_mch_id', ''));
33
34
        if (!is_null($payload->get('refund_id'))) {
35
            return 'v3/ecommerce/refunds/id/'.$payload->get('refund_id').'?sub_mchid='. $subMchId;
36
        }
37
38
        if (!is_null($payload->get('out_refund_no'))) {
39
            return 'v3/ecommerce/refunds/out-refund-no/'.$payload->get('out_refund_no').'?sub_mchid='. $subMchId;
40
        }
41
42
        throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
43
    }
44
45
    protected function getMethod(): string
46
    {
47
        return 'GET';
48
    }
49
50
    protected function doSomething(Rocket $rocket): void
51
    {
52
        $rocket->setPayload(null);
53
    }
54
}
55