AppPayment::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\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