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

FindRefundPlugin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 34
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A doSomething() 0 3 1
A getUri() 0 3 1
A getPartnerUri() 0 16 3
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
        throw new InvalidParamsException(Exception::SERVICE_NOT_FOUND_ERROR);
17
    }
18
19
    protected function getPartnerUri(Rocket $rocket): string
20
    {
21
        $payload = $rocket->getPayload();
22
23
        $config = get_wechat_config($rocket->getParams());
24
25
        $query = [
26
            'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id', '')),
27
        ];
28
29
        if (!is_null($payload->get('refund_id'))) {
30
            return 'v3/ecommerce/refunds/id/'.$payload->get('refund_id').'?'.http_build_query($query);
31
        } elseif (!is_null($payload->get('out_refund_no'))) {
32
            return 'v3/ecommerce/refunds/out-refund-no/'.$payload->get('out_refund_no').'?'.http_build_query($query);
33
        } else {
34
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
35
        }
36
    }
37
38
    protected function getMethod(): string
39
    {
40
        return 'GET';
41
    }
42
43
    protected function doSomething(Rocket $rocket): void
44
    {
45
        $rocket->setPayload(null);
46
    }
47
}
48