Client   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 72
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A querySubMerchantByWeChatId() 0 7 1
A addSubMerchant() 0 3 1
A querySubMerchantByMerchantId() 0 7 1
A manage() 0 10 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\Merchant;
13
14
use EasyWeChat\Payment\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @author mingyoung <[email protected]>
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * Add sub-merchant.
25
     *
26
     * @param array $params
27
     *
28
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
29
     *
30
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
31
     */
32 1
    public function addSubMerchant(array $params)
33
    {
34 1
        return $this->manage($params, ['action' => 'add']);
35
    }
36
37
    /**
38
     * Query sub-merchant by merchant id.
39
     *
40
     * @param string $id
41
     *
42
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
43
     *
44
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
45
     */
46 1
    public function querySubMerchantByMerchantId(string $id)
47
    {
48
        $params = [
49 1
            'micro_mch_id' => $id,
50
        ];
51
52 1
        return $this->manage($params, ['action' => 'query']);
53
    }
54
55
    /**
56
     * Query sub-merchant by wechat id.
57
     *
58
     * @param string $id
59
     *
60
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
61
     *
62
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
63
     */
64 1
    public function querySubMerchantByWeChatId(string $id)
65
    {
66
        $params = [
67 1
            'recipient_wechatid' => $id,
68
        ];
69
70 1
        return $this->manage($params, ['action' => 'query']);
71
    }
72
73
    /**
74
     * @param array $params
75
     * @param array $query
76
     *
77
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
78
     *
79
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
80
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
81
     * @throws \GuzzleHttp\Exception\GuzzleException
82
     */
83 3
    protected function manage(array $params, array $query)
84
    {
85 3
        $params = array_merge($params, [
86 3
            'appid' => $this->app['config']->app_id,
87 3
            'nonce_str' => '',
88 3
            'sub_mch_id' => '',
89 3
            'sub_appid' => '',
90
        ]);
91
92 3
        return $this->safeRequest('secapi/mch/submchmanage', $params, 'post', compact('query'));
93
    }
94
}
95