Completed
Push — master ( fe0998...b200bd )
by i
09:50
created

WebPayment   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPay() 0 14 1
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 Symfony\Component\HttpFoundation\Response;
9
10
class WebPayment extends AbstractAlipay
11
{
12
    use FormTrait;
13
14
    /**
15
     * Use web to pay for order.
16
     *
17
     * @param string $gateway
18
     * @param array  $payload
19
     *
20
     * @return \Symfony\Component\HttpFoundation\Response
21
     * @throws \InvalidArgumentException
22
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
23
     */
24 3
    public function toPay(string $gateway, array $payload) : Response
25
    {
26 3
        $key = $this->config->get('private_key');
27 3
        $content = array_merge(
28 3
            Arr::get($payload, 'biz_content'),
29 3
            Constant::ALI_PAY_WEB_PRO_CODE
30
        );
31 3
        self::check($content);
32 3
        $payload['method'] = Constant::ALI_PAY_WEB_PAY;
33 3
        $payload['biz_content'] = json_encode($content);
34 3
        $payload['sign'] = self::generateSign($payload, $key);
35
        $body = $this->buildRequestForm($gateway, $payload);
36
37
        return Response::create($body);
38
    }
39
}
40