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

QueryReturnAdvancePlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 36
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUri() 0 3 1
A getPartnerUri() 0 11 2
A getMethod() 0 3 1
A doSomething() 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
10
use function Yansongda\Pay\get_wechat_config;
11
12
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
13
use Yansongda\Pay\Rocket;
14
15
/**
16
 * @see https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_5.shtml
17
 */
18
class QueryReturnAdvancePlugin extends GeneralPlugin
19
{
20
    /**
21
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
22
     */
23
    protected function getUri(Rocket $rocket): string
24
    {
25
        throw new InvalidParamsException(Exception::NOT_IN_SERVICE_MODE);
26
    }
27
28
    /**
29
     * @throws \Yansongda\Pay\Exception\ContainerException
30
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
31
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
32
     */
33
    protected function getPartnerUri(Rocket $rocket): string
34
    {
35
        $payload = $rocket->getPayload();
36
        $config = get_wechat_config($rocket->getParams());
37
        $subMchId = $payload->get('sub_mchid', $config['sub_mch_id'] ?? '');
38
39
        if (is_null($payload->get('refund_id'))) {
40
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
41
        }
42
43
        return 'v3/ecommerce/refunds/'.$payload->get('refund_id').'/return-advance?sub_mchid='.$subMchId;
44
    }
45
46
    protected function getMethod(): string
47
    {
48
        return 'GET';
49
    }
50
51
    protected function doSomething(Rocket $rocket): void
52
    {
53
        $rocket->setPayload(null);
54
    }
55
}
56