WapPayment::toPay()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1852

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 14
ccs 3
cts 9
cp 0.3333
crap 3.1852
rs 9.4285
c 0
b 0
f 0
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