AppPayment   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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