WapGateway   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pay() 0 13 2
A getTradeType() 0 4 1
1
<?php
2
3
namespace Yansongda\Pay\Gateways\Wechat;
4
5
use Symfony\Component\HttpFoundation\RedirectResponse;
6
use Yansongda\Pay\Events;
7
use Yansongda\Pay\Exceptions\GatewayException;
8
use Yansongda\Pay\Exceptions\InvalidArgumentException;
9
use Yansongda\Pay\Exceptions\InvalidSignException;
10
11
class WapGateway extends Gateway
12
{
13
    /**
14
     * Pay an order.
15
     *
16
     * @author yansongda <[email protected]>
17
     *
18
     * @param string $endpoint
19
     * @param array  $payload
20
     *
21
     * @throws GatewayException
22
     * @throws InvalidArgumentException
23
     * @throws InvalidSignException
24
     *
25
     * @return RedirectResponse
26
     */
27
    public function pay($endpoint, array $payload): RedirectResponse
28
    {
29
        $payload['trade_type'] = $this->getTradeType();
30
31
        Events::dispatch(new Events\PayStarted('Wechat', 'Wap', $endpoint, $payload));
32
33
        $mweb_url = $this->preOrder($payload)->get('mweb_url');
34
35
        $url = is_null(Support::getInstance()->return_url) ? $mweb_url : $mweb_url.
36
                        '&redirect_url='.urlencode(Support::getInstance()->return_url);
37
38
        return RedirectResponse::create($url);
39
    }
40
41
    /**
42
     * Get trade type config.
43
     *
44
     * @author yansongda <[email protected]>
45
     *
46
     * @return string
47
     */
48
    protected function getTradeType(): string
49
    {
50
        return 'MWEB';
51
    }
52
}
53