Merge pull request #480 from yansongda/issue-430

feat: 支持微信服务商分账功能
This commit is contained in:
yansongda 2021-08-28 22:26:30 +08:00 committed by GitHub
commit deadb526f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 656 additions and 8 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
@ -18,9 +19,16 @@ class AddReceiverPlugin extends GeneralPlugin
{
$config = get_wechat_config($rocket->getParams());
$rocket->mergePayload([
$wechatId = [
'appid' => $config->get('mp_app_id'),
]);
];
if (Pay::MODE_SERVICE == $config->get('mode')) {
$wechatId['sub_mchid'] = $rocket->getPayload()
->get('sub_mchid', $config->get('sub_mch_id', ''));
}
$rocket->mergePayload($wechatId);
}
protected function getUri(Rocket $rocket): string

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
@ -18,9 +19,16 @@ class CreatePlugin extends GeneralPlugin
{
$config = get_wechat_config($rocket->getParams());
$rocket->mergePayload([
$wechatId = [
'appid' => $config->get('mp_app_id'),
]);
];
if (Pay::MODE_SERVICE == $config->get('mode')) {
$wechatId['sub_mchid'] = $rocket->getPayload()
->get('sub_mchid', $config->get('sub_mch_id', ''));
}
$rocket->mergePayload($wechatId);
}
protected function getUri(Rocket $rocket): string

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
@ -18,9 +19,16 @@ class DeleteReceiverPlugin extends GeneralPlugin
{
$config = get_wechat_config($rocket->getParams());
$rocket->mergePayload([
$wechatId = [
'appid' => $config->get('mp_app_id'),
]);
];
if (Pay::MODE_SERVICE == $config->get('mode')) {
$wechatId['sub_mchid'] = $rocket->getPayload()
->get('sub_mchid', $config->get('sub_mch_id', ''));
}
$rocket->mergePayload($wechatId);
}
protected function getUri(Rocket $rocket): string

