ScanPayment   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 31
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 15 1
1
<?php
2
3
namespace Nilnice\Payment\Alipay;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Collection;
7
use Nilnice\Payment\Constant;
8
use Nilnice\Payment\Log;
9
10
class ScanPayment extends AbstractAlipay
11
{
12
    /**
13
     * Use scan code to pay for order.
14
     *
15
     * @param string $gateway
16
     * @param array  $payload
17
     *
18
     * @return \Illuminate\Support\Collection
19
     *
20
     * @throws \InvalidArgumentException
21
     * @throws \Nilnice\Payment\Exception\GatewayException
22
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
23
     * @throws \Nilnice\Payment\Exception\InvalidSignException
24
     * @throws \RuntimeException
25
     */
26
    public function toPay(string $gateway, array $payload) : Collection
27
    {
28
        $key = $this->config->get('private_key');
29
        $content = array_merge(
30
            Arr::get($payload, 'biz_content'),
31
            Constant::ALI_PAY_SCAN_PRO_CODE
32
        );
33
        self::check($content);
34
        $payload['method'] = Constant::ALI_PAY_SCAN_PAY;
35
        $payload['biz_content'] = json_encode($content);
36
        $payload['sign'] = self::generateSign($payload, $key);
37
38
        Log::debug('Scan order:', [$gateway, $payload]);
39
40
        return $this->send($payload, $this->config->get('public_key'));
41
    }
42
}
43