TransferPayment   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 12
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 Illuminate\Support\Collection;
7
use Nilnice\Payment\Alipay\Traits\RequestTrait;
8
use Nilnice\Payment\Constant;
9
use Nilnice\Payment\Log;
10
11
class TransferPayment extends AbstractAlipay
12
{
13
    use RequestTrait;
14
15
    /**
16
     * Use transfer to pay for order.
17
     *
18
     * @param string $gateway
19
     * @param array  $payload
20
     *
21
     * @return \Illuminate\Support\Collection
22
     *
23
     * @throws \Nilnice\Payment\Exception\GatewayException
24
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
25
     * @throws \Nilnice\Payment\Exception\InvalidSignException
26
     * @throws \RuntimeException
27
     */
28
    public function toPay(string $gateway, array $payload) : Collection
29
    {
30
        $key = $this->config->get('private_key');
31
        $content = array_merge(
32
            Arr::get($payload, 'biz_content'),
33
            Constant::ALI_PAY_TRANSFER_PRO_CODE
34
        );
35
        $payload['method'] = Constant::ALI_PAY_TRANSFER;
36
        $payload['biz_content'] = json_encode($content);
37
        $payload['sign'] = self::generateSign($payload, $key);
38
39
        Log::debug('Transfer order:', [$gateway, $payload]);
40
41
        return $this->send($payload, $this->config->get('public_key'));
42
    }
43
}
44