Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: _type 类型统一定义为渠道id,如: 小程序id,公众号id等;增加 _action 为操作类型用于 shortcut #781

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

return (new PhpCsFixer\Config())
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'declare_strict_types' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'general_phpdoc_annotation_remove' => ['annotations' => ['author'], 'case_sensitive' => false],
'global_namespace_import' => [
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- change: ParserInterface 签名由 `?ResponseInterface $response` 变更为 `PackerInterface $packer, ?ResponseInterface $response`(#754)
- change: \Yansongda\Pay\Plugin\Wechat\RadarSignPlugin 增加 `__construct(JsonPacker $jsonPacker, XmlPacker $xmlPacker)` 方法(#753)
- change: 所有 `Parser` 更名为 `Direction`(#770, #774)
- change: '_type' 类型统一定义为渠道id,如: 小程序id,公众号id等;增加 '_action' 为操作类型用于 shortcut(#781)

## v3.2.14

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Exception extends \Exception

public const PLUGIN_ERROR = 4002;

public const SHORTCUT_MULTI_TYPE_ERROR = 4003;
public const SHORTCUT_MULTI_ACTION_ERROR = 4003;

public const METHOD_NOT_SUPPORTED = 4004;

Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Alipay/Shortcut/QueryShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class QueryShortcut implements ShortcutInterface
*/
public function getPlugins(array $params): array
{
$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (isset($params['out_request_no'])) {
return $this->refundPlugins();
Expand All @@ -29,7 +29,7 @@ public function getPlugins(array $params): array
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Query type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Query action [{$typeMethod}] not supported");
}

protected function defaultPlugins(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Unipay/Shortcut/CancelShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class CancelShortcut implements ShortcutInterface
*/
public function getPlugins(array $params): array
{
$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (method_exists($this, $typeMethod)) {
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Cancel type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Cancel action [{$typeMethod}] not supported");
}

public function defaultPlugins(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Unipay/Shortcut/PosShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class PosShortcut implements ShortcutInterface
*/
public function getPlugins(array $params): array
{
$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (method_exists($this, $typeMethod)) {
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Pos type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Pos action [{$typeMethod}] not supported");
}

public function defaultPlugins(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Unipay/Shortcut/QueryShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class QueryShortcut implements ShortcutInterface
*/
public function getPlugins(array $params): array
{
$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (method_exists($this, $typeMethod)) {
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Query type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Query action [{$typeMethod}] not supported");
}

public function defaultPlugins(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Unipay/Shortcut/RefundShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class RefundShortcut implements ShortcutInterface
*/
public function getPlugins(array $params): array
{
$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (method_exists($this, $typeMethod)) {
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Refund type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Refund action [{$typeMethod}] not supported");
}

public function defaultPlugins(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Unipay/Shortcut/ScanShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class ScanShortcut implements ShortcutInterface
*/
public function getPlugins(array $params): array
{
$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (method_exists($this, $typeMethod)) {
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Scan type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Scan action [{$typeMethod}] not supported");
}

public function defaultPlugins(): array
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin/Wechat/Papay/ApplyPlugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Yansongda\Pay\Plugin\Wechat\Papay;

use Yansongda\Pay\Plugin\Wechat\GeneralV2Plugin;
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin/Wechat/Papay/ContractOrderPlugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Yansongda\Pay\Plugin\Wechat\Papay;

use Yansongda\Pay\Plugin\Wechat\GeneralV2Plugin;
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin/Wechat/Papay/OnlyContractPlugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Yansongda\Pay\Plugin\Wechat\Papay;

use Closure;
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Wechat/Shortcut/CloseShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public function getPlugins(array $params): array
return $this->combinePlugins();
}

$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (method_exists($this, $typeMethod)) {
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Query type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Query action [{$typeMethod}] not supported");
}

protected function defaultPlugins(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Wechat/Shortcut/QueryShortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public function getPlugins(array $params): array
return $this->combinePlugins();
}

$typeMethod = Str::camel($params['_type'] ?? 'default').'Plugins';
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins';

if (method_exists($this, $typeMethod)) {
return $this->{$typeMethod}();
}

throw new InvalidParamsException(Exception::SHORTCUT_MULTI_TYPE_ERROR, "Query type [{$typeMethod}] not supported");
throw new InvalidParamsException(Exception::SHORTCUT_MULTI_ACTION_ERROR, "Query action [{$typeMethod}] not supported");
}

protected function defaultPlugins(): array
Expand Down
10 changes: 5 additions & 5 deletions tests/Plugin/Alipay/Shortcut/QueryShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ public function testRefund()
{
self::assertEquals([
FastRefundQueryPlugin::class,
], $this->plugin->getPlugins(['_type' => 'refund']));
], $this->plugin->getPlugins(['_action' => 'refund']));
}

public function testTransfer()
{
self::assertEquals([
TransCommonQueryPlugin::class,
], $this->plugin->getPlugins(['_type' => 'transfer']));
], $this->plugin->getPlugins(['_action' => 'transfer']));
}

public function testFoo()
{
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::SHORTCUT_MULTI_TYPE_ERROR);
self::expectExceptionMessage('Query type [fooPlugins] not supported');
self::expectExceptionCode(Exception::SHORTCUT_MULTI_ACTION_ERROR);
self::expectExceptionMessage('Query action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
8 changes: 4 additions & 4 deletions tests/Plugin/Unipay/Shortcut/CancelShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function testQrCode()
{
self::assertEquals([
\Yansongda\Pay\Plugin\Unipay\QrCode\CancelPlugin::class,
], $this->plugin->getPlugins(['_type' => 'qr_code']));
], $this->plugin->getPlugins(['_action' => 'qr_code']));
}

public function testFoo()
{
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::SHORTCUT_MULTI_TYPE_ERROR);
self::expectExceptionMessage('Cancel type [fooPlugins] not supported');
self::expectExceptionCode(Exception::SHORTCUT_MULTI_ACTION_ERROR);
self::expectExceptionMessage('Cancel action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
8 changes: 4 additions & 4 deletions tests/Plugin/Unipay/Shortcut/PosShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public function testPreAuth()
{
self::assertEquals([
PosPreAuthPlugin::class,
], $this->plugin->getPlugins(['_type' => 'pre_auth']));
], $this->plugin->getPlugins(['_action' => 'pre_auth']));
}

public function testFoo()
{
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::SHORTCUT_MULTI_TYPE_ERROR);
self::expectExceptionMessage('Pos type [fooPlugins] not supported');
self::expectExceptionCode(Exception::SHORTCUT_MULTI_ACTION_ERROR);
self::expectExceptionMessage('Pos action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
8 changes: 4 additions & 4 deletions tests/Plugin/Unipay/Shortcut/QueryShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function testQrCode()
{
self::assertEquals([
\Yansongda\Pay\Plugin\Unipay\QrCode\QueryPlugin::class,
], $this->plugin->getPlugins(['_type' => 'qr_code']));
], $this->plugin->getPlugins(['_action' => 'qr_code']));
}

public function testFoo()
{
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::SHORTCUT_MULTI_TYPE_ERROR);
self::expectExceptionMessage('Query type [fooPlugins] not supported');
self::expectExceptionCode(Exception::SHORTCUT_MULTI_ACTION_ERROR);
self::expectExceptionMessage('Query action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
6 changes: 3 additions & 3 deletions tests/Plugin/Unipay/Shortcut/RefundShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function testQrCode()
{
self::assertEquals([
\Yansongda\Pay\Plugin\Unipay\QrCode\RefundPlugin::class,
], $this->plugin->getPlugins(['_type' => 'qr_code']));
], $this->plugin->getPlugins(['_action' => 'qr_code']));
}

public function testFoo()
{
$this->expectException(InvalidParamsException::class);
$this->expectExceptionMessage('Refund type [fooPlugins] not supported');
$this->expectExceptionMessage('Refund action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
12 changes: 6 additions & 6 deletions tests/Plugin/Unipay/Shortcut/ScanShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@ public function testPreAuth()
{
self::assertEquals([
ScanPreAuthPlugin::class,
], $this->plugin->getPlugins(['_type' => 'pre_auth']));
], $this->plugin->getPlugins(['_action' => 'pre_auth']));
}

public function testPreOrder()
{
self::assertEquals([
ScanPreOrderPlugin::class,
], $this->plugin->getPlugins(['_type' => 'pre_order']));
], $this->plugin->getPlugins(['_action' => 'pre_order']));
}

public function testFee()
{
self::assertEquals([
ScanFeePlugin::class,
], $this->plugin->getPlugins(['_type' => 'fee']));
], $this->plugin->getPlugins(['_action' => 'fee']));
}

public function testFoo()
{
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::SHORTCUT_MULTI_TYPE_ERROR);
self::expectExceptionMessage('Scan type [fooPlugins] not supported');
self::expectExceptionCode(Exception::SHORTCUT_MULTI_ACTION_ERROR);
self::expectExceptionMessage('Scan action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
8 changes: 4 additions & 4 deletions tests/Plugin/Wechat/Shortcut/CloseShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testCombine()
{
self::assertEquals([
\Yansongda\Pay\Plugin\Wechat\Pay\Combine\ClosePlugin::class,
], $this->plugin->getPlugins(['_type' => 'combine']));
], $this->plugin->getPlugins(['_action' => 'combine']));
}

public function testCombineParams()
Expand All @@ -50,9 +50,9 @@ public function testCombineParams()
public function testFoo()
{
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::SHORTCUT_MULTI_TYPE_ERROR);
self::expectExceptionMessage('Query type [fooPlugins] not supported');
self::expectExceptionCode(Exception::SHORTCUT_MULTI_ACTION_ERROR);
self::expectExceptionMessage('Query action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
10 changes: 5 additions & 5 deletions tests/Plugin/Wechat/Shortcut/QueryShortcutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function testRefund()
{
self::assertEquals([
QueryRefundPlugin::class,
], $this->plugin->getPlugins(['_type' => 'refund']));
], $this->plugin->getPlugins(['_action' => 'refund']));
}

