Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
 /**
  * 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()));
 }