WapPayment   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
dl 0
loc 29
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
     */
24 3
    public function toPay(string $gateway, array $payload) : Response
25
    {
26 3
        $payload['trade_type'] = Constant::WX_PAY_WAP_TYPE;
27 3
        $object = $this->prepare(Constant::WX_PAY_PREPARE, $payload);
28
        $returnUrl = $this->config->get('return_url');
29
        $mwebUrl = $object->get('mweb_url');
30
31
        if (null === $returnUrl) {
32
            $url = $mwebUrl;
33
        } else {
34
            $url = $mwebUrl . '&redirect_url=' . urlencode($returnUrl);
35
        }
36
37
        return RedirectResponse::create($url);
38
    }
39
}
40