Passed
Push — master ( f07ef0...7807ae )
by wannanbigpig
02:30
created

Application::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Application.php
4
 *
5
 * Created by PhpStorm.
6
 *
7
 * author: liuml  <[email protected]>
8
 * DateTime: 2019-04-04  16:31
9
 */
10
11
namespace WannanBigPig\Alipay\Payment;
12
13
use Symfony\Component\HttpFoundation\Response;
14
use WannanBigPig\Alipay\Kernel\Support\Support;
15
use WannanBigPig\Alipay\Payment\Trade\Fund;
16
use WannanBigPig\Alipay\Payment\Trade\Query;
17
use WannanBigPig\Supports\AccessData;
18
use WannanBigPig\Supports\Exceptions;
19
use WannanBigPig\Supports\Str;
20
21
/**
22
 * Class Application.
23
 *
24
 * @method Response app(array $payload) app支付
25
 * @method AccessData create(array $payload) 统一收单交易创建接口 小程序支付
26
 * @method AccessData pay(array $payload) pos支付 (统一收单交易支付接口) 商户主扫
27
 * @method AccessData precreate(array $payload) 订单预创建
28
 * @method AccessData faceInit(array $payload) 扫脸支付 扫脸初始化
29
 * @method Response wap(array $payload) 手机站支付
30
 * @method Response pagePay(array $payload) pc支付
31
 * @method AccessData refund($params) 退款
32
 * @method AccessData cancel($params) 取消订单
33
 * @method AccessData close($params) 关闭订单
34
 * @method AccessData download($params) 下载对账单
35
 * @method AccessData settle($params) 结算
36
 * @method AccessData orderInfoSync($params) 订单信息同步
37
 * @method Query query() 查询类
38
 * @method Fund fund() 资金类
39
 *
40
 * @property Fund  fund  资金类
41
 * @property Query query 查询类
42
 */
