Issues (83)

src/Payment/Order/Client.php (2 issues)

Labels
Severity
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\Payment\Order;
13
14
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
15
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
16
use EasyWeChat\Kernel\Support;
17
use EasyWeChat\Kernel\Support\Collection;
18
use EasyWeChat\Payment\Kernel\BaseClient;
19
use Psr\Http\Message\ResponseInterface;
20
21
class Client extends BaseClient
22
{
23
    /**
24
     * Unify order.
25
     *
26
     * @param array $params
27
     * @param bool  $isContract
28
     *
29
     * @return ResponseInterface|Collection|array|object|string
30
     *
31
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
32
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
33
     * @throws \GuzzleHttp\Exception\GuzzleException
34
     */
35 2
    public function unify(array $params, $isContract = false)
36
    {
37 2
        if (empty($params['spbill_create_ip'])) {
38 2
            $params['spbill_create_ip'] = ('NATIVE' === $params['trade_type']) ? Support\get_server_ip() : Support\get_client_ip();
0 ignored issues
show
The function get_server_ip was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

38
            $params['spbill_create_ip'] = ('NATIVE' === $params['trade_type']) ? /** @scrutinizer ignore-call */ Support\get_server_ip() : Support\get_client_ip();
Loading history...
The function get_client_ip was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

38
            $params['spbill_create_ip'] = ('NATIVE' === $params['trade_type']) ? Support\get_server_ip() : /** @scrutinizer ignore-call */ Support\get_client_ip();
Loading history...
39
        }
40
41 2
        $params['appid'] = $this->app['config']->app_id;
42 2
        $params['notify_url'] = $params['notify_url'] ?? $this->app['config']['notify_url'];
43
44 2
        if ($isContract) {
45 1
            $params['contract_appid'] = $this->app['config']['app_id'];
46 1
            $params['contract_mchid'] = $this->app['config']['mch_id'];
47 1
            $params['request_serial'] = $params['request_serial'] ?? time();
48 1
            $params['contract_notify_url'] = $params['contract_notify_url'] ?? $this->app['config']['contract_notify_url'];
49
50 1
            return $this->request($this->wrap('pay/contractorder'), $params);
51
        }
52
53 1
        return $this->request($this->wrap('pay/unifiedorder'), $params);
54
    }
55
56
    /**
57
     * Query order by out trade number.
58
     *
59
     * @param string $number
60
     *
61
     * @return ResponseInterface|Collection|array|object|string
62
     *
63
     * @throws InvalidArgumentException
64
     * @throws InvalidConfigException
65
     */
66 1
    public function queryByOutTradeNumber(string $number)
67
    {
68 1
        return $this->query([
69 1
            'out_trade_no' => $number,
70
        ]);
71
    }
72
73
    /**
74
     * Query order by transaction id.
75
     *
76
     * @param string $transactionId
77
     *
78
     * @return ResponseInterface|Collection|array|object|string
79
     *
80
     * @throws InvalidArgumentException
81
     * @throws InvalidConfigException
82
     */
83 1
    public function queryByTransactionId(string $transactionId)
84
    {
85 1
        return $this->query([
86 1
            'transaction_id' => $transactionId,
87
        ]);
88
    }
89
90
    /**
91
     * @param array $params
92
     *
93
     * @return ResponseInterface|Collection|array|object|string
94
     *
95
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
96
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
97
     * @throws \GuzzleHttp\Exception\GuzzleException
98
     */
99 2
    protected function query(array $params)
100
    {
101 2
        $params['appid'] = $this->app['config']->app_id;
102
103 2
        return $this->request($this->wrap('pay/orderquery'), $params);
104
    }
105
106
    /**
107
     * Close order by out_trade_no.
108
     *
109
     * @param string $tradeNo
110
     *
111
     * @return ResponseInterface|Collection|array|object|string
112
     *
113
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
114
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
115
     * @throws \GuzzleHttp\Exception\GuzzleException
116
     */
117 1
    public function close(string $tradeNo)
118
    {
119
        $params = [
120 1
            'appid' => $this->app['config']->app_id,
121 1
            'out_trade_no' => $tradeNo,
122
        ];
123
124 1
        return $this->request($this->wrap('pay/closeorder'), $params);
125
    }
126
}
127