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

FindRefundPlugin::getPartnerUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 3
c 1
b 1
f 0
dl 0
loc 6
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
        $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