ScanGateway   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 38
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
     * @param array  $payload
21
     *
22
     * @throws GatewayException
23
     * @throws InvalidArgumentException
24
     * @throws InvalidSignException
25
     *
26
     * @return Collection
27
     */
28
    public function pay($endpoint, array $payload): Collection
29
    {
30
        $payload['spbill_create_ip'] = Request::createFromGlobals()->server->get('SERVER_ADDR');
31
        $payload['trade_type'] = $this->getTradeType();
32
33
        Events::dispatch(new Events\PayStarted('Wechat', 'Scan', $endpoint, $payload));
34
35
        return $this->preOrder($payload);
36
    }
37
38
    /**
39
     * Get trade type config.
40
     *
41
     * @author yansongda <[email protected]>
42
     *
43
     * @return string
44
     */
45
    protected function getTradeType(): string
46
    {
47
        return 'NATIVE';
48
    }
49
}
50