Passed
Pull Request — master (#1457)
by Sky
03:27
created

Client::prepends()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\Sharing;
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 string $receivers     分账接收方列表
82
     */
83 1
    public function sharing(
84
        string $transactionId,
85
        string $outOrderNo,
86
        array $receivers
87
    ) {
88
        $params = [
89 1
            'appid' => $this->app['config']->app_id,
90 1
            'transaction_id' => $transactionId,
91 1
            'out_order_no' => $outOrderNo,
92 1
            'receivers' => json_encode(
93 1
                $receivers, JSON_UNESCAPED_UNICODE
94
            ),
95
        ];
96
97 1
        return $this->safeRequest(
98 1
            'secapi/pay/profitsharing', $params
99
        );
100
    }
101
102
    /**
103
     * Multi profit sharing.
104
     * 请求多次分账.
105
     * 
106
     * @param string $transactionId 微信支付订单号
107
     * @param string $outOrderNo    商户系统内部的分账单号
108
     * @param string $receivers     分账接收方列表
109
     */
110 1
    public function multiSharing(
111
        string $transactionId,
112
        string $outOrderNo,
113
        array $receivers
114
    ) {
115
        $params = [
116 1
            'appid' => $this->app['config']->app_id,
117 1
            'transaction_id' => $transactionId,
118 1
            'out_order_no' => $outOrderNo,
119 1
            'receivers' => json_encode(
120 1
                $receivers, JSON_UNESCAPED_UNICODE
121
            ),
122
        ];
123
124 1
        return $this->safeRequest(
125 1
            'secapi/pay/multiprofitsharing', $params
126
        );
127
    }
128
129
    /**
130
     * Finish profit sharing
131
     * 完结分账.
132
     * 
133
     * @param array $params
134
     */
135 1
    public function finishSharing(array $params)
136
    {
137 1
        $params['appid'] = $this->app['config']->app_id;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
138 1
        $params['sub_appid'] = null;
139
140 1
        return $this->safeRequest(
141 1
            'secapi/pay/profitsharingfinish', $params
142
        );
143
    }
144
145
    /**
146
     * Query profit sharing result
147
     * 查询分账结果.
148
     * 
149
     * @param string $transactionId 微信支付订单号
150
     * @param string $outOrderNo    商户系统内部的分账单号
151
     */
152 1
    public function querySharing(
153
        string $transactionId, string $outOrderNo
154
    ) {
155
        $params = [
156 1
            'sub_appid' => null,
157 1
            'transaction_id' => $transactionId,
158 1
            'out_order_no' => $outOrderNo,
159
        ];
160
161 1
        return $this->request(
162 1
            'pay/profitsharingquery', $params
163
        );
164
    }
165
}
166