Example #1
0
 /**
  * Constructs an order instance.
  *
  * @param Connector $connector HTTP transport connector
  * @param string    $orderId   Order ID
  */
 public function __construct(Connector $connector, $orderId = null)
 {
     parent::__construct($connector);
     if ($orderId !== null) {
         $this->setLocation(self::$path . "/{$orderId}");
         $this[static::ID_FIELD] = $orderId;
     }
 }
Example #2
0
 /**
  * Constructs an order instance.
  *
  * @param Connector $connector HTTP transport connector
  * @param string    $orderUrl  Parent order resource url
  * @param string    $captureId Capture ID
  */
 public function __construct(Connector $connector, $orderUrl, $captureId = null)
 {
     parent::__construct($connector);
     $url = $orderUrl . self::$path;
     if ($captureId !== null) {
         $url = "{$url}/{$captureId}";
         $this[static::ID_FIELD] = $captureId;
     }
     $this->setLocation($url);
 }
Example #3
0
 /**
  * Fetches the order.
  *
  * @throws ConnectorException        When the API replies with an error response
  * @throws RequestException          When an error is encountered
  * @throws \RuntimeException         On an unexpected API response
  * @throws \RuntimeException         If the response content type is not JSON
  * @throws \InvalidArgumentException If the JSON cannot be parsed
  * @throws \LogicException           When Guzzle cannot populate the response
  *
  * @return self
  */
 public function fetch()
 {
     parent::fetch();
     // Convert captures data to Capture[]
     $captures = [];
     foreach ($this['captures'] as $capture) {
         $captureId = $capture[Capture::ID_FIELD];
         $object = new Capture($this->connector, $this->getLocation(), $captureId);
         $object->exchangeArray($capture);
         $captures[] = $object;
     }
     $this['captures'] = $captures;
     return $this;
 }