mirror of
https://gitee.com/yansongda/pay.git
synced 2024-11-30 03:07:38 +08:00
feat: 微信服务商退款及查询退款支持自动 sub_mchid 参数 (#619)
* feat: 微信服务商退款及查询退款支持自动 sub_mchid 参数 * tests: fix unit tests
This commit is contained in:
parent
b493c936c6
commit
d56f0527d6
18
CHANGELOG.md
18
CHANGELOG.md
@ -1,3 +1,21 @@
|
|||||||
|
## v3.1.5
|
||||||
|
|
||||||
|
### added
|
||||||
|
|
||||||
|
- feat: 微信服务商退款及查询退款支持自动 sub_mchid 参数(#619)
|
||||||
|
|
||||||
|
## v3.1.4
|
||||||
|
|
||||||
|
### added
|
||||||
|
|
||||||
|
- feat: 支持微信投诉API (#614)
|
||||||
|
|
||||||
|
## v3.1.3
|
||||||
|
|
||||||
|
### added
|
||||||
|
|
||||||
|
- feat: 配置文件增加第三方应用授权token的支持 (#602)
|
||||||
|
|
||||||
## v3.1.2
|
## v3.1.2
|
||||||
|
|
||||||
### fixed
|
### fixed
|
||||||
|
@ -25,6 +25,18 @@ class FindRefundPlugin extends GeneralPlugin
|
|||||||
return 'v3/refund/domestic/refunds/'.$payload->get('out_refund_no');
|
return 'v3/refund/domestic/refunds/'.$payload->get('out_refund_no');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||||
|
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||||
|
*/
|
||||||
|
protected function getPartnerUri(Rocket $rocket): string
|
||||||
|
{
|
||||||
|
$config = get_wechat_config($rocket->getParams());
|
||||||
|
$url = parent::getPartnerUri($rocket);
|
||||||
|
|
||||||
|
return $url.'?sub_mchid='.($rocket->getPayload()->get('sub_mchid', $config->get('sub_mch_id')));
|
||||||
|
}
|
||||||
|
|
||||||
protected function getMethod(): string
|
protected function getMethod(): string
|
||||||
{
|
{
|
||||||
return 'GET';
|
return 'GET';
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
|
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
|
||||||
|
|
||||||
|
use Yansongda\Pay\Pay;
|
||||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||||
use Yansongda\Pay\Rocket;
|
use Yansongda\Pay\Rocket;
|
||||||
|
|
||||||
@ -14,7 +15,18 @@ class RefundPlugin extends GeneralPlugin
|
|||||||
return 'v3/refund/domestic/refunds';
|
return 'v3/refund/domestic/refunds';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||||
|
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||||
|
*/
|
||||||
protected function doSomething(Rocket $rocket): void
|
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')),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
71
tests/Plugin/Wechat/Pay/Common/FindRefundPluginTest.php
Normal file
71
tests/Plugin/Wechat/Pay/Common/FindRefundPluginTest.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Yansongda\Pay\Tests\Plugin\Wechat\Pay\Common;
|
||||||
|
|
||||||
|
use GuzzleHttp\Psr7\Uri;
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
use Yansongda\Pay\Pay;
|
||||||
|
use Yansongda\Pay\Plugin\Wechat\Pay\Common\FindRefundPlugin;
|
||||||
|
use Yansongda\Pay\Provider\Wechat;
|
||||||
|
use Yansongda\Pay\Rocket;
|
||||||
|
use Yansongda\Pay\Tests\TestCase;
|
||||||
|
use Yansongda\Supports\Collection;
|
||||||
|
|
||||||
|
class FindRefundPluginTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Yansongda\Pay\Plugin\Wechat\Pay\Common\FindRefundPlugin
|
||||||
|
*/
|
||||||
|
protected $plugin;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->plugin = new FindRefundPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormal()
|
||||||
|
{
|
||||||
|
$rocket = new Rocket();
|
||||||
|
$rocket->setParams([])->setPayload(new Collection(['out_refund_no' => '123']));
|
||||||
|
|
||||||
|
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||||
|
|
||||||
|
$radar = $result->getRadar();
|
||||||
|
$payload = $result->getPayload();
|
||||||
|
|
||||||
|
self::assertInstanceOf(RequestInterface::class, $radar);
|
||||||
|
self::assertEquals('GET', $radar->getMethod());
|
||||||
|
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/refund/domestic/refunds/123'), $radar->getUri());
|
||||||
|
self::assertNull($payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPartner()
|
||||||
|
{
|
||||||
|
$rocket = new Rocket();
|
||||||
|
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['out_refund_no' => '123']));
|
||||||
|
|
||||||
|
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||||
|
|
||||||
|
$radar = $result->getRadar();
|
||||||
|
$payload = $result->getPayload();
|
||||||
|
|
||||||
|
self::assertInstanceOf(RequestInterface::class, $radar);
|
||||||
|
self::assertEquals('GET', $radar->getMethod());
|
||||||
|
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/refund/domestic/refunds/123?sub_mchid=1600314070'), $radar->getUri());
|
||||||
|
self::assertNull($payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPartnerDirectPayload()
|
||||||
|
{
|
||||||
|
$rocket = new Rocket();
|
||||||
|
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123','out_refund_no' => '456']));
|
||||||
|
|
||||||
|
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||||
|
|
||||||
|
$radar = $result->getRadar();
|
||||||
|
|
||||||
|
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/refund/domestic/refunds/456?sub_mchid=123'), $radar->getUri());
|
||||||
|
}
|
||||||
|
}
|
69
tests/Plugin/Wechat/Pay/Common/RefundPluginTest.php
Normal file
69
tests/Plugin/Wechat/Pay/Common/RefundPluginTest.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Yansongda\Pay\Tests\Plugin\Wechat\Pay\Common;
|
||||||
|
|
||||||
|
use GuzzleHttp\Psr7\Uri;
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
use Yansongda\Pay\Pay;
|
||||||
|
use Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin;
|
||||||
|
use Yansongda\Pay\Provider\Wechat;
|
||||||
|
use Yansongda\Pay\Rocket;
|
||||||
|
use Yansongda\Pay\Tests\TestCase;
|
||||||
|
use Yansongda\Supports\Collection;
|
||||||
|
|
||||||
|
class RefundPluginTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Yansongda\Pay\Plugin\Wechat\Pay\Common\RefundPlugin
|
||||||
|
*/
|
||||||
|
protected $plugin;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->plugin = new RefundPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormal()
|
||||||
|
{
|
||||||
|
$rocket = new Rocket();
|
||||||
|
$rocket->setParams([])->setPayload(new Collection());
|
||||||
|
|
||||||
|
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||||
|
|
||||||
|
$radar = $result->getRadar();
|
||||||
|
|
||||||
|
self::assertInstanceOf(RequestInterface::class, $radar);
|
||||||
|
self::assertEquals('POST', $radar->getMethod());
|
||||||
|
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/refund/domestic/refunds'), $radar->getUri());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPartner()
|
||||||
|
{
|
||||||
|
$rocket = new Rocket();
|
||||||
|
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection());
|
||||||
|
|
||||||
|
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||||
|
|
||||||
|
$radar = $result->getRadar();
|
||||||
|
$payload = $result->getPayload();
|
||||||
|
|
||||||
|
self::assertInstanceOf(RequestInterface::class, $radar);
|
||||||
|
self::assertEquals('POST', $radar->getMethod());
|
||||||
|
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_SERVICE].'v3/refund/domestic/refunds'), $radar->getUri());
|
||||||
|
self::assertEquals('1600314070', $payload->get('sub_mchid'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPartnerDirectPayload()
|
||||||
|
{
|
||||||
|
$rocket = new Rocket();
|
||||||
|
$rocket->setParams(['_config' => 'service_provider'])->setPayload(new Collection(['sub_mchid' => '123']));
|
||||||
|
|
||||||
|
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||||
|
|
||||||
|
$payload = $result->getPayload();
|
||||||
|
|
||||||
|
self::assertEquals('123', $payload->get('sub_mchid'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user