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\Refund; |
13
|
|
|
|
14
|
|
|
use EasyWeChat\Payment\Kernel\BaseClient; |
15
|
|
|
|
16
|
|
|
class Client extends BaseClient |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Refund by out trade number. |
20
|
|
|
* |
21
|
|
|
* @param string $number |
22
|
|
|
* @param string $refundNumber |
23
|
|
|
* @param int $totalFee |
24
|
|
|
* @param int $refundFee |
25
|
|
|
* @param array $optional |
26
|
|
|
* |
27
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
28
|
|
|
* |
29
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
30
|
|
|
*/ |
31
|
1 |
|
public function byOutTradeNumber(string $number, string $refundNumber, int $totalFee, int $refundFee, array $optional = []) |
32
|
|
|
{ |
33
|
1 |
|
return $this->refund($refundNumber, $totalFee, $refundFee, array_merge($optional, ['out_trade_no' => $number])); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Refund by transaction id. |
38
|
|
|
* |
39
|
|
|
* @param string $transactionId |
40
|
|
|
* @param string $refundNumber |
41
|
|
|
* @param int $totalFee |
42
|
|
|
* @param int $refundFee |
43
|
|
|
* @param array $optional |
44
|
|
|
* |
45
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
46
|
|
|
* |
47
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
48
|
|
|
*/ |
49
|
1 |
|
public function byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $optional = []) |
50
|
|
|
{ |
51
|
1 |
|
return $this->refund($refundNumber, $totalFee, $refundFee, array_merge($optional, ['transaction_id' => $transactionId])); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Query refund by transaction id. |
56
|
|
|
* |
57
|
|
|
* @param string $transactionId |
58
|
|
|
* |
59
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
60
|
|
|
* |
61
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
62
|
|
|
*/ |
63
|
1 |
|
public function queryByTransactionId(string $transactionId) |
64
|
|
|
{ |
65
|
1 |
|
return $this->query($transactionId, 'transaction_id'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Query refund by out trade number. |
70
|
|
|
* |
71
|
|
|
* @param string $outTradeNumber |
72
|
|
|
* |
73
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
74
|
|
|
* |
75
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
76
|
|
|
*/ |
77
|
1 |
|
public function queryByOutTradeNumber(string $outTradeNumber) |
78
|
|
|
{ |
79
|
1 |
|
return $this->query($outTradeNumber, 'out_trade_no'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Query refund by out refund number. |
84
|
|
|
* |
85
|
|
|
* @param string $outRefundNumber |
86
|
|
|
* |
87
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
88
|
|
|
* |
89
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
90
|
|
|
*/ |
91
|
1 |
|
public function queryByOutRefundNumber(string $outRefundNumber) |
92
|
|
|
{ |
93
|
1 |
|
return $this->query($outRefundNumber, 'out_refund_no'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Query refund by refund id. |
98
|
|
|
* |
99
|
|
|
* @param string $refundId |
100
|
|
|
* |
101
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
102
|
|
|
* |
103
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
104
|
|
|
*/ |
105
|
1 |
|
public function queryByRefundId(string $refundId) |
106
|
|
|
{ |
107
|
1 |
|
return $this->query($refundId, 'refund_id'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Refund. |
112
|
|
|
* |
113
|
|
|
* @param string $refundNumber |
114
|
|
|
* @param int $totalFee |
115
|
|
|
* @param int $refundFee |
116
|
|
|
* @param array $optional |
117
|
|
|
* |
118
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
119
|
|
|
* |
120
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
121
|
|
|
*/ |
122
|
2 |
|
protected function refund(string $refundNumber, int $totalFee, int $refundFee, $optional = []) |
123
|
|
|
{ |
124
|
2 |
|
$params = array_merge([ |
125
|
2 |
|
'out_refund_no' => $refundNumber, |
126
|
2 |
|
'total_fee' => $totalFee, |
127
|
2 |
|
'refund_fee' => $refundFee, |
128
|
2 |
|
'appid' => $this->app['config']->app_id, |
129
|
2 |
|
], $optional); |
130
|
|
|
|
131
|
2 |
|
$api = $this->wrap($this->app->inSandbox() ? 'pay/refund' : 'secapi/pay/refund'; |
|
|
|
|
132
|
|
|
|
133
|
|
|
return $this->safeRequest($api), $params); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Query refund. |
138
|
|
|
* |
139
|
|
|
* @param string $number |
140
|
|
|
* @param string $type |
141
|
|
|
* |
142
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
143
|
|
|
* |
144
|
4 |
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
145
|
|
|
*/ |
146
|
|
|
protected function query(string $number, string $type) |
147
|
4 |
|
{ |
148
|
4 |
|
$params = [ |
149
|
|
|
'appid' => $this->app['config']->app_id, |
150
|
|
|
$type => $number, |
151
|
4 |
|
]; |
152
|
|
|
|
153
|
|
|
return $this->request($this->wrap('pay/refundquery'), $params); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|