BarPayment::toPay()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 2
dl 0
loc 15
ccs 0
cts 13
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 Illuminate\Support\Collection;
7
use Nilnice\Payment\Constant;
8
use Nilnice\Payment\Log;
9
10
class BarPayment extends AbstractAlipay
11
{
12
    /**
13
     * Use bar code to pay for order.
14
     *
15
     * @param string $gateway
16
     * @param array  $payload
17
     *
18
     * @return \Illuminate\Support\Collection
19
     *
20
     * @throws \Nilnice\Payment\Exception\GatewayException
21
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
22
     * @throws \Nilnice\Payment\Exception\InvalidSignException
23
     * @throws \InvalidArgumentException
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_BAR_PRO_CODE
32
        );
33
        self::check($content);
34
        $payload['method'] = Constant::ALI_PAY_BAR_PAY;
35
        $payload['biz_content'] = json_encode($content);
36
        $payload['sign'] = self::generateSign($payload, $key);
37
38
        Log::debug('Bar order:', [$gateway, $payload]);
39
40
        return $this->send($payload, $this->config->get('public_key'));
41
    }
42
}
43