Passed
Pull Request — master (#513)
by Songda
02:06
created

FindReturnAdvancePlugin::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 FindReturnAdvancePlugin extends GeneralPlugin
13
{
14
    /**
15
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
16
     */
17
    protected function getUri(Rocket $rocket): string
18
    {
19
        throw new InvalidParamsException(Exception::NOT_IN_SERVICE_MODE);
20
    }
21
22
    /**
23
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
24
     * @throws \Yansongda\Pay\Exception\ContainerException
25
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
26
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
27
     */
28
    protected function getPartnerUri(Rocket $rocket): string
29
    {
30
        $payload = $rocket->getPayload();
31
        $config = get_wechat_config($rocket->getParams());
32
        $subMchId = $payload->get('sub_mchid', $config->get('sub_mch_id', ''));
33
34
        if (is_null($payload->get('refund_id'))) {
35
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
36
        }
37
38
        return 'v3/ecommerce/refunds/'.$payload->get('refund_id').'/return-advance?sub_mchid='. $subMchId;
39
    }
40
41
    protected function getMethod(): string
42
    {
43
        return 'GET';
44
    }
45
46
    protected function doSomething(Rocket $rocket): void
47
    {
48
        $rocket->setPayload(null);
49
    }
50
}
51