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

AppPayment   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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