Completed
Push — master ( bbcd34...fabc9b )
by i
03:49
created

PubPayment   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPay() 0 17 1
1
<?php
2
3
namespace Nilnice\Payment\Wechat;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Str;
7
use Nilnice\Payment\Constant;
8
use Nilnice\Payment\Log;
9
10
class PubPayment extends AbstractWechat
11
{
12
    /**
13
     * Use pub 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
     */
25
    public function toPay(string $gateway, array $payload) : Collection
26
    {
27
        $payload['trade_type'] = Constant::WX_PAY_PUB_TYPE;
28
        $key = $this->config->get('key');
29
        $object = $this->prepare(Constant::WX_PAY_PREPARE, $payload);
30
        $parameter = [
31
            'appId'     => $payload['appid'],
32
            'timeStamp' => (string)time(),
33
            'nonceStr'  => Str::random(),
34
            'package'   => 'prepay_id=' . $object->get('prepay_id'),
35
            'signType'  => 'MD5',
36
        ];
37
        $parameter['paySign'] = self::generateSign($parameter, $key);
38
39
        Log::debug('Pub order:', [$gateway, $payload, $parameter]);
40
41
        return new Collection($parameter);
42
    }
43
}
44