1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Moip; |
4
|
|
|
|
5
|
|
|
use Moip\Contracts\Authentication; |
6
|
|
|
use Moip\Resource\Account; |
7
|
|
|
use Moip\Resource\BankAccount; |
8
|
|
|
use Moip\Resource\Customer; |
9
|
|
|
use Moip\Resource\Entry; |
10
|
|
|
use Moip\Resource\Holder; |
11
|
|
|
use Moip\Resource\Keys; |
12
|
|
|
use Moip\Resource\Multiorders; |
13
|
|
|
use Moip\Resource\NotificationPreferences; |
14
|
|
|
use Moip\Resource\Orders; |
15
|
|
|
use Moip\Resource\Payment; |
16
|
|
|
use Moip\Resource\Refund; |
17
|
|
|
use Moip\Resource\Transfers; |
18
|
|
|
use Moip\Resource\WebhookList; |
19
|
|
|
use Requests_Session; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Moip. |
23
|
|
|
*/ |
24
|
|
|
class Moip |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* endpoint of production. |
28
|
|
|
* |
29
|
|
|
* @const string |
30
|
|
|
*/ |
31
|
|
|
const ENDPOINT_PRODUCTION = 'https://api.moip.com.br'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* endpoint of sandbox. |
35
|
|
|
* |
36
|
|
|
* @const string |
37
|
|
|
*/ |
38
|
|
|
const ENDPOINT_SANDBOX = 'https://sandbox.moip.com.br'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Client name. |
42
|
|
|
* |
43
|
|
|
* @const string |
44
|
|
|
* */ |
45
|
|
|
const CLIENT = 'MoipPhpSDK'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Client Version. |
49
|
|
|
* |
50
|
|
|
* @const string |
51
|
|
|
*/ |
52
|
|
|
const CLIENT_VERSION = '3.0.0'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Authentication that will be added to the header of request. |
56
|
|
|
* |
57
|
|
|
* @var \Moip\MoipAuthentication |
58
|
|
|
*/ |
59
|
|
|
private $moipAuthentication; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Endpoint of request. |
63
|
|
|
* |
64
|
|
|
* @var \Moip\Moip::ENDPOINT_PRODUCTION|\Moip\Moip::ENDPOINT_SANDBOX |
65
|
|
|
*/ |
66
|
|
|
private $endpoint; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var Requests_Session HTTP session configured to use the moip API. |
70
|
|
|
*/ |
71
|
|
|
private $session; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Create a new aurhentication with the endpoint. |
75
|
|
|
* |
76
|
|
|
* @param \Moip\Auth\MoipAuthentication $moipAuthentication |
77
|
|
|
* @param string $endpoint |
78
|
|
|
*/ |
79
|
|
|
public function __construct(Authentication $moipAuthentication, $endpoint = self::ENDPOINT_PRODUCTION) |
80
|
|
|
{ |
81
|
|
|
$this->moipAuthentication = $moipAuthentication; |
|
|
|
|
82
|
|
|
$this->endpoint = $endpoint; |
|
|
|
|
83
|
|
|
$this->createNewSession(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Creates a new Request_Session with all the default values. |
88
|
|
|
* A Session is created at construction. |
89
|
|
|
* |
90
|
|
|
* @param float $timeout How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01). |
91
|
|
|
* @param float $connect_timeout How long should we wait while trying to connect? (seconds with a millisecond precision, default: 10, example: 0.01) |
92
|
|
|
*/ |
93
|
|
|
public function createNewSession($timeout = 30.0, $connect_timeout = 30.0) |
94
|
|
|
{ |
95
|
|
|
$user_agent = sprintf('%s/%s (+https://github.com/moip/moip-sdk-php/)', self::CLIENT, self::CLIENT_VERSION); |
96
|
|
|
$sess = new Requests_Session($this->endpoint); |
97
|
|
|
$sess->options['auth'] = $this->moipAuthentication; |
98
|
|
|
$sess->options['timeout'] = $timeout; |
99
|
|
|
$sess->options['connect_timeout'] = $connect_timeout; |
100
|
|
|
$sess->options['useragent'] = $user_agent; |
101
|
|
|
$this->session = $sess; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the http session created. |
106
|
|
|
* |
107
|
|
|
* @return Requests_Session |
108
|
|
|
*/ |
109
|
|
|
public function getSession() |
110
|
|
|
{ |
111
|
|
|
return $this->session; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Replace the http session by a custom one. |
116
|
|
|
* |
117
|
|
|
* @param Requests_Session $session |
118
|
|
|
*/ |
119
|
|
|
public function setSession($session) |
120
|
|
|
{ |
121
|
|
|
$this->session = $session; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Create a new Customer instance. |
126
|
|
|
* |
127
|
|
|
* @return \Moip\Resource\Customer |
128
|
|
|
*/ |
129
|
|
|
public function customers() |
130
|
|
|
{ |
131
|
|
|
return new Customer($this); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Create a new Holder instance. |
136
|
|
|
* |
137
|
|
|
* @return \Moip\Resource\Holder |
138
|
|
|
*/ |
139
|
|
|
public function holders() |
140
|
|
|
{ |
141
|
|
|
return new Holder($this); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Create a new Account instance. |
146
|
|
|
* |
147
|
|
|
* @return \Moip\Resource\Account |
148
|
|
|
*/ |
149
|
|
|
public function accounts() |
150
|
|
|
{ |
151
|
|
|
return new Account($this); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Create a new Entry instance. |
156
|
|
|
* |
157
|
|
|
* @return \Moip\Resource\Entry |
158
|
|
|
*/ |
159
|
|
|
public function entries() |
160
|
|
|
{ |
161
|
|
|
return new Entry($this); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Create a new Orders instance. |
166
|
|
|
* |
167
|
|
|
* @return \Moip\Resource\Orders |
168
|
|
|
*/ |
169
|
|
|
public function orders() |
170
|
|
|
{ |
171
|
|
|
return new Orders($this); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Create a new Payment instance. |
176
|
|
|
* |
177
|
|
|
* @return \Moip\Resource\Payment |
178
|
|
|
*/ |
179
|
|
|
public function payments() |
180
|
|
|
{ |
181
|
|
|
return new Payment($this); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Create a new Multiorders instance. |
186
|
|
|
* |
187
|
|
|
* @return \Moip\Resource\Multiorders |
188
|
|
|
*/ |
189
|
|
|
public function multiorders() |
190
|
|
|
{ |
191
|
|
|
return new Multiorders($this); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Create a new Transfers. |
196
|
|
|
* |
197
|
|
|
* @return \Moip\Resource\Transfers |
198
|
|
|
*/ |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Create a new Transfers instance. |
202
|
|
|
* |
203
|
|
|
* @return Transfers |
204
|
|
|
*/ |
205
|
|
|
public function transfers() |
206
|
|
|
{ |
207
|
|
|
return new Transfers($this); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Create a new Notification Prefences instance. |
212
|
|
|
* |
213
|
|
|
* @return NotificationPreferences |
214
|
|
|
*/ |
215
|
|
|
public function notifications() |
216
|
|
|
{ |
217
|
|
|
return new NotificationPreferences($this); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Create a new WebhookList instance. |
222
|
|
|
* |
223
|
|
|
* @return WebhookList |
224
|
|
|
*/ |
225
|
|
|
public function webhooks() |
226
|
|
|
{ |
227
|
|
|
return new WebhookList($this); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Create a new Keys instance. |
232
|
|
|
* |
233
|
|
|
* @return Keys |
234
|
|
|
*/ |
235
|
|
|
public function keys() |
236
|
|
|
{ |
237
|
|
|
return new Keys($this); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Create a new Refund instance. |
242
|
|
|
* |
243
|
|
|
* @return Refund |
244
|
|
|
*/ |
245
|
|
|
public function refunds() |
246
|
|
|
{ |
247
|
|
|
return new Refund($this); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Create a new BankAccount instance. |
252
|
|
|
* |
253
|
|
|
* @return BankAccount |
254
|
|
|
*/ |
255
|
|
|
public function bankaccount() |
256
|
|
|
{ |
257
|
|
|
return new BankAccount($this); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Get the endpoint. |
262
|
|
|
* |
263
|
|
|
* @return \Moip\Moip::ENDPOINT_PRODUCTION|\Moip\Moip::ENDPOINT_SANDBOX |
264
|
|
|
*/ |
265
|
|
|
public function getEndpoint() |
266
|
|
|
{ |
267
|
|
|
return $this->endpoint; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..