|
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
|
|
|
public function byOutTradeNumber(string $number, string $refundNumber, int $totalFee, int $refundFee, array $optional = []) |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->refund($refundNumber, $totalFee, $refundFee, array_merge($optional, ['out_trade_no' => $number])); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Refund by transaction id. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $transactionId |
|
38
|
|
|
* @param string $refundNumber |
|
39
|
|
|
* @param int $totalFee |
|
40
|
|
|
* @param int $refundFee |
|
41
|
|
|
* @param array $optional |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
44
|
|
|
*/ |
|
45
|
|
|
public function byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $optional = []) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->refund($refundNumber, $totalFee, $refundFee, array_merge($optional, ['transaction_id' => $transactionId])); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Query refund by transaction id. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $transactionId |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function queryByTransactionId(string $transactionId) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->query($transactionId, 'transaction_id'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Query refund by out trade number. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $outTradeNumber |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function queryByOutTradeNumber(string $outTradeNumber) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->query($outTradeNumber, 'out_trade_no'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Query refund by out refund number. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $outRefundNumber |
|
78
|
|
|
* |
|
79
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function queryByOutRefundNumber(string $outRefundNumber) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->query($outRefundNumber, 'out_refund_no'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Query refund by refund id. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $refundId |
|
90
|
|
|
* |
|
91
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function queryByRefundId(string $refundId) |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->query($refundId, 'refund_id'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Refund. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $refundNumber |
|
102
|
|
|
* @param int $totalFee |
|
103
|
|
|
* @param int $refundFee |
|
104
|
|
|
* @param array $optional |
|
105
|
|
|
* |
|
106
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function refund(string $refundNumber, int $totalFee, int $refundFee, $optional = []) |
|
109
|
|
|
{ |
|
110
|
|
|
$params = array_merge([ |
|
111
|
|
|
'out_refund_no' => $refundNumber, |
|
112
|
|
|
'total_fee' => $totalFee, |
|
113
|
|
|
'refund_fee' => $refundFee, |
|
114
|
|
|
], $optional); |
|
115
|
|
|
|
|
116
|
|
|
return $this->safeRequest('secapi/pay/refund', $params); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Query refund. |
|
121
|
|
|
* |
|
122
|
|
|
* @param string $number |
|
123
|
|
|
* @param string $type |
|
124
|
|
|
* |
|
125
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
126
|
|
|
*/ |
|
127
|
|
|
protected function query(string $number, string $type) |
|
128
|
|
|
{ |
|
129
|
|
|
$params = [ |
|
130
|
|
|
$type => $number, |
|
131
|
|
|
]; |
|
132
|
|
|
|
|
133
|
|
|
return $this->request('pay/refundquery', $params); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|