Exemplo n.º 1
0
 /**
  * Mount the entry.
  *
  * @param \stdClass $response
  *
  * @return Entry Entry information.
  */
 protected function populate(stdClass $response)
 {
     $entry = clone $this;
     $entry->data->id = $this->getIfSet('id', $response);
     $entry->data->status = $this->getIfSet('status', $response);
     $entry->data->operation = $this->getIfSet('operation', $response);
     if (isset($response->amount)) {
         $entry->data->amount->total = $this->getIfSet('total', $response->amount);
         $entry->data->amount->fee = $this->getIfSet('fee', $response->amount);
         $entry->data->amount->liquid = $this->getIfSet('liquid', $response->amount);
         $entry->data->amount->currency = $this->getIfSet('currency', $response->amount);
     }
     if (isset($response->details)) {
         $entry->data->details = $this->getIfSet('details', $response);
     }
     if (isset($response->{'parent'}) && isset($response->{'parent'}->payments)) {
         $payments = new Payment($entry->moip);
         $payments->populate($response->{'parent'}->payments);
         $entry->data->parentPayments = $payments;
     }
     return $entry;
 }
Exemplo n.º 2
0
 /**
  * Mount the structure of order.
  * 
  * @param \stdClass $response
  *
  * @return \stdClass Response order.
  */
 protected function populate(stdClass $response)
 {
     $orders = clone $this;
     $orders->data->id = $response->id;
     $orders->data->amount->total = $response->amount->total;
     $orders->data->amount->fees = $response->amount->fees;
     $orders->data->amount->refunds = $response->amount->refunds;
     $orders->data->amount->liquid = $response->amount->liquid;
     $orders->data->amount->otherReceivers = $response->amount->otherReceivers;
     $orders->data->amount->subtotals = $response->amount->subtotals;
     $orders->data->customer = new Customer($orders->moip);
     $orders->data->customer->populate($response->customer);
     if (isset($response->payments)) {
         $orders->data->payments = array();
         foreach ($response->payments as $responsePayment) {
             $payment = new Payment($orders->moip);
             $payment->populate($responsePayment);
             $payment->setOrder($this);
             $orders->data->payments[] = $payment;
         }
     }
     if (isset($response->refunds)) {
         $orders->data->refunds = array();
         foreach ($response->refunds as $responseRefund) {
             $refund = new Refund($orders->moip);
             $refund->populate($responseRefund);
             $orders->data->refunds[] = $refund;
         }
     }
     if (isset($response->entries)) {
         $orders->data->entries = array();
         foreach ($response->entries as $responseEntry) {
             $entry = new Entry($orders->moip);
             $entry->populate($responseEntry);
             $orders->data->entries[] = $entry;
         }
     }
     if (isset($response->events)) {
         $orders->data->events = array();
         foreach ($response->events as $responseEvent) {
             $event = new Event($orders->moip);
             $event->populate($responseEvent);
             $orders->data->events[] = $event;
         }
     }
     $orders->data->items = $response->items;
     $orders->data->receivers = $response->receivers;
     $orders->data->createdAt = $response->createdAt;
     $orders->data->_links = $response->_links;
     return $orders;
 }