|
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\Papay\ApplyPlugin; |
|
12
|
|
|
use Yansongda\Pay\Plugin\Wechat\Papay\ContractOrderPlugin; |
|
13
|
|
|
use Yansongda\Pay\Plugin\Wechat\Papay\OnlyContractPlugin; |
|
14
|
|
|
use Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokePrepayV2Plugin; |
|
15
|
|
|
use Yansongda\Pay\Plugin\Wechat\PreparePlugin; |
|
16
|
|
|
use Yansongda\Pay\Plugin\Wechat\RadarSignPlugin; |
|
17
|
|
|
use Yansongda\Supports\Str; |
|
18
|
|
|
|
|
19
|
|
|
class PapayShortcut implements ShortcutInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @throws InvalidParamsException |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getPlugins(array $params): array |
|
25
|
|
|
{ |
|
26
|
|
|
$typeMethod = Str::camel($params['_action'] ?? 'default').'Plugins'; |
|
27
|
|
|
|
|
28
|
|
|
if (method_exists($this, $typeMethod)) { |
|
29
|
|
|
return $this->{$typeMethod}($params); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "Papay action [{$typeMethod}] not supported"); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* 返回只签约(委托代扣)参数. |
|
37
|
|
|
* |
|
38
|
|
|
* @see https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_3.shtml |
|
39
|
|
|
*/ |
|
40
|
|
|
public function ContractPlugins(): array |
|
41
|
|
|
{ |
|
42
|
|
|
return [ |
|
43
|
|
|
PreparePlugin::class, |
|
44
|
|
|
OnlyContractPlugin::class, |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* 申请代扣. |
|
50
|
|
|
* |
|
51
|
|
|
* @see https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_8.shtml |
|
52
|
|
|
*/ |
|
53
|
|
|
public function applyPlugins(): array |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
PreparePlugin::class, |
|
57
|
|
|
ApplyPlugin::class, |
|
58
|
|
|
RadarSignPlugin::class, |
|
59
|
|
|
ParserPlugin::class, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* 支付中签约. |
|
65
|
|
|
* |
|
66
|
|
|
* @see https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter3_5.shtml |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function defaultPlugins(array $params): array |
|
69
|
|
|
{ |
|
70
|
|
|
return [ |
|
71
|
|
|
PreparePlugin::class, |
|
72
|
|
|
ContractOrderPlugin::class, |
|
73
|
|
|
RadarSignPlugin::class, |
|
74
|
|
|
$this->getInvoke($params), |
|
75
|
|
|
ParserPlugin::class, |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function getInvoke(array $params): string |
|
80
|
|
|
{ |
|
81
|
|
|
return match ($params['_type'] ?? 'default') { |
|
82
|
|
|
'app' => \Yansongda\Pay\Plugin\Wechat\Pay\App\InvokePrepayV2Plugin::class, |
|
83
|
|
|
'mini' => \Yansongda\Pay\Plugin\Wechat\Pay\Mini\InvokePrepayV2Plugin::class, |
|
84
|
|
|
default => InvokePrepayV2Plugin::class, |
|
85
|
|
|
}; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|