Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 8f9755e

Browse files
committed
feat(orders): map attributes on order creation
1 parent ef33f92 commit 8f9755e

File tree

1 file changed

+132
-9
lines changed

1 file changed

+132
-9
lines changed

src/Resource/Orders.php

+132-9
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ protected function initialize()
118118
$this->data->amount->subtotals = new stdClass();
119119
$this->data->items = [];
120120
$this->data->receivers = [];
121+
$this->data->shippingAddress = new stdClass();
121122
$this->data->checkoutPreferences = new stdClass();
122123
$this->data->checkoutPreferences->redirectUrls = new stdClass();
123124
$this->data->checkoutPreferences->installments = [];
@@ -145,24 +146,36 @@ protected function populate(stdClass $response)
145146
$this->orders = clone $this;
146147
$this->orders->data->id = $response->id;
147148
$this->orders->data->ownId = $response->ownId;
149+
$this->orders->data->createdAt = $response->createdAt;
150+
$this->orders->data->updatedAt = $response->updatedAt;
151+
$this->orders->data->amount->paid = $response->amount->paid;
148152
$this->orders->data->amount->total = $response->amount->total;
149153
$this->orders->data->amount->fees = $response->amount->fees;
150154
$this->orders->data->amount->refunds = $response->amount->refunds;
151155
$this->orders->data->amount->liquid = $response->amount->liquid;
152156
$this->orders->data->amount->otherReceivers = $response->amount->otherReceivers;
153157
$this->orders->data->amount->subtotals = $response->amount->subtotals;
154-
158+
$this->orders->data->items = $response->items;
155159
$customer = new Customer($this->moip);
156160
$this->orders->data->customer = $customer->populate($response->customer);
157161

158162
$this->orders->data->payments = $this->structure($response, Payment::PATH, Payment::class);
163+
$this->orders->data->escrows = $this->structure($response, Payment::PATH, Escrow::class);
159164
$this->orders->data->refunds = $this->structure($response, Refund::PATH, Refund::class);
160165
$this->orders->data->entries = $this->structure($response, Entry::PATH, Entry::class);
161166
$this->orders->data->events = $this->structure($response, Event::PATH, Event::class);
162167

163-
$this->orders->data->items = $response->items;
164168
$this->orders->data->receivers = $this->getIfSet('receivers', $response);
165-
$this->orders->data->createdAt = $response->createdAt;
169+
170+
$this->orders->data->shippingAddress->zipCode = $response->shippingAddress->zipCode;
171+
$this->orders->data->shippingAddress->street = $response->shippingAddress->street;
172+
$this->orders->data->shippingAddress->streetNumber = $response->shippingAddress->streetNumber;
173+
$this->orders->data->shippingAddress->complement = $response->shippingAddress->complement;
174+
$this->orders->data->shippingAddress->city = $response->shippingAddress->city;
175+
$this->orders->data->shippingAddress->district = $response->shippingAddress->district;
176+
$this->orders->data->shippingAddress->state = $response->shippingAddress->state;
177+
$this->orders->data->shippingAddress->country = $response->shippingAddress->country;
178+
166179
$this->orders->data->status = $response->status;
167180
$this->orders->data->_links = $response->_links;
168181

@@ -234,6 +247,16 @@ public function getOwnId()
234247
return $this->getIfSet('ownId');
235248
}
236249

250+
/**
251+
* Get paid value of order.
252+
*
253+
* @return int|float
254+
*/
255+
public function getAmountPaid()
256+
{
257+
return $this->getIfSet('paid', $this->data->amount);
258+
}
259+
237260
/**
238261
* Get total value of order.
239262
*
@@ -362,6 +385,86 @@ public function getCustomer()
362385
return $this->data->customer;
363386
}
364387

388+
/**
389+
* Get zipCode of shippingAddress.
390+
*
391+
* @return string
392+
*/
393+
public function getShippingAddressZipCode()
394+
{
395+
return $this->getIfSet('zipCode', $this->data->shippingAddress);
396+
}
397+
398+
/**
399+
* Get street of shippingAddress.
400+
*
401+
* @return string
402+
*/
403+
public function getShippingAddressStreet()
404+
{
405+
return $this->getIfSet('street', $this->data->shippingAddress);
406+
}
407+
408+
/**
409+
* Get streetNumber of shippingAddress.
410+
*
411+
* @return string
412+
*/
413+
public function getShippingAddressStreetNumber()
414+
{
415+
return $this->getIfSet('streetNumber', $this->data->shippingAddress);
416+
}
417+
418+
/**
419+
* Get complement of shippingAddress.
420+
*
421+
* @return string
422+
*/
423+
public function getShippingAddressComplement()
424+
{
425+
return $this->getIfSet('complement', $this->data->shippingAddress);
426+
}
427+
428+
/**
429+
* Get city of shippingAddress.
430+
*
431+
* @return string
432+
*/
433+
public function getShippingAddressCity()
434+
{
435+
return $this->getIfSet('city', $this->data->shippingAddress);
436+
}
437+
438+
/**
439+
* Get district of shippingAddress.
440+
*
441+
* @return string
442+
*/
443+
public function getShippingAddressDistrict()
444+
{
445+
return $this->getIfSet('district', $this->data->shippingAddress);
446+
}
447+
448+
/**
449+
* Get state of shippingAddress.
450+
*
451+
* @return string
452+
*/
453+
public function getShippingAddressState()
454+
{
455+
return $this->getIfSet('state', $this->data->shippingAddress);
456+
}
457+
458+
/**
459+
* Get country of shippingAddress.
460+
*
461+
* @return string
462+
*/
463+
public function getShippingAddressCountry()
464+
{
465+
return $this->getIfSet('country', $this->data->shippingAddress);
466+
}
467+
365468
/**
366469
* Get payments associated with the request.
367470
*
@@ -373,13 +476,33 @@ public function getPaymentIterator()
373476
}
374477

375478
/**
376-
* Get recipient structure of payments.
479+
* Get escrows associated with the request.
377480
*
378481
* @return ArrayIterator
379482
*/
380-
public function getReceiverIterator()
483+
public function getEscrowIterator()
381484
{
382-
return new ArrayIterator($this->data->receivers);
485+
return new ArrayIterator($this->data->escrows);
486+
}
487+
488+
/**
489+
* Get refunds associated with the request.
490+
*
491+
* @return ArrayIterator
492+
*/
493+
public function getRefundIterator()
494+
{
495+
return new ArrayIterator($this->data->refunds);
496+
}
497+
498+
/**
499+
* Get entries associated with the request.
500+
*
501+
* @return ArrayIterator
502+
*/
503+
public function getEntryIterator()
504+
{
505+
return new ArrayIterator($this->data->entries);
383506
}
384507

385508
/**
@@ -393,13 +516,13 @@ public function getEventIterator()
393516
}
394517

395518
/**
396-
* Get repayments associated with the request.
519+
* Get recipient structure of payments.
397520
*
398521
* @return ArrayIterator
399522
*/
400-
public function getRefundIterator()
523+
public function getReceiverIterator()
401524
{
402-
return new ArrayIterator($this->data->refunds);
525+
return new ArrayIterator($this->data->receivers);
403526
}
404527

405528
/**

0 commit comments

Comments
 (0)