Client   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 259
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 80
c 1
b 0
f 0
dl 0
loc 259
ccs 91
cts 91
cp 1
rs 10
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 1
A pay() 0 13 1
A query() 0 12 1
A close() 0 16 1
A cancel() 0 11 1
A refund() 0 12 1
A preCreate() 0 9 1
A orderSettle() 0 19 2
A orderInfoSync() 0 17 2
1
<?php
2
/*
3
 * This file is part of the wannanbigpig/alipay-sdk-php.
4
 *
5
 * (c) wannanbigpig <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace EasyAlipay\Payment\Base;
12
13
use EasyAlipay\Payment\Kernel\BaseClient;
14
15
/**
16
 * Class Client
17
 *
18
 * @author   liuml  <[email protected]>
19
 * @DateTime 2019-07-24  14:24
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * alipay.trade.pay(统一收单交易支付接口).
25
     *
26
     * @param array $params
27
     *
28
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
29
     *
30
     * @throws \GuzzleHttp\Exception\GuzzleException
31
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
32
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
33
     */
34 2
    public function pay(array $params)
35
    {
36 2
        $method = 'alipay.trade.pay';
37 2
        $params = array_merge([
38 2
            'scene' => 'bar_code',
39
            'product_code' => 'FACE_TO_FACE_PAYMENT',
40 2
        ], $params);
41 2
        $this->app->setEndpointConfig($method, [
42 2
            'notify_url' => $this->app['config']->get('notify_url'),
43
        ]);
44
45 2
        return $this->request($method, [
46 2
            'biz_content' => $params,
47
        ]);
48
    }
49
50
    /**
51
     * alipay.trade.create(统一收单交易创建接口).
52
     *
53
     * @param array $params
54
     *
55
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
56
     *
57
     * @throws \GuzzleHttp\Exception\GuzzleException
58
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
59
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
60
     */
61 2
    public function create(array $params)
62
    {
63 2
        $method = 'alipay.trade.create';
64 2
        $this->app->setEndpointConfig($method, [
65 2
            'notify_url' => $this->app['config']->get('notify_url'),
66
        ]);
67
68 2
        return $this->request($method, [
69 2
            'biz_content' => $params,
70
        ]);
71
    }
72
73
    /**
74
     * alipay.trade.precreate(统一收单线下交易预创建).
75
     *
76
     * @param array $params
77
     *
78
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
79
     *
80
     * @throws \GuzzleHttp\Exception\GuzzleException
81
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
82
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
83
     */
84 2
    public function preCreate(array $params)
85
    {
86 2
        $method = 'alipay.trade.precreate';
87 2
        $this->app->setEndpointConfig($method, [
88 2
            'notify_url' => $this->app['config']->get('notify_url'),
89
        ]);
90
91 2
        return $this->request($method, [
92 2
            'biz_content' => $params,
93
        ]);
94
    }
95
96
97
    /**
98
     * alipay.trade.close(统一收单交易关闭接口).
99
     *
100
     * @param string      $outTradeNo
101
     * @param string|null $tradeNo
102
     * @param string|null $operatorId
103
     *
104
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
105
     *
106
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
107
     * @throws \GuzzleHttp\Exception\GuzzleException
108
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
109
     */
110 2
    public function close(string $outTradeNo, string $tradeNo = null, string $operatorId = null)
111
    {
112 2
        $method = 'alipay.trade.close';
113 2
        $params = array_filter([
114 2
            'trade_no' => $tradeNo,
115 2
            'out_trade_no' => $outTradeNo,
116 2
            'operator_id' => $operatorId,
117 2
        ], function ($value) {
118 2
            return !($this->checkEmpty($value));
119 2
        });
120 2
        $this->app->setEndpointConfig($method, [
121 2
            'notify_url' => $this->app['config']->get('notify_url'),
122
        ]);
123
124 2
        return $this->request($method, [
125 2
            'biz_content' => $params,
126
        ]);
127
    }
128
129
    /**
130
     * alipay.trade.refund(统一收单交易退款接口).
131
     *
132
     * @param string           $tradeNo
133
     * @param float|int|string $amount
134
     * @param string|null      $outTradeNo
135
     * @param array            $params
136
     *
137
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
138
     *
139
     * @throws \GuzzleHttp\Exception\GuzzleException
140
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
141
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
142
     */
143 2
    public function refund(string $tradeNo, $amount, string $outTradeNo = null, array $params = [])
144
    {
145 2
        $params = array_merge(array_filter([
146 2
            'trade_no' => $tradeNo,
147 2
            'out_trade_no' => $outTradeNo,
148 2
            'refund_amount' => $amount,
149 2
        ], function ($value) {
150 2
            return !($this->checkEmpty($value));
151 2
        }), $params);
152
153 2
        return $this->request('alipay.trade.refund', [
154 2
            'biz_content' => $params,
155
        ]);
156
    }
