Passed
Pull Request — master (#619)
by Songda
08:04
created

FindRefundPlugin::getPartnerUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
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\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
        $params = $rocket->getParams();
35
        $config = get_wechat_config($params);
36
        $url = parent::getPartnerUri($rocket);
37
38
        return $url.'?sub_mchid='.($params['sub_mchid'] ?? $config->get('sub_mch_id'));
39
    }
40
41
    protected function getMethod(): string
42
    {
43
        return 'GET';
44
    }
45
46
    protected function doSomething(Rocket $rocket): void
47
    {
48
        $rocket->setPayload(null);
49
    }
50
}
51