public function testCombine()
{
self::assertEquals([
\Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin::class,
], $this->plugin->getPlugins(['_type' => 'combine']));
], $this->plugin->getPlugins(['_action' => 'combine']));
}

public function testCombineParams()
Expand All @@ -53,9 +53,9 @@ public function testCombineParams()
public function testFoo()
{
self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::SHORTCUT_MULTI_TYPE_ERROR);
self::expectExceptionMessage('Query type [fooPlugins] not supported');
self::expectExceptionCode(Exception::SHORTCUT_MULTI_ACTION_ERROR);
self::expectExceptionMessage('Query action [fooPlugins] not supported');

$this->plugin->getPlugins(['_type' => 'foo']);
$this->plugin->getPlugins(['_action' => 'foo']);
}
}
4 changes: 2 additions & 2 deletions tests/Provider/AlipayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testFindTransfer()
$http->shouldReceive('sendRequest')->andReturn(new Response(200, [], json_encode($response)));
Pay::set(HttpClientInterface::class, $http);

$result = Pay::alipay()->find(['out_biz_no' => '202209032319', '_type' => 'transfer']);
$result = Pay::alipay()->find(['out_biz_no' => '202209032319', '_action' => 'transfer']);
self::assertEqualsCanonicalizing($response['alipay_fund_trans_common_query_response'], $result->all());
}

Expand Down Expand Up @@ -118,7 +118,7 @@ public function testFindRefund()
$result = Pay::alipay()->find([
'out_trade_no' => '1623160012',
'out_request_no' => '1623160012',
'_type' => 'refund'
'_action' => 'refund'
]);
self::assertEqualsCanonicalizing($response['alipay_trade_fastpay_refund_query_response'], $result->all());

Expand Down