View File

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
class QueryMerchantConfigsPlugin extends GeneralPlugin
{
protected function getMethod(): string
{
return 'GET';
}
protected function doSomething(Rocket $rocket): void
{
$rocket->setPayload(null);
}
/**
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
* @throws \Yansongda\Pay\Exception\ContainerException
* @throws \Yansongda\Pay\Exception\InvalidParamsException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function getUri(Rocket $rocket): string
{
$config = get_wechat_config($rocket->getParams());
$payload = $rocket->getPayload();
if (Pay::MODE_SERVICE !== $config->get('mode', Pay::MODE_NORMAL)) {
throw new InvalidParamsException(Exception::METHOD_NOT_SUPPORTED);
}
return 'v3/profitsharing/merchant-configs/'.
$payload->get('sub_mchid', $config->get('sub_mch_id', ''));
}
}

View File

@ -6,6 +6,7 @@ namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
@ -22,19 +23,29 @@ class QueryPlugin extends GeneralPlugin
}
/**
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
* @throws \Yansongda\Pay\Exception\ContainerException
* @throws \Yansongda\Pay\Exception\InvalidParamsException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function getUri(Rocket $rocket): string
{
$payload = $rocket->getPayload();
$config = get_wechat_config($rocket->getParams());
if (is_null($payload->get('out_order_no')) ||
is_null($payload->get('transaction_id'))) {
throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
}
return '/v3/profitsharing/orders/'.
$url = 'v3/profitsharing/orders/'.
$payload->get('out_order_no').
'?transaction_id='.$payload->get('transaction_id');
if (Pay::MODE_SERVICE == $config->get('mode')) {
$url .= '&sub_mchid='.$payload->get('sub_mchid', $config->get('sub_mch_id', ''));
}
return $url;
}
}

View File

@ -6,6 +6,7 @@ namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
@ -22,19 +23,29 @@ class QueryReturnPlugin extends GeneralPlugin
}
/**
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
* @throws \Yansongda\Pay\Exception\ContainerException
* @throws \Yansongda\Pay\Exception\InvalidParamsException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function getUri(Rocket $rocket): string
{
$payload = $rocket->getPayload();
$config = get_wechat_config($rocket->getParams());
if (is_null($payload->get('out_return_no')) ||
is_null($payload->get('out_order_no'))) {
throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
}
return 'v3/profitsharing/return-orders/'.
$url = 'v3/profitsharing/return-orders/'.
$payload->get('out_return_no').
'?out_order_no='.$payload->get('out_order_no');
if (Pay::MODE_SERVICE == $config->get('mode')) {
$url .= '&sub_mchid='.$payload->get('sub_mchid', $config->get('sub_mch_id', ''));
}
return $url;
}
}

View File

@ -4,13 +4,27 @@ declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
class ReturnPlugin extends GeneralPlugin
{
/**
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
* @throws \Yansongda\Pay\Exception\ContainerException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function doSomething(Rocket $rocket): void
{
$config = get_wechat_config($rocket->getParams());
if (Pay::MODE_SERVICE == $config->get('mode')) {
$rocket->mergePayload([
'sub_mchid' => $rocket->getPayload()
->get('sub_mchid', $config->get('sub_mch_id', '')),
]);
}
}
protected function getUri(Rocket $rocket): string

View File

@ -4,13 +4,27 @@ declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
use Yansongda\Pay\Rocket;
class UnfreezePlugin extends GeneralPlugin
{
/**
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
* @throws \Yansongda\Pay\Exception\ContainerException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function doSomething(Rocket $rocket): void
{
$payload = $rocket->getPayload();
$config = get_wechat_config($rocket->getParams());
if (Pay::MODE_SERVICE == $config->get('mode') && !$payload->has('sub_mchid')) {
$rocket->mergePayload([
'sub_mchid' => $config->get('sub_mch_id', ''),
]);
}
}
protected function getUri(Rocket $rocket): string

View File

@ -0,0 +1,63 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\AddReceiverPlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class AddReceiverPluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection());
$plugin = new AddReceiverPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/receivers/add'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertArrayNotHasKey('sub_mchid', $payload->all());
}
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
$plugin = new AddReceiverPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/receivers/add'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertEquals('1600314070', $payload->get('sub_mchid'));
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
$plugin = new AddReceiverPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload();
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertEquals('123', $payload->get('sub_mchid'));
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\CreatePlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class CreatePluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection());
$plugin = new CreatePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/orders'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertArrayNotHasKey('sub_mchid', $payload->all());
}
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
$plugin = new CreatePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertEquals('1600314070', $payload->get('sub_mchid'));
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
$plugin = new CreatePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload();
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertEquals('123', $payload->get('sub_mchid'));
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\DeleteReceiverPlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class DeleteReceiverPluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection());
$plugin = new DeleteReceiverPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/receivers/delete'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertArrayNotHasKey('sub_mchid', $payload->all());
}
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
$plugin = new DeleteReceiverPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/receivers/delete'), $radar->getUri());
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertEquals('1600314070', $payload->get('sub_mchid'));
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
$plugin = new DeleteReceiverPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload();
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
self::assertEquals('123', $payload->get('sub_mchid'));
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\QueryMerchantConfigsPlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class QueryMerchantConfigsPluginTest extends TestCase
{
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
$plugin = new QueryMerchantConfigsPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/merchant-configs/1600314070'), $radar->getUri());
self::assertEquals('GET', $radar->getMethod());
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
$plugin = new QueryMerchantConfigsPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/merchant-configs/123'), $radar->getUri());
}
}

View File

@ -0,0 +1,87 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\QueryPlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class QueryPluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123','transaction_id' => '456']));
$plugin = new QueryPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/orders/123?transaction_id=456'), $radar->getUri());
self::assertEquals('GET', $radar->getMethod());
}
public function testNormalNoOutTradeNo()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection(['transaction_id' => '456']));
$plugin = new QueryPlugin();
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testNormalNoTransactionId()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123']));
$plugin = new QueryPlugin();
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','transaction_id' => '456']));
$plugin = new QueryPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders/123?transaction_id=456&sub_mchid=1600314070'), $radar->getUri());
self::assertEquals('GET', $radar->getMethod());
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','transaction_id' => '456','sub_mchid' => '123']));
$plugin = new QueryPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders/123?transaction_id=456&sub_mchid=123'), $radar->getUri());
self::assertEquals('GET', $radar->getMethod());
}
}

View File

@ -0,0 +1,87 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidParamsException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\QueryReturnPlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class QueryReturnPluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123','out_return_no' => '456']));
$plugin = new QueryReturnPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/return-orders/456?out_order_no=123'), $radar->getUri());
self::assertEquals('GET', $radar->getMethod());
}
public function testNormalNoOutTradeNo()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection(['out_return_no' => '456']));
$plugin = new QueryReturnPlugin();
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testNormalNoTransactionId()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection(['out_order_no' => '123']));
$plugin = new QueryReturnPlugin();
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','out_return_no' => '456']));
$plugin = new QueryReturnPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/return-orders/456?out_order_no=123&sub_mchid=1600314070'), $radar->getUri());
self::assertEquals('GET', $radar->getMethod());
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_order_no' => '123','out_return_no' => '456','sub_mchid' => '123']));
$plugin = new QueryReturnPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/return-orders/456?out_order_no=123&sub_mchid=123'), $radar->getUri());
self::assertEquals('GET', $radar->getMethod());
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\ReturnPlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class ReturnPluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection());
$plugin = new ReturnPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/return-orders'), $radar->getUri());
self::assertEquals('POST', $radar->getMethod());
self::assertArrayNotHasKey('sub_mchid', $payload->all());
}
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
$plugin = new ReturnPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/return-orders'), $radar->getUri());
self::assertEquals('POST', $radar->getMethod());
self::assertEquals('1600314070', $payload->get('sub_mchid'));
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
$plugin = new ReturnPlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload();
self::assertEquals('123', $payload->get('sub_mchid'));
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Fund\Profitsharing;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing\UnfreezePlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class UnfreezePluginTest extends TestCase
{
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection());
$plugin = new UnfreezePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/profitsharing/orders/unfreeze'), $radar->getUri());
self::assertEquals('POST', $radar->getMethod());
self::assertArrayNotHasKey('sub_mchid', $payload->all());
}
public function testPartner()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
$plugin = new UnfreezePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$radar = $result->getRadar();
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/profitsharing/orders/unfreeze'), $radar->getUri());
self::assertEquals('POST', $radar->getMethod());
self::assertEquals('1600314070', $payload->get('sub_mchid'));
}
public function testPartnerDirectPayload()
{
$rocket = new Rocket();
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
$plugin = new UnfreezePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload();
self::assertEquals('123', $payload->get('sub_mchid'));
}
}

View File

@ -27,6 +27,7 @@ class ClosePluginTest extends TestCase
$payload = $result->getPayload();
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/pay/transactions/out-trade-no/123/close'), $radar->getUri());
self::assertEquals('POST', $radar->getMethod());
self::assertEquals('1600314069', $payload->get('mchid'));
self::assertArrayNotHasKey('sp_mchid', $payload->all());
self::assertArrayNotHasKey('sub_mchid', $payload->all());