fix: 微信代金券详情 url 不正确 (#663)

* fixed: 微信代金券详情插件

* tests

Co-authored-by: yansongda <me@yansongda.cn>
This commit is contained in:
branll 2022-09-03 13:39:21 +08:00 committed by GitHub
parent 9aa4d3b8ad
commit 7ff004f05f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 132 additions and 17 deletions

View File

@ -1,3 +1,13 @@
## v3.1.12
### fixed
- fix: 微信代金券详情 url 不正确(#663)
### refactor
- refactor: 优化代码 (#661)
## v3.1.11
### added

View File

@ -41,7 +41,7 @@ class QueryCouponDetailPlugin extends GeneralPlugin
return 'v3/marketing/favor/users/'.
$payload->get('openid').
'coupons/'.$payload->get('coupon_id').
'/coupons/'.$payload->get('coupon_id').
'?appid='.$appid;
}
}

2
tests/Cert/foo Normal file
View File

@ -0,0 +1,2 @@
foo
-----END CERTIFICATE-----

View File

@ -2,20 +2,32 @@
namespace Yansongda\Pay\Tests\Plugin\Alipay;
use Yansongda\Pay\Contract\ConfigInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidConfigException;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Alipay\PreparePlugin;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Config;
class PreparePluginTest extends TestCase
{
protected $plugin;
protected function setUp(): void
{
parent::setUp();
$this->plugin = new PreparePlugin();
}
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([]);
$plugin = new PreparePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
$payload = $result->getPayload();
self::assertTrue($payload->has('app_cert_sn'));
@ -31,7 +43,7 @@ class PreparePluginTest extends TestCase
$rocket = new Rocket();
$rocket->setParams([]);
$result = (new PreparePlugin())->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertEquals('687b59193f3f462dd5336e5abf83c5d8_02941eef3187dddf3d3b83462e1dfcf6', $result->getPayload()->get('alipay_root_cert_sn'));
}
@ -43,9 +55,7 @@ class PreparePluginTest extends TestCase
'_return_url' => 'https://yansongda.cn',
]);
$plugin = new PreparePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertEquals('', $result->getPayload()->get('notify_url'));
self::assertEquals('https://yansongda.cn', $result->getPayload()->get('return_url'));
@ -58,9 +68,7 @@ class PreparePluginTest extends TestCase
'_notify_url' => 'https://yansongda.cn',
]);
$plugin = new PreparePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertEquals('', $result->getPayload()->get('return_url'));
self::assertEquals('https://yansongda.cn', $result->getPayload()->get('notify_url'));
@ -74,9 +82,7 @@ class PreparePluginTest extends TestCase
'_notify_url' => 'https://yansongda.cn',
]);
$plugin = new PreparePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertEquals('https://yansongda.cn', $result->getPayload()->get('return_url'));
self::assertEquals('https://yansongda.cn', $result->getPayload()->get('notify_url'));
@ -89,10 +95,64 @@ class PreparePluginTest extends TestCase
'_app_auth_token' => 'yansongda.cn',
]);
$plugin = new PreparePlugin();
$result = $plugin->assembly($rocket, function ($rocket) { return $rocket; });
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
self::assertEquals('yansongda.cn', $result->getPayload()->get('app_auth_token'));
}
public function testMissingAppPublicCertPath()
{
$rocket = new Rocket();
Pay::set(ConfigInterface::class, new Config());
self::expectException(InvalidConfigException::class);
self::expectExceptionCode(Exception::ALIPAY_CONFIG_ERROR);
self::expectExceptionMessage('Missing Alipay Config -- [app_public_cert_path]');
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testWrongAppPublicCertPath()
{
$rocket = new Rocket();
$config = Pay::get(ConfigInterface::class);
$config->set('alipay.default.app_public_cert_path', __DIR__.'/../../Cert/foo');
Pay::set(ConfigInterface::class, $config);
self::expectException(InvalidConfigException::class);
self::expectExceptionCode(Exception::ALIPAY_CONFIG_ERROR);
self::expectExceptionMessage('Parse `app_public_cert_path` Error');
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testMissingAlipayRootPath()
{
$rocket = new Rocket();
$config = Pay::get(ConfigInterface::class);
$config->set('alipay.default.alipay_root_cert_path', null);
self::expectException(InvalidConfigException::class);
self::expectExceptionCode(Exception::ALIPAY_CONFIG_ERROR);
self::expectExceptionMessage('Missing Alipay Config -- [alipay_root_cert_path]');
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
public function testWrongAlipayRootPath()
{
$rocket = new Rocket();
$config = Pay::get(ConfigInterface::class);
$config->set('alipay.default.alipay_root_cert_path', __DIR__.'/../../Cert/foo');
self::expectException(InvalidConfigException::class);
self::expectExceptionCode(Exception::ALIPAY_CONFIG_ERROR);
self::expectExceptionMessage('Invalid alipay_root_cert');
$this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Yansongda\Pay\Tests\Plugin\Wechat\Marketing\Coupon;
use GuzzleHttp\Psr7\Uri;
use Yansongda\Pay\Pay;
use Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryCouponDetailPlugin;
use Yansongda\Pay\Provider\Wechat;
use Yansongda\Pay\Rocket;
use Yansongda\Pay\Tests\TestCase;
use Yansongda\Supports\Collection;
class QueryCouponDetailPluginTest extends TestCase
{
/**
* @var \Yansongda\Pay\Plugin\Wechat\Marketing\Coupon\QueryCouponDetailPlugin
*/
protected $plugin;
protected function setUp(): void
{
parent::setUp();
$this->plugin = new QueryCouponDetailPlugin();
}
public function testNormal()
{
$rocket = new Rocket();
$rocket->setParams([])->setPayload(new Collection([
'coupon_id' => '123456',
'openid' => '7890',
]));
$result = $this->plugin->assembly($rocket, function ($rocket) {return $rocket; });
$radar = $result->getRadar();
self::assertEquals('GET', $radar->getMethod());
self::assertNull($result->getPayload());
self::assertEquals(new Uri(Wechat::URL[Pay::MODE_NORMAL].'v3/marketing/favor/users/7890/coupons/123456?appid=wx55955316af4ef13'), $radar->getUri());
}
}