/** * Checks path that will be the request. * * @return string */ private function getPath() { if ($this->order !== null) { return sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Orders::PATH, $this->order->getId(), self::PATH); } return sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Payment::PATH, $this->payment->getId(), self::PATH); }
/** * 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; }
/** * Get iterator. * * @return \ArrayIterator */ public function getIterator() { $httpConnection = $this->createConnection(); $httpConnection->addHeader('Content-Type', 'application/json'); if ($this->order !== null) { $path = sprintf('/v2/orders/%s/refunds', $this->order->getId()); } else { $path = sprintf('/v2/payments/%s/refunds', $this->payment->getId()); } $httpResponse = $httpConnection->execute($path, HTTPRequest::GET); if ($httpResponse->getStatusCode() != 200) { throw new RuntimeException($httpResponse->getStatusMessage(), $httpResponse->getStatusCode()); } $response = json_decode($httpResponse->getContent()); $refunds = array(); foreach ($response->refunds as $refund) { $refunds[] = $this->populate($refund); } return new ArrayIterator($refunds); }
/** * Structure of multipayments. * * @return \Moip\Resource\Payment */ public function multipayments() { $payments = new Payment($this->moip); $payments->setMultiorder($this); return $payments; }
/** * Structure of payment. * * @return \Moip\Resource\Payment */ public function payments() { $payment = new Payment($this->moip); $payment->setOrder($this); return $payment; }