WapPayment::toPay()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 0
loc 17
ccs 0
cts 14
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nilnice\Payment\Alipay;
4
5
use Illuminate\Support\Arr;
6
use Nilnice\Payment\Alipay\Traits\FormTrait;
7
use Nilnice\Payment\Constant;
8
use Nilnice\Payment\Log;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class WapPayment extends AbstractAlipay
12
{
13
    use FormTrait;
14
15
    /**
16
     * Use wap to pay for order.
17
     *
18
     * @param string $gateway
19
     * @param array  $payload
20
     *
21
     * @return \Symfony\Component\HttpFoundation\Response
22
     *
23
     * @throws \InvalidArgumentException
24
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
25
     */
26
    public function toPay(string $gateway, array $payload) : Response
27
    {
28
        $key = $this->config->get('private_key');
29
        $content = array_merge(
30
            Arr::get($payload, 'biz_content'),
31
            Constant::ALI_PAY_WAP_PRO_CODE
32
        );
33
        self::check($content);
34
        $payload['method'] = Constant::ALI_PAY_WAP_PAY;
35
        $payload['biz_content'] = json_encode($content);
36
        $payload['sign'] = self::generateSign($payload, $key);
37
38
        Log::debug('Wap order:', [$gateway, $payload]);
39
40
        $body = $this->buildRequestForm($gateway, $payload);
41
42
        return Response::create($body);
43
    }
44
}
45