Skip to content

Commit

Permalink
change: 查询API方法由 find 改为 query,同时参数只支持 array (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
yansongda authored Dec 22, 2023
1 parent 6259850 commit dc6fc6e
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- change(internal): 按场景对支付宝插件进行分类(#894)
- change(internal): 支付宝 shortcut 从 plugin 文件夹独立出来(#895)
- change(internal): DirectionInterface 方法由 `parse` 改为 `guide`(#896)
- change: 查询API方法由 `find` 改为 `query`,同时参数只支持 array(#897)

## v3.5.3

Expand Down
2 changes: 1 addition & 1 deletion src/Contract/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ProviderInterface
*/
public function pay(array $plugins, array $params): null|array|Collection|MessageInterface;

public function find(array|string $order): array|Collection;
public function query(array $order): array|Collection;

public function cancel(array|string $order): null|array|Collection;

Expand Down
4 changes: 1 addition & 3 deletions src/Provider/Alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ public function __call(string $shortcut, array $params): null|Collection|Message
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function find(array|string $order): array|Collection
public function query(array $order): array|Collection
{
$order = is_array($order) ? $order : ['out_trade_no' => $order];

Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null));

return $this->__call('query', [$order]);
Expand Down
6 changes: 1 addition & 5 deletions src/Provider/Unipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ public function __call(string $shortcut, array $params): null|Collection|Message
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function find(array|string $order): array|Collection
public function query(array $order): array|Collection
{
if (!is_array($order)) {
throw new InvalidParamsException(Exception::UNIPAY_FIND_STRING_NOT_SUPPORTED);
}

Event::dispatch(new Event\MethodCalled('unipay', __METHOD__, $order, null));

return $this->__call('query', [$order]);
Expand Down
4 changes: 1 addition & 3 deletions src/Provider/Wechat.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ public function __call(string $shortcut, array $params): null|Collection|Message
* @throws InvalidParamsException
* @throws ServiceNotFoundException
*/
public function find(array|string $order): array|Collection
public function query(array $order): array|Collection
{
$order = is_array($order) ? $order : ['transaction_id' => $order];

Event::dispatch(new Event\MethodCalled('wechat', __METHOD__, $order, null));

return $this->__call('query', [$order]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testNoCommonPlugins()

class FooProviderStub extends AbstractProvider
{
public function find(array|string $order): Collection
public function query(array $order): Collection
{
return new Collection();
}
Expand Down
16 changes: 8 additions & 8 deletions tests/Provider/AlipayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testShortcutIncompatible()
Pay::alipay()->foo();
}

public function testFindDefault()
public function testQueryDefault()
{
$response = [
"alipay_trade_query_response" => [
Expand All @@ -65,12 +65,12 @@ public function testFindDefault()
$http->shouldReceive('sendRequest')->andReturn(new Response(200, [], json_encode($response)));
Pay::set(HttpClientInterface::class, $http);

$result = Pay::alipay()->find('1703141270');
$result = Pay::alipay()->query(['out_trade_no' => '1703141270']);

self::assertEqualsCanonicalizing($response['alipay_trade_query_response'], $result->except('_sign')->all());
}

public function testFindTransfer()
public function testQueryTransfer()
{
$response = [
"alipay_fund_trans_common_query_response" => [
Expand All @@ -90,11 +90,11 @@ 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', '_action' => 'transfer']);
$result = Pay::alipay()->query(['out_biz_no' => '202209032319', '_action' => 'transfer']);
self::assertEqualsCanonicalizing($response['alipay_fund_trans_common_query_response'], $result->except('_sign')->all());
}

public function testFindRefund()
public function testQueryRefund()
{
$response = [
"alipay_trade_fastpay_refund_query_response" => [
Expand All @@ -116,18 +116,18 @@ public function testFindRefund()
);
Pay::set(HttpClientInterface::class, $http);

$result = Pay::alipay()->find([
$result = Pay::alipay()->query([
'out_trade_no' => '1703141270',
'out_request_no' => '1703141270',
'_action' => 'refund'
]);
self::assertEqualsCanonicalizing($response['alipay_trade_fastpay_refund_query_response'], $result->except('_sign')->all());

$result1 = Pay::alipay()->find([
$result1 = Pay::alipay()->query([
'out_trade_no' => '1703141270',
'out_request_no' => '1703141270',
]);
self::assertEqualsCanonicalizing($response['alipay_trade_fastpay_refund_query_response'], $result->except('_sign')->all());
self::assertEqualsCanonicalizing($response['alipay_trade_fastpay_refund_query_response'], $result1->except('_sign')->all());
}

public function testClose()
Expand Down
8 changes: 2 additions & 6 deletions tests/Provider/UnipayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testMergeCommonPlugins()
), Pay::unipay()->mergeCommonPlugins($plugins));
}

public function testFind()
public function testQuery()
{
$response = [
"accNo" => "dZRvehtDtCcBPbPBVJk+ezkyeXkF07UnbKwr8/012R5XSsDLE4RqpHSLis7WCItKIf6SYUcXCLHYpV9deIfnJfziDGpUdQXnlPfejrw5pKglzjKI/pRYg0ApNomryVBIoUIdTwlpELh048ITEojRgJwzaazWdLaB5iZPeN22E2KP7JkfwsYHEclVpLY4tYEc35IjMpWCs0i8U5KY4qAJ3zXpCFIur4x+9z4gyK89Mwf+csowScvfDbFBsqTpClQlNRJ6lLWOrISNnlCdc1ONK4QVhabDTTWsemM7PSuya2e3imeZFfRYDmSv6W1eMIs0gbRo8BxOr3suUhb2ukPL7w==",
Expand Down Expand Up @@ -109,16 +109,12 @@ public function testFind()
$http->shouldReceive('sendRequest')->andReturn(new Response(200, [], json_encode($response)));
Pay::set(HttpClientInterface::class, $http);

$result = Pay::unipay()->find([
$result = Pay::unipay()->query([
'txnTime' => '20220911041647',
'orderId' => 'pay20220911041647',
]);

self::assertArrayHasKey('origRespMsg', $result->all());

self::expectException(InvalidParamsException::class);
self::expectExceptionCode(Exception::UNIPAY_FIND_STRING_NOT_SUPPORTED);
Pay::unipay()->find('123');
}

public function testCancel()
Expand Down

0 comments on commit dc6fc6e

Please sign in to comment.