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

FindReturnAdvancePlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A getPartnerUri() 0 15 2
A doSomething() 0 3 1
A getUri() 0 3 1
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 FindReturnAdvancePlugin 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
        if (is_null($payload->get('refund_id'))) {
24
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
25
        }
26
27
        $config = get_wechat_config($rocket->getParams());
28
29
        $query = [
30
            'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id', '')),
31
        ];
32
33
        return 'v3/ecommerce/refunds/'.$payload->get('refund_id').'/return-advance?'.http_build_query($query);
34
    }
35
36
    protected function getMethod(): string
37
    {
38
        return 'GET';
39
    }
40
41
    protected function doSomething(Rocket $rocket): void
42
    {
43
        $rocket->setPayload(null);
44
    }
45
}
46