From b9c4ff77ee7515750be45000c13b9bac70513bd4 Mon Sep 17 00:00:00 2001 From: Simon Geoghegan Date: Wed, 2 Dec 2020 12:59:33 +0800 Subject: [PATCH 1/2] Added an optional shipping address into the data for a RestAuthorizeRequest --- src/Message/RestAuthorizeRequest.php | 53 +++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index f9c8d3a..3524f0f 100644 --- a/src/Message/RestAuthorizeRequest.php +++ b/src/Message/RestAuthorizeRequest.php @@ -77,6 +77,11 @@ public function hasMetaData() return !empty($this->getMeta()); } + public function hasShippingAddress() + { + return !empty($this->getShippingAddressLine1()); + } + public function getData() { $this->validate( @@ -153,9 +158,25 @@ protected function convertItemToItemData(ItemInterface $item) public function getOrderShippingDetails() { - return [ + $shippingDetails = [ 'pickup' => true, ]; + // Check for a shipping address and set pickup to `false` and add the address + // details if one has been supplied. + if ($this->hasShippingAddress()) { + $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 +226,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); From d350eb286eb8d433f277f2ab00783fd6a73d2026 Mon Sep 17 00:00:00 2001 From: Simon Geoghegan Date: Tue, 12 Jan 2021 11:34:37 +0800 Subject: [PATCH 2/2] Updated the shipping address check to use a request parameter --- src/Message/RestAuthorizeRequest.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php index 3524f0f..9bf7c6b 100644 --- a/src/Message/RestAuthorizeRequest.php +++ b/src/Message/RestAuthorizeRequest.php @@ -77,9 +77,14 @@ public function hasMetaData() return !empty($this->getMeta()); } - public function hasShippingAddress() + public function getHasShippingAddress() { - return !empty($this->getShippingAddressLine1()); + return $this->getParameter('hasShippingAddress'); + } + + public function setHasShippingAddress($value) + { + return $this->setParameter('hasShippingAddress', $value); } public function getData() @@ -161,9 +166,9 @@ public function getOrderShippingDetails() $shippingDetails = [ 'pickup' => true, ]; - // Check for a shipping address and set pickup to `false` and add the address - // details if one has been supplied. - if ($this->hasShippingAddress()) { + // 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' => [