AppPayment   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPay() 0 18 1
1
<?php
2
3
namespace Nilnice\Payment\Wechat;
4
5
use Illuminate\Support\Str;
6
use Nilnice\Payment\Constant;
7
use Nilnice\Payment\Log;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class AppPayment extends AbstractWechat
12
{
13
    /**
14
     * Use app to pay for order.
15
     *
16
     * @param string $gateway
17
     * @param array  $payload
18
     *
19
     * @return \Symfony\Component\HttpFoundation\Response
20
     *
21
     * @throws \InvalidArgumentException
22
     * @throws \Nilnice\Payment\Exception\GatewayException
23
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
24
     * @throws \Nilnice\Payment\Exception\InvalidSignException
25
     */
26
    public function toPay(string $gateway, array $payload) : Response
27
    {
28
        $payload['trade_type'] = Constant::WX_PAY_APP_TYPE;
29
        $object = $this->prepare(Constant::WX_PAY_PREPARE, $payload);
30
        $key = $this->config->get('app_key');
31
        $parameter = [
32
            'appid'     => $payload['appid'],
33
            'partnerid' => $payload['mch_id'],
34
            'prepayid'  => $object->get('prepay_id'),
35
            'timestamp' => (string)time(),
36
            'noncestr'  => Str::random(),
37
            'package'   => 'Sign=WXPay',
38
        ];
39
        $parameter['sign'] = self::generateSign($parameter, $key);
40
41
        Log::debug('App order:', [$gateway, $payload]);
42
43
        return JsonResponse::create($parameter);
44
    }
45
}
46