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