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

WapPayment::toPay()   A

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
     * @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