TransferPayment   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B toPay() 0 28 3
1
<?php
2
3
namespace Nilnice\Payment\Wechat;
4
5
use Illuminate\Support\Collection;
6
use Nilnice\Payment\Constant;
7
use Nilnice\Payment\Log;
8
9
class TransferPayment extends AbstractWechat
10
{
11
    /**
12
     * Use transfer to pay for order.
13
     *
14
     * @param string $gateway
15
     * @param array  $payload
16
     *
17
     * @return \Illuminate\Support\Collection
18
     *
19
     * @throws \InvalidArgumentException
20
     * @throws \Nilnice\Payment\Exception\GatewayException
21
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
22
     * @throws \Nilnice\Payment\Exception\InvalidSignException
23
     */
24
    public function toPay(string $gateway, array $payload) : Collection
25
    {
26
        if (isset($payload['type'])) {
27
            $type = $payload['type'] . ($payload['type'] === 'app' ?: '_')
0 ignored issues
show
Bug introduced by
Are you sure $payload['type'] === 'app' ?: '_' of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            $type = $payload['type'] . (/** @scrutinizer ignore-type */ $payload['type'] === 'app' ?: '_')
Loading history...
28
                . 'id';
29
        } else {
30
            $type = 'app_id';
31
        }
32
        $payload['mch_appid'] = $this->config->get($type, '');
33
        $payload['mchid'] = $payload['mch_id'];
34
        $payload['spbill_create_ip'] = $this->getClientIp();
35
36
        unset(
37
            $payload['appid'],
38
            $payload['mch_id'],
39
            $payload['trade_type'],
40
            $payload['notify_url'],
41
            $payload['type']
42
        );
43
        $gateway .= Constant::WX_PAY_TRANSFER;
44
        $key = $this->config->get('key');
45
        $certClient = $this->config->get('cert_client');
46
        $certKey = $this->config->get('cert_key');
47
        $payload['sign'] = self::generateSign($payload, $key);
48
49
        Log::debug('Transfer order:', [$gateway, $payload]);
50
51
        return $this->send($gateway, $payload, $key, $certClient, $certKey);
52
    }
53
}
54