Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yansongda committed Sep 13, 2022
1 parent f7a06da commit e16a856
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v3.2.3

### added

- feat: 微信 Native 支付支持关联其它类型 appid(#680)

## v3.2.2

### refactor
Expand Down
7 changes: 6 additions & 1 deletion src/Plugin/Wechat/Pay/Common/PrepayPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ protected function getWechatId(array $config, Rocket $rocket): array

protected function getConfigKey(array $params): string
{
return 'mp_app_id';
$key = ($params['_type'] ?? 'mp').'_app_id';
if ('app_app_id' === $key) {
$key = 'app_id';
}

return $key;
}
}
10 changes: 0 additions & 10 deletions src/Plugin/Wechat/Pay/H5/PrepayPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ protected function getPartnerUri(Rocket $rocket): string
{
return 'v3/pay/partner/transactions/h5';
}

protected function getConfigKey(array $params): string
{
$key = ($params['_type'] ?? 'mp').'_app_id';
if ('app_app_id' === $key) {
$key = 'app_id';
}

return $key;
}
}
10 changes: 0 additions & 10 deletions src/Plugin/Wechat/Pay/Native/PrepayPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ protected function getPartnerUri(Rocket $rocket): string
{
return 'v3/pay/partner/transactions/native';
}

protected function getConfigKey(array $params): string
{
$key = ($params['_type'] ?? 'mp').'_app_id';
if ('app_app_id' === $key) {
$key = 'app_id';
}

return $key;
}
}
13 changes: 13 additions & 0 deletions tests/Plugin/Wechat/Pay/App/PrepayPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public function testWechatIdNormal()
self::assertEquals('1600314069', $payload->get('mchid'));
}

public function testWechatIdNormalWithType()
{
$rocket = new Rocket();
$rocket->setParams(['_type' => 'mini'])->setPayload(new Collection());

$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });

$payload = $result->getPayload();

self::assertEquals('yansongda', $payload->get('appid'));
self::assertEquals('1600314069', $payload->get('mchid'));
}

public function testWechatIdPartner()
{
$rocket = new Rocket();
Expand Down
21 changes: 21 additions & 0 deletions tests/Plugin/Wechat/Pay/Common/PrepayPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ public function testNormal()
self::assertEquals('1600314069', $payload->get('mchid'));
}

public function testNormalType()
{
$rocket = new Rocket();
$rocket->setParams(['_type' => 'mini'])->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_NORMAL].'v3/pay/transactions/jsapi'), $radar->getUri());
self::assertArrayNotHasKey('sp_appid', $payload->all());
self::assertArrayNotHasKey('sp_mchid', $payload->all());
self::assertArrayNotHasKey('sub_appid', $payload->all());
self::assertArrayNotHasKey('sub_mchid', $payload->all());
self::assertEquals('wx55955316af4ef14', $payload->get('appid'));
self::assertEquals('1600314069', $payload->get('mchid'));
}

public function testPartner()
{
$rocket = new Rocket();
Expand Down
13 changes: 13 additions & 0 deletions tests/Plugin/Wechat/Pay/Mini/PrepayPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public function testWechatIdNormal()
self::assertEquals('1600314069', $payload->get('mchid'));
}

public function testWechatIdNormalWithType()
{
$rocket = new Rocket();
$rocket->setParams(['_type' => 'app'])->setPayload(new Collection());

$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });

$payload = $result->getPayload();

self::assertEquals('wx55955316af4ef14', $payload->get('appid'));
self::assertEquals('1600314069', $payload->get('mchid'));
}

public function testWechatIdPartner()
{
$rocket = new Rocket();
Expand Down

0 comments on commit e16a856

Please sign in to comment.