RedpackGateway   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pay() 0 25 3
A getTradeType() 0 4 1
1
<?php
2
3
namespace Yansongda\Pay\Gateways\Wechat;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Yansongda\Pay\Events;
7
use Yansongda\Pay\Exceptions\GatewayException;
8
use Yansongda\Pay\Exceptions\InvalidArgumentException;
9
use Yansongda\Pay\Exceptions\InvalidSignException;
10
use Yansongda\Pay\Gateways\Wechat;
11
use Yansongda\Supports\Collection;
12
13
class RedpackGateway extends Gateway
14
{
15
    /**
16
     * Pay an order.
17
     *
18
     * @author yansongda <[email protected]>
19
     *
20
     * @param string $endpoint
21
     * @param array  $payload
22
     *
23
     * @throws GatewayException
24
     * @throws InvalidArgumentException
25
     * @throws InvalidSignException
26
     *
27
     * @return Collection
28
     */
29
    public function pay($endpoint, array $payload): Collection
30
    {
31
        $payload['wxappid'] = $payload['appid'];
32
33
        if ('cli' !== php_sapi_name()) {
34
            $payload['client_ip'] = Request::createFromGlobals()->server->get('SERVER_ADDR');
35
        }
36
37
        if (Wechat::MODE_SERVICE === $this->mode) {
38
            $payload['msgappid'] = $payload['appid'];
39
        }
40
41
        unset($payload['appid'], $payload['trade_type'],
42
              $payload['notify_url'], $payload['spbill_create_ip']);
43
44
        $payload['sign'] = Support::generateSign($payload);
45
46
        Events::dispatch(new Events\PayStarted('Wechat', 'Redpack', $endpoint, $payload));
47
48
        return Support::requestApi(
49
            'mmpaymkttransfers/sendredpack',
50
            $payload,
51
            true
52
        );
53
    }
54
55
    /**
56
     * Get trade type config.
57
     *
58
     * @author yansongda <[email protected]>
59
     *
60
     * @return string
61
     */
62
    protected function getTradeType(): string
63
    {
64
        return '';
65
    }
66
}
67