Skip to content

Commit

Permalink
Merge pull request #7 from workhouse-advertising/feature/shipping-add…
Browse files Browse the repository at this point in the history
…ress

Added an optional shipping address into the data for a RestAuthorizeRequest
  • Loading branch information
alexw23 authored Jan 18, 2021
2 parents aa38e01 + d350eb2 commit 3c4383a
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/Message/RestAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3c4383a

Please sign in to comment.