Passed
Pull Request — master (#513)
by
unknown
02:04
created

FindRefundPlugin::getMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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 FindRefundPlugin extends GeneralPlugin
13
{
14
    protected function getUri(Rocket $rocket): string
15
    {
16
        $payload = $rocket->getPayload();
17
        
18
        $config = get_wechat_config($rocket->getParams());
19
20
        $query = [
21
            'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id', '')),
22
        ];
23
24
        if (!is_null($payload->get('refund_id'))) {
25
            return 'v3/ecommerce/refunds/id/'.$payload->get('refund_id').'?'.http_build_query($query);
26
        } elseif (!is_null($payload->get('out_refund_no'))) {
27
            return 'v3/ecommerce/refunds/out-refund-no/'.$payload->get('out_refund_no').'?'.http_build_query($query);
28
        } else {
29
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
30
        }
31
    }
32
33
    protected function getMethod(): string
34
    {
35
        return 'GET';
36
    }
37
38
    protected function doSomething(Rocket $rocket): void
39
    {
40
        $rocket->setPayload(null);
41
    }
42
}
43