Completed
Push — master ( c25059...aa3601 )
by i
04:27
created

AbstractWechat::getClientIp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nilnice\Payment\Wechat;
4
5
use Illuminate\Config\Repository;
6
use Illuminate\Support\Collection;
7
use Nilnice\Payment\PaymentInterface;
8
use Nilnice\Payment\Wechat\Traits\RequestTrait;
9
use Nilnice\Payment\Wechat\Traits\SecurityTrait;
10
use Symfony\Component\HttpFoundation\Request;
11
12
abstract class AbstractWechat implements PaymentInterface
13
{
14
    use SecurityTrait;
15
    use RequestTrait;
16
17
    /**
18
     * @var \Illuminate\Config\Repository
19
     */
20
    protected $config;
21
22
    /**
23
     * AbstractWechat constructor.
24
     *
25
     * @param \Illuminate\Config\Repository $config
26
     */
27 3
    public function __construct(Repository $config)
28
    {
29 3
        $this->config = $config;
30 3
    }
31
32
    /**
33
     * @return mixed
34
     */
35
    public function getClientIp()
36
    {
37
        return Request::createFromGlobals()->server->get('SERVER_ADDR');
38
    }
39
40
    /**
41
     * Pregenerating order.
42
     *
43
     * @param string $gateway
44
     * @param array  $payload
45
     *
46
     * @return \Illuminate\Support\Collection
47
     *
48
     * @throws \Nilnice\Payment\Exception\GatewayException
49
     * @throws \InvalidArgumentException
50
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
51
     * @throws \Nilnice\Payment\Exception\InvalidSignException
52
     * @throws \RuntimeException
53
     */
54 3
    protected function prepare(string $gateway, array $payload) : Collection
55
    {
56 3
        $key = $this->config->get('key');
57 3
        $payload['sign'] = self::generateSign($payload, $key);
58
59
        return $this->send($gateway, $payload, $key);
60
    }
61
}
62