-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## v3.7.11 | ||
|
||
### added | ||
|
||
- feat: 新增微信分账申请分账账单插件 (#1041) | ||
|
||
## v3.7.10 | ||
|
||
### fixed | ||
|
47 changes: 47 additions & 0 deletions
47
src/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
tests/Plugin/Wechat/V3/Extend/ProfitSharing/GetBillPluginTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters