|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Shortcut\Wechat; |
|
6
|
|
|
|
|
7
|
|
|
use Yansongda\Pay\Contract\ShortcutInterface; |
|
8
|
|
|
use Yansongda\Pay\Exception\Exception; |
|
9
|
|
|
use Yansongda\Pay\Exception\InvalidParamsException; |
|
10
|
|
|
use Yansongda\Pay\Plugin\ParserPlugin; |
|
11
|
|
|
use Yansongda\Pay\Plugin\Wechat\LaunchPlugin; |
|
12
|
|
|
use Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin; |
|
13
|
|
|
use Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryRefundPlugin; |
|
14
|
|
|
use Yansongda\Pay\Plugin\Wechat\PreparePlugin; |
|
15
|
|
|
use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; |
|
16
|
|
|
use Yansongda\Supports\Str; |
|
17
|
|
|
|
|
18
|
|
|
class QueryShortcut implements ShortcutInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @throws InvalidParamsException |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getPlugins(array $params): array |
|
24
|
|
|
{ |
|
25
|
|
|
if (isset($params['combine_out_trade_no'])) { |
|
26
|
|
|
return $this->combinePlugins(); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins'; |
|
30
|
|
|
|
|
31
|
|
|
if (method_exists($this, $typeMethod)) { |
|
32
|
|
|
return $this->{$typeMethod}(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Query action [{$typeMethod}] not supported"); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function defaultPlugins(): array |
|
39
|
|
|
{ |
|
40
|
|
|
return [ |
|
41
|
|
|
PreparePlugin::class, |
|
42
|
|
|
QueryPlugin::class, |
|
43
|
|
|
RadarSignPlugin::class, |
|
44
|
|
|
LaunchPlugin::class, |
|
45
|
|
|
ParserPlugin::class, |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function refundPlugins(): array |
|
50
|
|
|
{ |
|
51
|
|
|
return [ |
|
52
|
|
|
PreparePlugin::class, |
|
53
|
|
|
QueryRefundPlugin::class, |
|
54
|
|
|
RadarSignPlugin::class, |
|
55
|
|
|
LaunchPlugin::class, |
|
56
|
|
|
ParserPlugin::class, |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function combinePlugins(): array |
|
61
|
|
|
{ |
|
62
|
|
|
return [ |
|
63
|
|
|
PreparePlugin::class, |
|
64
|
|
|
\Yansongda\Pay\Plugin\Wechat\Pay\Combine\QueryPlugin::class, |
|
65
|
|
|
RadarSignPlugin::class, |
|
66
|
|
|
LaunchPlugin::class, |
|
67
|
|
|
ParserPlugin::class, |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: