Test Setup Failed
Pull Request — master (#1777)
by
unknown
09:11
created

Client   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 214
Duplicated Lines 0 %

Test Coverage

Coverage 95.12%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 51
c 3
b 1
f 0
dl 0
loc 214
ccs 39
cts 41
cp 0.9512
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A prepends() 0 4 1
A share() 0 16 1
A query() 0 11 1
A deleteReceiver() 0 11 1
A addReceiver() 0 11 1
A multiShare() 0 16 1
A markOrderAsFinished() 0 7 1
A returnShare() 0 18 1
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\ProfitSharing;
13
14
use EasyWeChat\Payment\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @author ClouderSky <[email protected]>
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * {@inheritdoc}.
25
     */
26
    protected function prepends()
27
    {
28
        return [
29
            'sign_type' => 'HMAC-SHA256',
30
        ];
31
    }
32
33
    /**
34
     * Add profit sharing receiver.
35
     * 服务商代子商户发起添加分账接收方请求.
36
     * 后续可通过发起分账请求将结算后的钱分到该分账接收方.
37
     *
38
     * @param array $receiver 分账接收方对象,json格式
39
     *
40
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
41
     *
42
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
43
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
44
     * @throws \GuzzleHttp\Exception\GuzzleException
45
     */
46 1
    public function addReceiver(array $receiver)
47
    {
48
        $params = [
49 1
            'appid' => $this->app['config']->app_id,
50 1
            'receiver' => json_encode(
51 1
                $receiver, JSON_UNESCAPED_UNICODE
52
            ),
53
        ];
54
55 1
        return $this->request(
56 1
            'pay/profitsharingaddreceiver', $params
57
        );
58
    }
59
60
    /**
61
     * Delete profit sharing receiver.
62
     * 服务商代子商户发起删除分账接收方请求.
63
     * 删除后不支持将结算后的钱分到该分账接收方.
64
     *
65
     * @param array $receiver 分账接收方对象,json格式
66
     *
67
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
68
     *
69
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
70
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
71
     * @throws \GuzzleHttp\Exception\GuzzleException
72
     */
73 1
    public function deleteReceiver(array $receiver)
74
    {
75
        $params = [
76 1
            'appid' => $this->app['config']->app_id,
77 1
            'receiver' => json_encode(
78 1
                $receiver, JSON_UNESCAPED_UNICODE
79
            ),
80
        ];
81
82 1
        return $this->request(
83 1
            'pay/profitsharingremovereceiver', $params
84
        );
85
    }
86
87
    /**
88
     * Single profit sharing.
89
     * 请求单次分账.
90
     *
91
     * @param string $transactionId 微信支付订单号
92
     * @param string $outOrderNo    商户系统内部的分账单号
93
     * @param array  $receivers     分账接收方列表
94
     *
95
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
96
     *
97
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
98
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
99
     * @throws \GuzzleHttp\Exception\GuzzleException
100
     */
101 1
    public function share(
102
        string $transactionId,
103
        string $outOrderNo,
104
        array $receivers
105
    ) {
106
        $params = [
107 1
            'appid' => $this->app['config']->app_id,
108 1
            'transaction_id' => $transactionId,
109 1
            'out_order_no' => $outOrderNo,
110 1
            'receivers' => json_encode(
111 1
                $receivers, JSON_UNESCAPED_UNICODE
112
            ),
113
        ];
114
115 1
        return $this->safeRequest(
116 1
            'secapi/pay/profitsharing', $params
117
        );
118
    }
119
120
    /**
121
     * Multi profit sharing.
122
     * 请求多次分账.
123
     *
124
     * @param string $transactionId 微信支付订单号
125
     * @param string $outOrderNo    商户系统内部的分账单号
126
     * @param array  $receivers     分账接收方列表
127
     *
128
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
129
     *
130
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
131
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
132
     * @throws \GuzzleHttp\Exception\GuzzleException
133
     */
134 1
    public function multiShare(
135
        string $transactionId,
136
        string $outOrderNo,
137
        array $receivers
138
    ) {
139
        $params = [
140 1
            'appid' => $this->app['config']->app_id,
141 1
            'transaction_id' => $transactionId,
142 1
            'out_order_no' => $outOrderNo,
143 1
            'receivers' => json_encode(
144 1
                $receivers, JSON_UNESCAPED_UNICODE
145
            ),
146
        ];
147
148 1
        return $this->safeRequest(
149 1
            'secapi/pay/multiprofitsharing', $params
150
        );
151
    }
152
153
    /**
154
     * Finish profit sharing.
155
     * 完结分账.
156
     *
157
     * @param array $params
158
     *
159
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
160
     *
161
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
162
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
163
     * @throws \GuzzleHttp\Exception\GuzzleException
164
     */
165 1
    public function markOrderAsFinished(array $params)
166
    {
167 1
        $params['appid'] = $this->app['config']->app_id;
168 1
        $params['sub_appid'] = null;
169
170 1
        return $this->safeRequest(
171 1
            'secapi/pay/profitsharingfinish', $params
172
        );
173
    }
174
175
    /**
176
     * Query profit sharing result.
177
     * 查询分账结果.
178
     *
179
     * @param string $transactionId 微信支付订单号
180
     * @param string $outOrderNo    商户系统内部的分账单号
181
     *
182
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
183
     *
184
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
185
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
186
     * @throws \GuzzleHttp\Exception\GuzzleException
187
     */
188 1
    public function query(
189
        string $transactionId, string $outOrderNo
190
    ) {
191
        $params = [
192 1
            'sub_appid' => null,
193 1
            'transaction_id' => $transactionId,
194 1
            'out_order_no' => $outOrderNo,
195
        ];
196
197 1
        return $this->request(
198 1
            'pay/profitsharingquery', $params
199
        );
200
    }
201
202
    /**
203
     * Profit sharing return.
204
     * 分账回退.
205
     *
206
     * @param string $outOrderNo   商户系统内部的分账单号
207
     * @param string $outReturnNo  商户系统内部分账回退单号
208
     * @param int    $returnAmount 回退金额
209
     * @param string $description  回退描述
210
     *
211
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
212
     *
213
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
214
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
215
     * @throws \GuzzleHttp\Exception\GuzzleException
216
     */
217
    public function returnShare(
218
        string $outOrderNo,
219
        string $outReturnNo,
220
        int $returnAmount,
221
        string $description
222
    ) {
223
        $params = [
224
            'appid' => $this->app['config']->app_id,
225
            'out_order_no' => $outOrderNo,
226
            'out_return_no' => $outReturnNo,
227
            'return_account_type' => 'MERCHANT_ID',
228
            'return_account' => $this->app['config']->mch_id,
229
            'return_amount' => $returnAmount,
230
            'description' => $description,
231
        ];
232
233
        return $this->safeRequest(
234
            'secapi/pay/profitsharingreturn', $params
235
        );
236
    }
237
}
238