Passed
Pull Request — master (#909)
by Songda
02:14
created

QueryAmountsPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\Extend\ProfitSharing;
6
7
use Closure;
8
use Yansongda\Pay\Contract\PluginInterface;
9
use Yansongda\Pay\Exception\Exception;
10
use Yansongda\Pay\Exception\InvalidParamsException;
11
use Yansongda\Pay\Logger;
12
use Yansongda\Pay\Rocket;
13
14
/**
15
 * @see https://pay.weixin.qq.com/docs/merchant/apis/profit-sharing/transactions/query-order-amount.html
16
 * @see https://pay.weixin.qq.com/docs/partner/apis/profit-sharing/transactions/query-order-amount.html
17
 */
18
class QueryAmountsPlugin implements PluginInterface
19
{
20
    /**
21
     * @throws InvalidParamsException
22
     */
23
    public function assembly(Rocket $rocket, Closure $next): Rocket
24
    {
25
        Logger::debug('[Wechat][Extend][ProfitSharing][QueryAmountsPlugin] 插件开始装载', ['rocket' => $rocket]);
26
27
        $transactionId = $rocket->getPayload()?->get('transaction_id');
28
29
        if (is_null($transactionId)) {
30
            throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 缺少分账参数');
31
        }
32
33
        $rocket->setPayload(array_merge(
34
            [
35
                '_method' => 'GET',
36
                '_url' => 'v3/profitsharing/transactions/'.$transactionId.'/amounts',
37
                '_service_url' => 'v3/profitsharing/transactions/'.$transactionId.'/amounts',
38
            ],
39
        ));
40
41
        Logger::info('[Wechat][Extend][ProfitSharing][QueryAmountsPlugin] 插件装载完毕', ['rocket' => $rocket]);
42
43
        return $next($rocket);
44
    }
45
}
46