157
158
    /**
159
     * alipay.trade.query(统一收单线下交易查询).
160
     *
161
     * @param string      $outTradeNo
162
     * @param string|null $tradeNo
163
     * @param string|null $orgPid
164
     *
165
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
166
     *
167
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
168
     * @throws \GuzzleHttp\Exception\GuzzleException
169
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
170
     */
171 2
    public function query(string $outTradeNo, string $tradeNo = null, string $orgPid = null)
172
    {
173 2
        $params = array_filter([
174 2
            'trade_no' => $tradeNo,
175 2
            'out_trade_no' => $outTradeNo,
176 2
            'org_pid' => $orgPid,
177 2
        ], function ($value) {
178 2
            return !($this->checkEmpty($value));
179 2
        });
180
181 2
        return $this->request('alipay.trade.query', [
182 2
            'biz_content' => $params,
183
        ]);
184
    }
185
186
    /**
187
     * alipay.trade.cancel(统一收单交易撤销接口).
188
     *
189
     * @param string      $outTradeNo
190
     * @param string|null $tradeNo
191
     *
192
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
193
     *
194
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
195
     * @throws \GuzzleHttp\Exception\GuzzleException
196
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
197
     */
198 2
    public function cancel(string $outTradeNo, string $tradeNo = null)
199
    {
200 2
        $params = array_filter([
201 2
            'trade_no' => $tradeNo,
202 2
            'out_trade_no' => $outTradeNo,
203 2
        ], function ($value) {
204 2
            return !($this->checkEmpty($value));
205 2
        });
206
207 2
        return $this->request('alipay.trade.cancel', [
208 2
            'biz_content' => $params,
209
        ]);
210
    }
211
212
    /**
213
     * alipay.trade.order.settle(统一收单交易结算接口).
214
     *
215
     * @param string      $outRequestNo
216
     * @param string      $tradeNo
217
     * @param array       $royaltyParameters
218
     * @param string|null $operatorId
219
     *
220
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
221
     *
222
     * @throws \GuzzleHttp\Exception\GuzzleException
223
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
224
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
225
     */
226 2
    public function orderSettle(string $outRequestNo, string $tradeNo, array $royaltyParameters, string $operatorId = null)
227
    {
228 2
        $royalty = [];
229 2
        if (count($royaltyParameters) === count($royaltyParameters, COUNT_RECURSIVE)) {
230 2
            $royalty[0] = $royaltyParameters;
231
        } else {
232 2
            $royalty = $royaltyParameters;
233
        }
234 2
        $params = array_filter([
235 2
            'out_request_no' => $outRequestNo,
236 2
            'trade_no' => $tradeNo,
237 2
            'royalty_parameters' => $royalty,
238 2
            'operator_id' => $operatorId,
239 2
        ], function ($value) {
240 2
            return !($this->checkEmpty($value));
241 2
        });
242
243 2
        return $this->request('alipay.trade.order.settle', [
244 2
            'biz_content' => $params,
245
        ]);
246
    }
247
248
    /**
249
     * alipay.trade.orderinfo.sync(支付宝订单信息同步接口).
250
     *
251
     * @param string      $tradeNo
252
     * @param string      $outRequestNo
253
     * @param string      $bizType
254
     * @param string|null $origRequestNo
255
     * @param string|null $orderBizInfo
256
     *
257
     * @return array|object|\Psr\Http\Message\ResponseInterface|\WannanBigPig\Supports\Collection|\WannanBigPig\Supports\Http\Response
258
     *
259
     * @throws \GuzzleHttp\Exception\GuzzleException
260
     * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
261
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
262
     */
263 2
    public function orderInfoSync(string $tradeNo, string $outRequestNo, string $bizType, string $origRequestNo = null, string $orderBizInfo = null)
264
    {
265 2
        $params = array_filter([
266 2
            'trade_no' => $tradeNo,
267 2
            'out_request_no' => $outRequestNo,
268 2
            'orig_request_no' => $origRequestNo,
269 2
            'biz_type' => $bizType,
270 2
        ], function ($value) {
271 2
            return !($this->checkEmpty($value));
272 2
        });
273
274 2
        if (!($this->checkEmpty($orderBizInfo))) {
275 2
            $params['order_biz_info'] = json_encode(['status' => $orderBizInfo]);
276
        }
277
278 2
        return $this->request('alipay.trade.orderinfo.sync', [
279 2
            'biz_content' => $params,
280
        ]);
281
    }
282
}
283