Passed
Pull Request — master (#1647)
by
11:06
created

Client   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Test Coverage

Coverage 95.12%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 41
c 2
b 1
f 0
dl 0
loc 152
ccs 39
cts 41
cp 0.9512
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteReceiver() 0 11 1
A addReceiver() 0 11 1
A share() 0 16 1
A query() 0 11 1
A multiShare() 0 16 1
A markOrderAsFinished() 0 7 1
A prepends() 0 4 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 1
    public function addReceiver(array $receiver)
41
    {
42
        $params = [
43 1
            'appid' => $this->app['config']->app_id,
44 1
            'receiver' => json_encode(
45 1
                $receiver, JSON_UNESCAPED_UNICODE
46
            ),
47
        ];
48
49 1
        return $this->request(
50 1
            'pay/profitsharingaddreceiver', $params
51
        );
52
    }
53
54
    /**
55
     * Delete profit sharing receiver.
56
     * 服务商代子商户发起删除分账接收方请求.
57
     * 删除后不支持将结算后的钱分到该分账接收方.
58
     *
59
     * @param array $receiver 分账接收方对象,json格式
60
     */
61 1
    public function deleteReceiver(array $receiver)
62
    {
63
        $params = [
64 1
            'appid' => $this->app['config']->app_id,
65 1
            'receiver' => json_encode(
66 1
                $receiver, JSON_UNESCAPED_UNICODE
67
            ),
68
        ];
69
70 1
        return $this->request(
71 1
            'pay/profitsharingremovereceiver', $params
72
        );
73
    }
74
75
    /**
76
     * Single profit sharing.
77
     * 请求单次分账.
78
     *
79
     * @param string $transactionId 微信支付订单号
80
     * @param string $outOrderNo    商户系统内部的分账单号
81
     * @param array  $receivers     分账接收方列表
82
     *
83
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
84
     *
85
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
86
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
87
     */
88 1
    public function share(
89
        string $transactionId,
90
        string $outOrderNo,
91
        array $receivers
92
    ) {
93
        $params = [
94 1
            'appid' => $this->app['config']->app_id,
95 1
            'transaction_id' => $transactionId,
96 1
            'out_order_no' => $outOrderNo,
97 1
            'receivers' => json_encode(
98 1
                $receivers, JSON_UNESCAPED_UNICODE
99
            ),
100
        ];
101
102 1
        return $this->safeRequest(
103 1
            'secapi/pay/profitsharing', $params
104
        );
105
    }
106
107
    /**
108
     * Multi profit sharing.
109
     * 请求多次分账.
110
     *
111
     * @param string $transactionId 微信支付订单号
112
     * @param string $outOrderNo    商户系统内部的分账单号
113
     * @param array  $receivers     分账接收方列表
114
     *
115
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
116
     *
117
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
118
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
119
     */
120 1
    public function multiShare(
121
        string $transactionId,
122
        string $outOrderNo,
123
        array $receivers
124
    ) {
125
        $params = [
126 1
            'appid' => $this->app['config']->app_id,
127 1
            'transaction_id' => $transactionId,
128 1
            'out_order_no' => $outOrderNo,
129 1
            'receivers' => json_encode(
130 1
                $receivers, JSON_UNESCAPED_UNICODE
131
            ),
132
        ];
133
134 1
        return $this->safeRequest(
135 1
            'secapi/pay/multiprofitsharing', $params
136
        );
137
    }
138
139
    /**
140
     * Finish profit sharing.
141
     * 完结分账.
142
     *
143
     * @param array $params
144
     */
145 1
    public function markOrderAsFinished(array $params)
146
    {
147 1
        $params['appid'] = $this->app['config']->app_id;
148 1
        $params['sub_appid'] = null;
149
150 1
        return $this->safeRequest(
151 1
            'secapi/pay/profitsharingfinish', $params
152
        );
153
    }
154
155
    /**
156
     * Query profit sharing result.
157
     * 查询分账结果.
158
     *
159
     * @param string $transactionId 微信支付订单号
160
     * @param string $outOrderNo    商户系统内部的分账单号
161
     */
162 1
    public function query(
163
        string $transactionId, string $outOrderNo
164
    ) {
165
        $params = [
166 1
            'sub_appid' => null,
167 1
            'transaction_id' => $transactionId,
168 1
            'out_order_no' => $outOrderNo,
169
        ];
170
171 1
        return $this->request(
172 1
            'pay/profitsharingquery', $params
173
        );
174
    }
175
}
176