Passed
Pull Request — master (#756)
by Songda
01:53
created

QueryRefundPlugin::getMethod()   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
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
10
use function Yansongda\Pay\get_wechat_config;
11
12
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
13
use Yansongda\Pay\Rocket;
14
15
class QueryRefundPlugin extends GeneralPlugin
16
{
17
    /**
18
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
19
     */
20
    protected function getUri(Rocket $rocket): string
21
    {
22
        $payload = $rocket->getPayload();
23
24
        if (is_null($payload->get('out_refund_no'))) {
25
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
26
        }
27
28
        return 'v3/refund/domestic/refunds/'.$payload->get('out_refund_no');
29
    }
30
31
    /**
32
     * @throws \Yansongda\Pay\Exception\ContainerException
33
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
34
     */
35
    protected function getPartnerUri(Rocket $rocket): string
36
    {
37
        $config = get_wechat_config($rocket->getParams());
38
        $url = parent::getPartnerUri($rocket);
39
40
        return $url.'?sub_mchid='.$rocket->getPayload()->get('sub_mchid', $config['sub_mch_id'] ?? '');
41
    }
42
43
    protected function getMethod(): string
44
    {
45
        return 'GET';
46
    }
47
48
    protected function doSomething(Rocket $rocket): void
49
    {
50
        $rocket->setPayload(null);
51
    }
52
}
53