diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index f9c8d3a..9bf7c6b 100644 --- a/src/Message/RestAuthorizeRequest.php +++ b/src/Message/RestAuthorizeRequest.php @@ -77,6 +77,16 @@ public function hasMetaData() return !empty($this->getMeta()); } + public function getHasShippingAddress() + { + return $this->getParameter('hasShippingAddress'); + } + + public function setHasShippingAddress($value) + { + return $this->setParameter('hasShippingAddress', $value); + } + public function getData() { $this->validate( @@ -153,9 +163,25 @@ protected function convertItemToItemData(ItemInterface $item) public function getOrderShippingDetails() { - return [ + $shippingDetails = [ 'pickup' => true, ]; + // Check if a shipping address has supposedly been supplied and, if so, set pickup + // to `false` and add the address details. + if ($this->getHasShippingAddress()) { + $shippingDetails = [ + 'pickup' => false, + 'address' => [ + 'line1' => $this->getShippingAddressLine1(), + 'line2' => $this->getShippingAddressLine2(), + 'city' => $this->getShippingAddressCity(), + 'state' => $this->getShippingAddressState(), + 'postal_code' => $this->getShippingAddressPostalCode(), + 'country' => $this->getShippingAddressCountry(), + ], + ]; + } + return $shippingDetails; } public function getConfig() @@ -205,6 +231,36 @@ public function getBillingAddressLastName() return $this->getCard()->getBillingLastName(); } + public function getShippingAddressLine1() + { + return $this->getCard()->getShippingAddress1(); + } + + public function getShippingAddressLine2() + { + return $this->getCard()->getShippingAddress2(); + } + + public function getShippingAddressCity() + { + return $this->getCard()->getShippingCity(); + } + + public function getShippingAddressState() + { + return $this->getCard()->getShippingState(); + } + + public function getShippingAddressPostalCode() + { + return $this->getCard()->getShippingPostcode(); + } + + public function getShippingAddressCountry() + { + return $this->getCard()->getShippingCountry(); + } + protected function createResponse($data, $headers = [], $status = 404) { return $this->response = new RestAuthorizeResponse($this, $data, $headers, $status);