/** * 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); }
/** * 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); }