These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Yansongda\Pay\Gateways\Wechat; |
||
4 | |||
5 | use Yansongda\Pay\Contracts\GatewayInterface; |
||
6 | use Yansongda\Pay\Events; |
||
7 | use Yansongda\Pay\Exceptions\GatewayException; |
||
8 | use Yansongda\Pay\Exceptions\InvalidArgumentException; |
||
9 | use Yansongda\Pay\Exceptions\InvalidSignException; |
||
10 | use Yansongda\Supports\Collection; |
||
11 | |||
12 | abstract class Gateway implements GatewayInterface |
||
13 | { |
||
14 | /** |
||
15 | * Mode. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $mode; |
||
20 | |||
21 | /** |
||
22 | * Bootstrap. |
||
23 | * |
||
24 | * @author yansongda <[email protected]> |
||
25 | * |
||
26 | * @throws InvalidArgumentException |
||
27 | */ |
||
28 | public function __construct() |
||
29 | { |
||
30 | $this->mode = Support::getInstance()->mode; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Pay an order. |
||
35 | * |
||
36 | * @author yansongda <[email protected]> |
||
37 | * |
||
38 | * @param string $endpoint |
||
39 | * |
||
40 | * @return Collection |
||
41 | */ |
||
42 | abstract public function pay($endpoint, array $payload); |
||
43 | |||
44 | /** |
||
45 | * Find. |
||
46 | * |
||
47 | * @author yansongda <[email protected]> |
||
48 | * |
||
49 | * @param string|array $order |
||
50 | */ |
||
51 | View Code Duplication | public function find($order): array |
|
52 | { |
||
53 | return [ |
||
54 | 'endpoint' => 'pay/orderquery', |
||
55 | 'order' => is_array($order) ? $order : ['out_trade_no' => $order], |
||
56 | 'cert' => false, |
||
57 | ]; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Get trade type config. |
||
62 | * |
||
63 | * @author yansongda <[email protected]> |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | abstract protected function getTradeType(); |
||
68 | |||
69 | /** |
||
70 | * Schedule an order. |
||
71 | * |
||
72 | * @author yansongda <[email protected]> |
||
73 | * |
||
74 | * @param array $payload |
||
75 | * |
||
76 | * @throws GatewayException |
||
77 | * @throws InvalidArgumentException |
||
78 | * @throws InvalidSignException |
||
79 | */ |
||
80 | View Code Duplication | protected function preOrder($payload): Collection |
|
0 ignored issues
–
show
|
|||
81 | { |
||
82 | $payload['sign'] = Support::generateSign($payload); |
||
83 | |||
84 | Events::dispatch(new Events\MethodCalled('Wechat', 'PreOrder', '', $payload)); |
||
85 | |||
86 | return Support::requestApi('pay/unifiedorder', $payload); |
||
87 | } |
||
88 | } |
||
89 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.