WebPayment   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPay() 0 17 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 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
     *
23
     * @throws \InvalidArgumentException
24
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
25
     */
26 3
    public function toPay(string $gateway, array $payload) : Response
27
    {
28 3
        $key = $this->config->get('private_key');
29 3
        $content = array_merge(
30 3
            Arr::get($payload, 'biz_content'),
31 3
            Constant::ALI_PAY_WEB_PRO_CODE
32
        );
33 3
        self::check($content);
34 3
        $payload['method'] = Constant::ALI_PAY_WEB_PAY;
35 3
        $payload['biz_content'] = json_encode($content);
36 3
        $payload['sign'] = self::generateSign($payload, $key);
37
38
        Log::debug('Web order:', [$gateway, $payload]);
39
40
        $body = $this->buildRequestForm($gateway, $payload);
41
42
        return Response::create($body);
43
    }
44
}
45