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\Alipay; |
||
4 | |||
5 | use Yansongda\Pay\Events; |
||
6 | use Yansongda\Pay\Exceptions\GatewayException; |
||
7 | use Yansongda\Pay\Exceptions\InvalidArgumentException; |
||
8 | use Yansongda\Pay\Exceptions\InvalidConfigException; |
||
9 | use Yansongda\Pay\Exceptions\InvalidSignException; |
||
10 | use Yansongda\Pay\Gateways\Alipay; |
||
11 | use Yansongda\Supports\Collection; |
||
12 | |||
13 | View Code Duplication | class ScanGateway extends Gateway |
|
0 ignored issues
–
show
|
|||
14 | { |
||
15 | /** |
||
16 | * Pay an order. |
||
17 | * |
||
18 | * @author yansongda <[email protected]> |
||
19 | * |
||
20 | * @param string $endpoint |
||
21 | * |
||
22 | * @throws GatewayException |
||
23 | * @throws InvalidArgumentException |
||
24 | * @throws InvalidConfigException |
||
25 | * @throws InvalidSignException |
||
26 | */ |
||
27 | public function pay($endpoint, array $payload): Collection |
||
28 | { |
||
29 | $payload['method'] = 'alipay.trade.precreate'; |
||
30 | $biz_array = json_decode($payload['biz_content'], true); |
||
31 | if ((Alipay::MODE_SERVICE === $this->mode) && (!empty(Support::getInstance()->pid))) { |
||
32 | $biz_array['extend_params'] = is_array($biz_array['extend_params']) ? array_merge(['sys_service_provider_id' => Support::getInstance()->pid], $biz_array['extend_params']) : ['sys_service_provider_id' => Support::getInstance()->pid]; |
||
33 | } |
||
34 | $payload['biz_content'] = json_encode(array_merge($biz_array, ['product_code' => ''])); |
||
35 | $payload['sign'] = Support::generateSign($payload); |
||
36 | |||
37 | Events::dispatch(new Events\PayStarted('Alipay', 'Scan', $endpoint, $payload)); |
||
38 | |||
39 | return Support::requestApi($payload); |
||
40 | } |
||
41 | } |
||
42 |
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.