/** * Create a new payment in api MoIP. * * @return $this */ public function execute() { if ($this->order !== null) { $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Orders::PATH, $this->order->getId(), self::PATH); } else { $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Multiorders::PATH, $this->multiorder->getId(), self::MULTI_PAYMENTS_PATH); } $response = $this->httpRequest($path, Requests::POST, $this); return $this->populate($response); }
/** * 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); }
/** * Create a new payment in api MoIP. * * @return $this */ public function execute() { $body = json_encode($this, JSON_UNESCAPED_SLASHES); $httpConnection = $this->createConnection(); $httpConnection->addHeader('Content-Type', 'application/json'); $httpConnection->addHeader('Content-Length', strlen($body)); $httpConnection->setRequestBody($body); if ($this->order !== null) { $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Orders::PATH, $this->order->getId(), self::PATH); } else { $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Multiorders::PATH, $this->multiorder->getId(), Multiorders::PATH); } $httpResponse = $httpConnection->execute($path, HTTPRequest::POST); if ($httpResponse->getStatusCode() != 200 && $httpResponse->getStatusCode() != 201) { throw new RuntimeException($httpResponse->getStatusMessage(), $httpResponse->getStatusCode()); } $response = json_decode($httpResponse->getContent()); if (!is_object($response)) { throw new UnexpectedValueException('O servidor enviou uma resposta inesperada'); } return $this->populate(json_decode($httpResponse->getContent())); }
/** * 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); }