Passed
Push — master ( dd084b...0c8bcb )
by Songda
03:08 queued 49s
created

GetBillPlugin::assembly()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 21
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing;
6
7
use Closure;
8
use Yansongda\Artful\Contract\PluginInterface;
9
use Yansongda\Artful\Exception\InvalidParamsException;
10
use Yansongda\Artful\Logger;
11
use Yansongda\Artful\Rocket;
12
use Yansongda\Pay\Exception\Exception;
13
14
use function Yansongda\Artful\filter_params;
15
16
/**
17
 * @see https://pay.weixin.qq.com/docs/partner/apis/profit-sharing/bill-shipment/split-bill.html
18
 * @see https://pay.weixin.qq.com/docs/partner/apis/profit-sharing/bill-shipment/split-bill.html
19
 */
20
class GetBillPlugin implements PluginInterface
21
{
22
    /**
23
     * @throws InvalidParamsException
24
     */
25
    public function assembly(Rocket $rocket, Closure $next): Rocket
26
    {
27
        Logger::debug('[Wechat][V3][Extend][ProfitSharing][GetBillPlugin] 插件开始装载', ['rocket' => $rocket]);
28
29
        $payload = $rocket->getPayload();
30
31
        if (is_null($payload)) {
32
            throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 分账 申请账单,参数为空');
33
        }
34
35
        $query = filter_params($payload)->query();
36
37
        $rocket->setPayload([
38
            '_method' => 'GET',
39
            '_url' => 'v3/profitsharing/bills?'.$query,
40
            '_service_url' => 'v3/profitsharing/bills?'.$query,
41
        ]);
42
43
        Logger::info('[Wechat][V3][Extend][ProfitSharing][GetBillPlugin] 插件装载完毕', ['rocket' => $rocket]);
44
45
        return $next($rocket);
46
    }
47
}
48