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

QueryReceiptDetailPlugin::normal()   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
dl 0
loc 3
rs 10
c 1
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\Marketing\Transfer;
6
7
use Closure;
8
use Yansongda\Pay\Contract\PluginInterface;
9
use Yansongda\Pay\Logger;
10
use Yansongda\Pay\Rocket;
11
use Yansongda\Supports\Collection;
12
13
/**
14
 * @see https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/electronic-receipt-api/query-electronic-receipt.html
15
 */
16
class QueryReceiptDetailPlugin implements PluginInterface
17
{
18
    public function assembly(Rocket $rocket, Closure $next): Rocket
19
    {
20
        Logger::debug('[Wechat][Marketing][Transfer][QueryReceiptDetailPlugin] 插件开始装载', ['rocket' => $rocket]);
21
22
        $rocket->setPayload(array_merge(
23
            [
24
                '_method' => 'GET',
25
                '_url' => 'v3/transfer-detail/electronic-receipts?'.$this->normal($rocket->getPayload()),
26
            ],
27
        ));
28
29
        Logger::info('[Wechat][Marketing][Transfer][QueryReceiptDetailPlugin] 插件装载完毕', ['rocket' => $rocket]);
30
31
        return $next($rocket);
32
    }
33
34
    protected function normal(?Collection $payload): string
35
    {
36
        return $payload?->query() ?? '';
37
    }
38
}
39