mirror of
https://gitee.com/yansongda/pay.git
synced 2024-11-30 03:07:38 +08:00
feat: 服务商批量转账到零钱 (#503)
* feat: #499 * changelog * fix: 传参 sub_mch_id 可能造成的参数问题
This commit is contained in:
parent
c581fb6db7
commit
215d5f0696
@ -2,6 +2,12 @@
|
||||
|
||||
### added
|
||||
|
||||
- feat: 服务商批量转账到零钱 (#503)
|
||||
|
||||
## v3.0.9
|
||||
|
||||
### added
|
||||
|
||||
- feat: 支持直连商户批量转账到零钱 (#501)
|
||||
|
||||
## v3.0.8
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Fund\Transfer;
|
||||
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
@ -18,15 +19,26 @@ class CreatePlugin extends GeneralPlugin
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
$wechatId = [
|
||||
$extra = [
|
||||
'appid' => $config->get('mp_app_id'),
|
||||
];
|
||||
|
||||
$rocket->mergePayload($wechatId);
|
||||
if (Pay::MODE_SERVICE == $config->get('mode')) {
|
||||
$extra = [
|
||||
'sub_mchid' => $config->get('sub_mch_id', ''),
|
||||
];
|
||||
}
|
||||
|
||||
$rocket->mergePayload($extra);
|
||||
}
|
||||
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
return 'v3/transfer/batches';
|
||||
}
|
||||
|
||||
protected function getPartnerUri(Rocket $rocket): string
|
||||
{
|
||||
return 'v3/partner-transfer/batches';
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,18 @@ class QueryBatchDetailIdPlugin extends GeneralPlugin
|
||||
'/details/detail-id/'.
|
||||
$payload->get('detail_id');
|
||||
}
|
||||
|
||||
protected function getPartnerUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('batch_id')) || is_null($payload->get('detail_id'))) {
|
||||
throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/partner-transfer/batches/batch-id/'.
|
||||
$payload->get('batch_id').
|
||||
'/details/detail-id/'.
|
||||
$payload->get('detail_id');
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,19 @@ class QueryBatchIdPlugin extends GeneralPlugin
|
||||
return 'v3/transfer/batches/batch-id/'.$payload->get('batch_id').
|
||||
'?'.$payload->query();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getPartnerUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('batch_id')) || is_null($payload->get('need_query_detail'))) {
|
||||
throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/partner-transfer/batches/batch-id/'.$payload->get('batch_id').
|
||||
'?'.$payload->query();
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,21 @@ class QueryOutBatchDetailNoPlugin extends GeneralPlugin
|
||||
'/details/out-detail-no/'.
|
||||
$payload->get('out_detail_no');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getPartnerUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('out_batch_no')) || is_null($payload->get('out_detail_no'))) {
|
||||
throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/partner-transfer/batches/out-batch-no/'.
|
||||
$payload->get('out_batch_no').
|
||||
'/details/out-detail-no/'.
|
||||
$payload->get('out_detail_no');
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,19 @@ class QueryOutBatchNoPlugin extends GeneralPlugin
|
||||
return 'v3/transfer/batches/out-batch-no/'.$payload->get('out_batch_no').
|
||||
'?'.$payload->query();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getPartnerUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('out_batch_no')) || is_null($payload->get('need_query_detail'))) {
|
||||
throw new InvalidParamsException(Exception::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/partner-transfer/batches/out-batch-no/'.$payload->get('out_batch_no').
|
||||
'?'.$payload->query();
|
||||
}
|
||||
}
|
||||
|
@ -42,4 +42,20 @@ class CreateBillReceiptPluginTest extends TestCase
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartner()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123']));
|
||||
|
||||
$plugin = new CreateBillReceiptPlugin();
|
||||
|
||||
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$radar = $result->getRadar();
|
||||
$payload = $result->getPayload();
|
||||
|
||||
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/bill-receipt'), $radar->getUri());
|
||||
self::assertEquals('123', $payload->get('out_batch_no'));
|
||||
}
|
||||
}
|
||||
|
@ -56,4 +56,21 @@ class CreateDetailReceiptPluginTest extends TestCase
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartner()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_detail_no' => '123', 'accept_type' => '456']));
|
||||
|
||||
$plugin = new CreateDetailReceiptPlugin();
|
||||
|
||||
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$radar = $result->getRadar();
|
||||
$payload = $result->getPayload();
|
||||
|
||||
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer-detail/electronic-receipts'), $radar->getUri());
|
||||
self::assertEquals('123', $payload->get('out_detail_no'));
|
||||
self::assertEquals('456', $payload->get('accept_type'));
|
||||
}
|
||||
}
|
||||
|
@ -27,4 +27,21 @@ class CreatePluginTest extends TestCase
|
||||
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/batches'), $radar->getUri());
|
||||
self::assertEquals('wx55955316af4ef13', $payload->get('appid'));
|
||||
}
|
||||
|
||||
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_NORMAL].'v3/partner-transfer/batches'), $radar->getUri());
|
||||
self::assertEquals('1600314070', $payload->get('sub_mchid'));
|
||||
self::assertNull($payload->get('appid'));
|
||||
}
|
||||
}
|
||||
|
@ -54,4 +54,45 @@ class QueryBatchDetailIdPluginTest extends TestCase
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartner()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123', 'detail_id' => '456']));
|
||||
|
||||
$plugin = new QueryBatchDetailIdPlugin();
|
||||
|
||||
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$radar = $result->getRadar();
|
||||
|
||||
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/partner-transfer/batches/batch-id/123/details/detail-id/456'), $radar->getUri());
|
||||
self::assertEquals('GET', $radar->getMethod());
|
||||
}
|
||||
|
||||
public function testPartnerNoBatchId()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['detail' => '456']));
|
||||
|
||||
$plugin = new QueryBatchDetailIdPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartnerNoDetailId()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123']));
|
||||
|
||||
$plugin = new QueryBatchDetailIdPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
}
|
||||
|
@ -53,4 +53,47 @@ class QueryBatchIdPluginTest extends TestCase
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartner()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123', 'need_query_detail' => false]));
|
||||
|
||||
$plugin = new QueryBatchIdPlugin();
|
||||
|
||||
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$radar = $result->getRadar();
|
||||
$url = $radar->getUri();
|
||||
|
||||
self::assertEquals('/v3/partner-transfer/batches/batch-id/123', $url->getPath());
|
||||
self::assertStringContainsString('need_query_detail=0', $url->getQuery());
|
||||
self::assertEquals('GET', $radar->getMethod());
|
||||
}
|
||||
|
||||
public function testPartnerNoBatchId()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['need_query_detail' => false]));
|
||||
|
||||
$plugin = new QueryBatchIdPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartnerNoNeedQueryDetail()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['batch_id' => '123']));
|
||||
|
||||
$plugin = new QueryBatchIdPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
}
|
||||
|
@ -41,4 +41,32 @@ class QueryBillReceiptPluginTest extends TestCase
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartner()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123']));
|
||||
|
||||
$plugin = new QueryBillReceiptPlugin();
|
||||
|
||||
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$radar = $result->getRadar();
|
||||
|
||||
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/transfer/bill-receipt/123'), $radar->getUri());
|
||||
self::assertEquals('GET', $radar->getMethod());
|
||||
}
|
||||
|
||||
public function testPartnerNoOutBatchNo()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
|
||||
|
||||
$plugin = new QueryBillReceiptPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
}
|
||||
|
@ -54,4 +54,45 @@ class QueryOutBatchDetailNoPluginTest extends TestCase
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartner()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123', 'out_detail_no' => '456']));
|
||||
|
||||
$plugin = new QueryOutBatchDetailNoPlugin();
|
||||
|
||||
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$radar = $result->getRadar();
|
||||
|
||||
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/partner-transfer/batches/out-batch-no/123/details/out-detail-no/456'), $radar->getUri());
|
||||
self::assertEquals('GET', $radar->getMethod());
|
||||
}
|
||||
|
||||
public function testPartnerNoBatchId()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_detail_no' => '456']));
|
||||
|
||||
$plugin = new QueryOutBatchDetailNoPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartnerNoDetailId()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123']));
|
||||
|
||||
$plugin = new QueryOutBatchDetailNoPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
}
|
||||
|
@ -53,4 +53,47 @@ class QueryOutBatchNoPluginTest extends TestCase
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartner()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123', 'need_query_detail' => false]));
|
||||
|
||||
$plugin = new QueryOutBatchNoPlugin();
|
||||
|
||||
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$radar = $result->getRadar();
|
||||
$url = $radar->getUri();
|
||||
|
||||
self::assertEquals('/v3/partner-transfer/batches/out-batch-no/123', $url->getPath());
|
||||
self::assertStringContainsString('need_query_detail=0', $url->getQuery());
|
||||
self::assertEquals('GET', $radar->getMethod());
|
||||
}
|
||||
|
||||
public function testPartnerNoOutBatchNo()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['need_query_detail' => false]));
|
||||
|
||||
$plugin = new QueryOutBatchNoPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
|
||||
public function testPartnerNoNeedQueryDetail()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_batch_no' => '123']));
|
||||
|
||||
$plugin = new QueryOutBatchNoPlugin();
|
||||
|
||||
self::expectException(InvalidParamsException::class);
|
||||
self::expectExceptionCode(Exception::MISSING_NECESSARY_PARAMS);
|
||||
|
||||
$plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user