Entry::populate()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 28
rs 8.439
cc 5
eloc 17
nc 8
nop 1
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
     * Get id from entry.
78
     *
79
     * @return string Event ID that generated the launch.
80
     */
81
    public function getId()
82
    {
83
        return $this->getIfSet('id');
84
    }
85
86
    /**
87
     * Get status from entry.
88
     *
89
     * @return string Launch status. Possible values: SCHEDULED, SETTLED.
90
     */
91
    public function getStatus()
92
    {
93
        return $this->getIfSet('status');
94
    }
95
96
    public function getOperation()
97
    {
98
        return $this->getIfSet('operation');
99
    }
100
101
    /**
102
     * Get total value of order.
103
     *
104
     * @return int|float
105
     */
106
    public function getAmountTotal()
107
    {
108
        return $this->getIfSet('total', $this->data->amount);
109
    }
110
111
    /**
112
     * Get total value of MoIP rate.
113
     *
114
     * @return int|float
115
     */
116
    public function getAmountFee()
117
    {
118
        return $this->getIfSet('fee', $this->data->amount);
119
    }
120
121
    /**
122
     * Get net total value.
123
     *
124
     * @return int|float
125
     */
126
    public function getAmountLiquid()
127
    {
128
        return $this->getIfSet('liquid', $this->data->amount);
129
    }
130
131
    /**
132
     * Get currency used in the application. Possible values: BRL.
133
     *
134
     * @return string
135
     */
136
    public function getAmountCurrency()
137
    {
138
        return $this->getIfSet('currency', $this->data->amount);
139
    }
140
141
    /**
142
     * Get additional description.
143
     *
144
     * @return string
145
     */
146
    public function getDetails()
147
    {
148
        return $this->getIfSet('details');
149
    }
150
151
    /**
152
     * Get parant payments.
153
     *
154
     * @return string
155
     */
156
    public function getParentPayments()
157
    {
158
        return $this->getIfSet('parentPayments');
159
    }
160
161
    /**
162
     * Get expected date of settlement.
163
     *
164
     * @return \DateTime
165
     */
166
    public function getScheduledFor()
167
    {
168
        return $this->getIfSetDateTime('scheduledFor');
169
    }
170
171
    /**
172
     * Get Settlement date;.
173
     *
174
     * @return \DateTime
175
     */
176
    public function getSettledAt()
177
    {
178
        return $this->getIfSetDateTime('settledAt');
179
    }
180
181
    /**
182
     * Get date of last update.
183
     *
184
     * @return \DateTime
185
     */
186
    public function getUpdatedAt()
187
    {
188
        return $this->getIfSetDateTime('updatedAt');
189
    }
190
191
    /**
192
     * Get creation date of launch.
193
     *
194
     * @return \DateTime
195
     */
196
    public function getCreatedAt()
197
    {
198
        return $this->getIfSetDateTime('createdAt');
199
    }
200
}
201