コード例 #1
0
ファイル: Payment.php プロジェクト: moip/moip-sdk-php
 /**
  * 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);
 }
コード例 #2
0
ファイル: Refund.php プロジェクト: filpgame/moip-sdk-php
 /**
  * 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);
 }
コード例 #3
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()));
 }
コード例 #4
0
ファイル: Refund.php プロジェクト: kassyn/moip-sdk-php
 /**
  * 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);
 }