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

ScanPayment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
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
8
class ScanPayment extends AbstractAlipay
9
{
10
    /**
11
     * Use scan code to pay for order.
12
     *
13
     * @param string $gateway
14
     * @param array  $payload
15
     *
16
     * @return mixed|void
17
     * @throws \InvalidArgumentException
18
     * @throws \Nilnice\Payment\Exception\GatewayException
19
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
20
     * @throws \Nilnice\Payment\Exception\InvalidSignException
21
     * @throws \RuntimeException
22
     */
23
    public function toPay(string $gateway, array $payload)
24
    {
25
        $key = $this->config->get('private_key');
26
        $content = array_merge(
27
            Arr::get($payload, 'biz_content'),
28
            Constant::ALI_PAY_SCAN_PRO_CODE
29
        );
30
        self::check($content);
31
        $payload['method'] = Constant::ALI_PAY_SCAN_PAY;
32
        $payload['biz_content'] = json_encode($content);
33
        $payload['sign'] = self::generateSign($payload, $key);
34
35
        return $this->send($payload, $this->config->get('public_key'));
36
    }
37
}
38