|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Moip\Resource; |
|
4
|
|
|
|
|
5
|
|
|
use stdClass; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Entry. |
|
9
|
|
|
*/ |
|
10
|
|
|
class Entry extends MoipResource |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @const string |
|
14
|
|
|
*/ |
|
15
|
|
|
const PATH = 'entries'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Initializes new instances. |
|
19
|
|
|
*/ |
|
20
|
|
|
protected function initialize() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->data = new stdClass(); |
|
23
|
|
|
$this->data->amount = new stdClass(); |
|
24
|
|
|
$this->data->details = new stdClass(); |
|
25
|
|
|
$this->data->parentPayments = new stdClass(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Mount the entry. |
|
30
|
|
|
* |
|
31
|
|
|
* @param \stdClass $response |
|
32
|
|
|
* |
|
33
|
|
|
* @return Entry Entry information. |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function populate(stdClass $response) |
|
36
|
|
|
{ |
|
37
|
|
|
$entry = clone $this; |
|
38
|
|
|
|
|
39
|
|
|
$entry->data->id = $this->getIfSet('id', $response); |
|
40
|
|
|
$entry->data->status = $this->getIfSet('status', $response); |
|
41
|
|
|
$entry->data->operation = $this->getIfSet('operation', $response); |
|
42
|
|
|
|
|
43
|
|
|
if (isset($response->amount)) { |
|
44
|
|
|
$entry->data->amount->total = $this->getIfSet('total', $response->amount); |
|
45
|
|
|
$entry->data->amount->fee = $this->getIfSet('fee', $response->amount); |
|
46
|
|
|
$entry->data->amount->liquid = $this->getIfSet('liquid', $response->amount); |
|
47
|
|
|
$entry->data->amount->currency = $this->getIfSet('currency', $response->amount); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if (isset($response->details)) { |
|
51
|
|
|
$entry->data->details = $this->getIfSet('details', $response); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (isset($response->{'parent'}) && isset($response->{'parent'}->payments)) { |
|
55
|
|
|
$payments = new Payment($entry->moip); |
|
56
|
|
|
$payments->populate($response->{'parent'}->payments); |
|
57
|
|
|
|
|
58
|
|
|
$entry->data->parentPayments = $payments; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $entry; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get entry in api by id. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $id_moip Event ID that generated the launch. |
|
68
|
|
|
* |
|
69
|
|
|
* @return stdClass |
|
70
|
|
|
*/ |
|
71
|
|
|
public function get($id_moip) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->getByPath(sprintf('/%s/%s/%s/', MoipResource::VERSION, self::PATH, $id_moip)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Create a new Entries List instance. |
|
78
|
|
|
* |
|
79
|
|
|
* @return \Moip\Resource\EntriesList |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getList() |
|
82
|
|
|
{ |
|
83
|
|
|
$entriesList = new EntriesList($this->moip); |
|
84
|
|
|
|
|
85
|
|
|
return $entriesList->get(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get id from entry. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string Event ID that generated the launch. |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getId() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->getIfSet('id'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get status from entry. |
|
100
|
|
|
* |
|
101
|
|
|
* @return string Launch status. Possible values: SCHEDULED, SETTLED. |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getStatus() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->getIfSet('status'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getOperation() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->getIfSet('operation'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get total value of order. |
|
115
|
|
|
* |
|
116
|
|
|
* @return int|float |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getAmountTotal() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->getIfSet('total', $this->data->amount); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get total value of MoIP rate. |
|
125
|
|
|
* |
|
126
|
|
|
* @return int|float |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getAmountFee() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->getIfSet('fee', $this->data->amount); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Get net total value. |
|
135
|
|
|
* |
|
136
|
|
|
* @return int|float |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getAmountLiquid() |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->getIfSet('liquid', $this->data->amount); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Get currency used in the application. Possible values: BRL. |
|
145
|
|
|
* |
|
146
|
|
|
* @return string |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getAmountCurrency() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->getIfSet('currency', $this->data->amount); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Get additional description. |
|
155
|
|
|
* |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getDetails() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->getIfSet('details'); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Get parant payments. |
|
165
|
|
|
* |
|
166
|
|
|
* @return string |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getParentPayments() |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->getIfSet('parentPayments'); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Get expected date of settlement. |
|
175
|
|
|
* |
|
176
|
|
|
* @return \DateTime |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getScheduledFor() |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->getIfSetDateTime('scheduledFor'); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Get Settlement date;. |
|
185
|
|
|
* |
|
186
|
|
|
* @return \DateTime |
|
187
|
|
|
*/ |
|
188
|
|
|
public function getSettledAt() |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->getIfSetDateTime('settledAt'); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Get date of last update. |
|
195
|
|
|
* |
|
196
|
|
|
* @return \DateTime |
|
197
|
|
|
*/ |
|
198
|
|
|
public function getUpdatedAt() |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->getIfSetDateTime('updatedAt'); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Get creation date of launch. |
|
205
|
|
|
* |
|
206
|
|
|
* @return \DateTime |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getCreatedAt() |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->getIfSetDateTime('createdAt'); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|