Completed
Push — master ( c25059...aa3601 )
by i
04:27
created

WapPayment   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 3
cts 9
cp 0.3333
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPay() 0 14 2
1
<?php
2
3
namespace Nilnice\Payment\Wechat;
4
5
use Nilnice\Payment\Constant;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class WapPayment extends AbstractWechat
10
{
11
    /**
12
     * Use wap(H5) to pay for order.
13
     *
14
     * @param string $gateway
15
     * @param array  $payload
16
     *
17
     * @return \Symfony\Component\HttpFoundation\Response
18
     *
19
     * @throws \InvalidArgumentException
20
     * @throws \Nilnice\Payment\Exception\GatewayException
21
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
22
     * @throws \Nilnice\Payment\Exception\InvalidSignException
23
     * @throws \RuntimeException
24
     */
25 3
    public function toPay(string $gateway, array $payload) : Response
26
    {
27 3
        $payload['trade_type'] = Constant::WX_PAY_WAP_TYPE;
28 3
        $object = $this->prepare(Constant::WX_PAY_PREPARE, $payload);
29
        $returnUrl = $this->config->get('return_url');
30
        $mwebUrl = $object->get('mweb_url');
31
32
        if (null === $returnUrl) {
33
            $url = $mwebUrl;
34
        } else {
35
            $url = $mwebUrl . '&redirect_url=' . urlencode($returnUrl);
36
        }
37
38
        return RedirectResponse::create($url);
39
    }
40
}
41