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

BarPayment   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPay() 0 13 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
9
class BarPayment extends AbstractAlipay
10
{
11
    /**
12
     * Use bar code to pay for order.
13
     *
14
     * @param string $gateway
15
     * @param array  $payload
16
     *
17
     * @return \Illuminate\Support\Collection
18
     * @throws \Nilnice\Payment\Exception\GatewayException
19
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
20
     * @throws \Nilnice\Payment\Exception\InvalidSignException
21
     * @throws \InvalidArgumentException
22
     * @throws \RuntimeException
23
     */
24
    public function toPay(string $gateway, array $payload) : Collection
25
    {
26
        $key = $this->config->get('private_key');
27
        $content = array_merge(
28
            Arr::get($payload, 'biz_content'),
29
            Constant::ALI_PAY_BAR_PRO_CODE
30
        );
31
        self::check($content);
32
        $payload['method'] = Constant::ALI_PAY_BAR_PAY;
33
        $payload['biz_content'] = json_encode($content);
34
        $payload['sign'] = self::generateSign($payload, $key);
35
36
        return $this->send($payload, $this->config->get('public_key'));
37
    }
38
}
39