Passed
Pull Request — master (#513)
by Songda
02:40 queued 37s
created

ReturnAdvancePlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
dl 0
loc 38
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUri() 0 3 1
A doSomething() 0 9 1
A getPartnerUri() 0 9 2
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