Passed
Pull Request — master (#619)
by Songda
15:02 queued 05:16
created

FindRefundPlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 10
c 2
b 1
f 0
dl 0
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUri() 0 9 2
A getMethod() 0 3 1
A doSomething() 0 3 1
A getPartnerUri() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
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 FindRefundPlugin extends GeneralPlugin
13
{
14
    /**
15
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
16
     */
17
    protected function getUri(Rocket $rocket): string
18
    {
19
        $payload = $rocket->getPayload();
20
21
        if (is_null($payload->get('out_refund_no'))) {
22
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
23
        }
24
25
        return 'v3/refund/domestic/refunds/'.$payload->get('out_refund_no');
26
    }
27
28
    /**
29
     * @throws \Yansongda\Pay\Exception\ContainerException
30
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
31
     */
32
    protected function getPartnerUri(Rocket $rocket): string
33
    {
34
        $config = get_wechat_config($rocket->getParams());
35
        $url = parent::getPartnerUri($rocket);
36
37
        return $url.'?sub_mchid='.($rocket->getPayload()->get('sub_mchid', $config->get('sub_mch_id')));
38
    }
39
40
    protected function getMethod(): string
41
    {
42
        return 'GET';
43
    }
44
45
    protected function doSomething(Rocket $rocket): void
46
    {
47
        $rocket->setPayload(null);
48
    }
49
}
50