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

ReturnAdvancePlugin::doSomething()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
use Yansongda\Supports\Collection;
12
13
class ReturnAdvancePlugin extends GeneralPlugin
14
{
15
    /**
16
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
17
     */
18
    protected function getUri(Rocket $rocket): string
19
    {
20
        throw new InvalidParamsException(Exception::NOT_IN_SERVICE_MODE);
21
    }
22
23
    /**
24
     * @throws \Yansongda\Pay\Exception\InvalidParamsException
25
     */
26
    protected function getPartnerUri(Rocket $rocket): string
27
    {
28
        $payload = $rocket->getPayload();
29
30
        if (is_null($payload->get('refund_id'))) {
31
            throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
32
        }
33
34
        return 'v3/ecommerce/refunds/'.$payload->get('refund_id').'/return-advance';
35
    }
36
37
    /**
38
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
39
     * @throws \Yansongda\Pay\Exception\ContainerException
40
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
41
     */
42
    protected function doSomething(Rocket $rocket): void
43
    {
44
        $config = get_wechat_config($rocket->getParams());
45
46
        $body = [
47
            'sub_mchid' => $rocket->getPayload()->get('sub_mchid', $config->get('sub_mch_id', '')),
48
        ];
49
50
        $rocket->setPayload(new Collection($body));
51
    }
52
}
53