43
class Application
44
{
45
46
    /**
47
     * @var string
48
     */
49
    public $method = '';
50
51
    /**
52
     * __get
53
     *
54
     * @param $name
55
     *
56
     * @return mixed
57
     *
58
     * @throws \WannanBigPig\Supports\Exceptions\ApplicationException
59
     *
60
     * @author   liuml  <[email protected]>
61
     * @DateTime 2019-04-28  12:10
62
     */
63 2
    public function __get($name)
64
    {
65 2
        return $this->getVariable($name);
66
    }
67
68
    /**
69
     * __set
70
     *
71
     * @param $name
72
     * @param $value
73
     *
74
     * @author   liuml  <[email protected]>
75
     * @DateTime 2019-04-28  12:10
76
     */
77
    public function __set($name, $value)
78
    {
79
        Support::$config->set($name, $value);
80
    }
81
82
    /**
83
     * getVariable
84
     *
85
     * @param $name
86
     *
87
     * @return mixed
88
     *
89
     * @throws \WannanBigPig\Supports\Exceptions\ApplicationException
90
     *
91
     * @author   liuml  <[email protected]>
92
     * @DateTime 2019-04-28  12:10
93
     */
94 2
    public function getVariable($name)
95
    {
96 2
        $method = Str::studly($name);
97
        // 组装命名空间
98 2
        $gateway = __NAMESPACE__ . '\\Trade\\' . $method;
99
100 2
        if (class_exists($gateway)) {
101 2
            $this->setMethod();
102 2
            return $this->make($gateway);
103
        }
104
105
        throw new Exceptions\ApplicationException("The {$method}  member variable doesn't exist");
106
    }
107
108
    /**
109
     * get
110
     *
111
     * @param $name
112
     *
113
     * @return array|mixed|null
114
     *
115
     * @author   liuml  <[email protected]>
116
     * @DateTime 2019-04-28  12:10
117
     */
118
    public function get($name)
119
    {
120
        return Support::$config->get($name, '');
121
    }
122
123
    /**
124
     * set
125
     *
126
     * @param $name
127
     * @param $value
128
     *
129
     * @author   liuml  <[email protected]>
130
     * @DateTime 2019-04-28  12:09
131
     */
132
    public function set($name, $value)
133
    {
134
        Support::$config->set($name, $value);
135
    }
136
137
    /**
138
     * __call
139
     *
140
     * @param $name
141
     * @param $arguments
142
     *
143
     * @return mixed
144
     *
145
     * @throws \WannanBigPig\Supports\Exceptions\ApplicationException
146
     *
147
     * @author   liuml  <[email protected]>
148
     * @DateTime 2019-04-28  12:09
149
     */
150 15
    public function __call($name, $arguments)
151
    {
152 15
        return $this->alipayMethod($name, ...$arguments);
153
    }
154
155
    /**
156
     * alipayMethod
157
     *
158
     * @param         $method
159
     * @param  array  $params
160
     *
161
     * @return mixed
162
     *
163
     * @throws \WannanBigPig\Supports\Exceptions\ApplicationException
164
     *
165
     * @author   liuml  <[email protected]>
166
     * @DateTime 2019-04-28  12:09
167
     */
168 15
    public function alipayMethod($method, $params = [])
169
    {
170 15
        $method = Str::studly($method);
171
        // 组装命名空间
172 15
        $gateway = __NAMESPACE__ . '\\Trade\\' . $method;
173
174 15
        if (class_exists($gateway)) {
175 13
            $this->setMethod($method);
176
177 13
            return $this->make($gateway, $params);
178
        }
179
180 2
        throw new Exceptions\ApplicationException("The {$method} method doesn't exist");
181
    }
182
183
    /**
184
     * make
185
     *
186
     * @param  string  $gateway
187
     * @param  array   $params
188
     *
189
     * @return mixed
190
     *
191
     * @author   liuml  <[email protected]>
192
     * @DateTime 2019-04-28  12:09
193
     */
194 15
    public function make(string $gateway, $params = [])
195
    {
196 15
        $app = new $gateway();
197
198 15
        if ($app instanceof DoctorInterface) {
199 13
            return $app->exec($params);
200
        }
201
202 2
        return $app;
203
    }
204
205
    /**
206
     * setMethod
207
     *
208
     * @param  string  $method
209
     *
210
     * @author   liuml  <[email protected]>
211
     * @DateTime 2019-04-28  12:09
212
     */
213 15
    public function setMethod($method = '')
214
    {
215 15
        Support::$config->set('event', [
216 15
            'driver' => 'Payment',
217 15
            'method' => $method ? : $this->method,
218
        ]);
219 15
    }
220
221
    /**
222
     * verify
223
     *
224
     * @param  array|null  $data
225
     *
226
     * @return bool
227
     *
228
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
229
     *
230
     * @author   liuml  <[email protected]>
231
     * @DateTime 2019-04-28  12:09
232
     */
233 1
    public function verify($data = null)
234
    {
235 1
        return Support::notifyVerify($data);
236
    }
237
238
    /**
239
     * execute
240
     *
241
     * @param $method
242
     * @param $params
243
     *
244
     * @return \WannanBigPig\Supports\AccessData
245
     *
246
     * @throws \WannanBigPig\Alipay\Kernel\Exceptions\SignException
247
     * @throws \WannanBigPig\Supports\Exceptions\BusinessException
248
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
249
     *
250
     * @author   liuml  <[email protected]>
251
     * @DateTime 2019-04-28  12:08
252
     */
253
    public function execute($method, $params)
254
    {
255
        return Support::executeApi($params, $method);
256
    }
257
258
    /**
259
     * sdkExecute
260
     *
261
     * @param $method
262
     * @param $params
263
     *
264
     * @return \Symfony\Component\HttpFoundation\Response
265
     *
266
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
267
     *
268
     * @author   liuml  <[email protected]>
269
     * @DateTime 2019-04-28  12:08
270
     */
271
    public function sdkExecute($method, $params)
272
    {
273
        return Support::executeSdk($params, $method);
274
    }
275
276
    /**
277
     * pegeExecute
278
     *
279
     * @param $method
280
     * @param $params
281
     *
282
     * @return \Symfony\Component\HttpFoundation\Response
283
     *
284
     * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException
285
     *
286
     * @author   liuml  <[email protected]>
287
     * @DateTime 2019-04-28  12:09
288
     */
289
    public function pegeExecute($method, $params)
290
    {
291
        return Support::executePage($params, $method);
292
    }
293
}
294