ScanGateway   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pay() 0 9 1
A getTradeType() 0 4 1
1
<?php
2
3
namespace Yansongda\Pay\Gateways\Wechat;
4
5
use Symfony\Component\HttpFoundation\Request;
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
class ScanGateway extends Gateway
13
{
14
    /**
15
     * Pay an order.
16
     *
17
     * @author yansongda <[email protected]>
18
     *
19
     * @param string $endpoint
20
     *
21
     * @throws GatewayException
22
     * @throws InvalidArgumentException
23
     * @throws InvalidSignException
24
     */
25
    public function pay($endpoint, array $payload): Collection
26
    {
27
        $payload['spbill_create_ip'] = Request::createFromGlobals()->server->get('SERVER_ADDR');
28
        $payload['trade_type'] = $this->getTradeType();
29
30
        Events::dispatch(new Events\PayStarted('Wechat', 'Scan', $endpoint, $payload));
31
32
        return $this->preOrder($payload);
33
    }
34
35
    /**
36
     * Get trade type config.
37
     *
38
     * @author yansongda <[email protected]>
39
     */
40
    protected function getTradeType(): string
41
    {
42
        return 'NATIVE';
43
    }
44
}
45