Completed
Push — master ( d3395c...6ce6f6 )
by i
03:50
created

WebPayment::toPay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1.0156

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 0
loc 17
ccs 9
cts 12
cp 0.75
crap 1.0156
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 WebPayment extends AbstractAlipay
12
{
13
    use FormTrait;
14
15
    /**
16
     * Use web to pay for order.
17
     *
18
     * @param string $gateway
19
     * @param array  $payload
20
     *
21
     * @return \Symfony\Component\HttpFoundation\Response
22
     * @throws \InvalidArgumentException
23
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
24
     */
25 3
    public function toPay(string $gateway, array $payload) : Response
26
    {
27 3
        $key = $this->config->get('private_key');
28 3
        $content = array_merge(
29 3
            Arr::get($payload, 'biz_content'),
30 3
            Constant::ALI_PAY_WEB_PRO_CODE
31
        );
32 3
        self::check($content);
33 3
        $payload['method'] = Constant::ALI_PAY_WEB_PAY;
34 3
        $payload['biz_content'] = json_encode($content);
35 3
        $payload['sign'] = self::generateSign($payload, $key);
36
37
        Log::debug('Web order:', [$gateway, $payload]);
38
39
        $body = $this->buildRequestForm($gateway, $payload);
40
41
        return Response::create($body);
42
    }
43
}
44