Skip to content

Commit

Permalink
feat: 新增微信分账申请分账账单插件
Browse files Browse the repository at this point in the history
  • Loading branch information
yansongda committed Nov 23, 2024
1 parent dd084bf commit 5e0cb02
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v3.7.11

### added

- feat: 新增微信分账申请分账账单插件 (#1041)

## v3.7.10

### fixed
Expand Down
47 changes: 47 additions & 0 deletions src/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing;

use Closure;
use Yansongda\Artful\Contract\PluginInterface;
use Yansongda\Artful\Exception\InvalidParamsException;
use Yansongda\Artful\Logger;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Exception\Exception;

use function Yansongda\Artful\filter_params;

/**
* @see https://pay.weixin.qq.com/docs/partner/apis/profit-sharing/bill-shipment/split-bill.html
* @see https://pay.weixin.qq.com/docs/partner/apis/profit-sharing/bill-shipment/split-bill.html
*/
class GetBillPlugin implements PluginInterface
{
/**
* @throws InvalidParamsException
*/
public function assembly(Rocket $rocket, Closure $next): Rocket
{
Logger::debug('[Wechat][V3][Extend][ProfitSharing][GetBillPlugin] 插件开始装载', ['rocket' => $rocket]);

$payload = $rocket->getPayload();

if (is_null($payload)) {
throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 分账 申请账单,参数为空');
}

$query = filter_params($payload)->query();

$rocket->setPayload([
'_method' => 'GET',
'_url' => 'v3/profitsharing/bills?'.$query,
'_service_url' => 'v3/profitsharing/bills?'.$query,
]);

Logger::info('[Wechat][V3][Extend][ProfitSharing][GetBillPlugin] 插件装载完毕', ['rocket' => $rocket]);

return $next($rocket);
}
}
50 changes: 50 additions & 0 deletions tests/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Plugin\Wechat\V3\Extend\ProfitSharing;

use Yansongda\Artful\Exception\InvalidParamsException;
use Yansongda\Artful\Rocket;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\GetBillPlugin;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;

class GetBillPluginTest extends TestCase
{
protected GetBillPlugin $plugin;

protected function setUp(): void
{
parent::setUp();

$this->plugin = new GetBillPlugin();
}

public function testEmptyPayload()
{
$rocket = new Rocket();

self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::PARAMS_NECESSARY_PARAMS_MISSING);
self::expectExceptionMessage('参数异常: 分账 申请账单,参数为空');

$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
}

public function testNormal()
{
$rocket = new Rocket();
$rocket->setPayload(new Collection( [
"download_url" => "111",
'_t' => 'a',
]));

$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });

self::assertEquals([
'_method' => 'GET',
'_url' => 'v3/profitsharing/bills?download_url=111',
'_service_url' => 'v3/profitsharing/bills?download_url=111',
], $result->getPayload()->all());
}
}
2 changes: 1 addition & 1 deletion web/docs/v3/wechat/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ $result = Pay::wechat()->papay([

- 申请分账账单

`暂无`
`\Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing\GetBillPlugin`

- 下载账单

Expand Down

0 comments on commit 5e0cb02

Please sign in to comment.