Skip to content

Commit

Permalink
Fixed minor issues. Update order service response.
Browse files Browse the repository at this point in the history
  • Loading branch information
milindsingh committed Dec 9, 2019
1 parent f148fa4 commit 2126ca8
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Starshipit/Handler/DateTimeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function deserializeDateTimeFromJson(JsonDeserializationVisitor $visitor,
*/
public function serializeDateTimeToJson(JsonSerializationVisitor $visitor, $data, array $type)
{
return $data->format($type['params'][0]);
return $data instanceof \DateTimeInterface ? $data->format($type['params'][0]) : $data;
}
}

24 changes: 24 additions & 0 deletions src/Starshipit/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class Address
*/
protected $delivery_instructions;

/**
* @var string
*/
protected $city;


/**
* @return string
Expand Down Expand Up @@ -217,6 +222,25 @@ public function setState($state)
return $this;
}

/**
* @return string
*/
public function getCity()
{
return $this->city;
}

/**
* @param string $city
* @return $this
*/
public function setCity($city)
{
$this->city = $city;

return $this;
}

/**
* @return string
*/
Expand Down
53 changes: 50 additions & 3 deletions src/Starshipit/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,32 @@ class Order
* @var string
*/
protected $success;

/**
* @var string
*/
protected $errors;

/**
* @var string
* @var OrderDetails
*/
protected $order;

/**
* @var string
*/
protected $data;

/**
* @var int
*/
protected $typeId;

/**
* @var string
*/
protected $type;

/**
* @param string $success
* @return $this
Expand Down Expand Up @@ -62,7 +79,7 @@ public function getErrors()
}

/**
* @param string $order
* @param OrderDetails $order
* @return $this
*/
public function setOrder($order)
Expand All @@ -73,11 +90,41 @@ public function setOrder($order)
}

/**
* @return string
* @return OrderDetails
*/
public function getOrder()
{
return $this->order;
}

public function setData($data)
{
$this->data = $data;
}

public function getData()
{
return $this->data;
}

public function setType($type)
{
$this->type = $type;
}

public function getType()
{
return $this->type;
}

public function setTypeId($typeId)
{
$this->typeId = $typeId;
}

public function getTypeId()
{
return $this->typeId;
}
}

59 changes: 43 additions & 16 deletions src/Starshipit/Model/OrderDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@ class OrderDetails
*/
protected $tracking_number;

/**
* @var string
*/
protected $country;

/**
* @var bool
*/
protected $return_order;

/**
* @return string
*/
Expand All @@ -100,23 +108,23 @@ public function getOrderId()
}

/**
* @param string OrderId
* @param string $orderId
* @return $this
*/
public function setOrderId($order_id)
public function setOrderId($orderId)
{
$this->order_id = $order_id;

return $this;
}

/**
* @param string $OrderDate
* @param string $date
* @return $this
*/
public function setOrderDate($order_date)
public function setOrderDate($date)
{
$this->order_date = $order_date;
$this->order_date = $date;

return $this;
}
Expand All @@ -130,12 +138,12 @@ public function getOrderDate()
}

/**
* @param string $OrderNumber
* @param string $orderNumber
* @return $this
*/
public function setOrderNumber($order_number)
public function setOrderNumber($orderNumber)
{
$this->order_number = $order_number;
$this->order_number = $orderNumber;

return $this;
}
Expand Down Expand Up @@ -282,24 +290,43 @@ public function getShippingMethod()
}

/**
* @param string $SignatureRequired
* @param boolean $required
* @return $this
*/
public function setSignatureRequired($signature_required)
public function setSignatureRequired($required)
{
$this->signature_required = $signature_required;
$this->signature_required = $required;

return $this;
}

/**
* @return string
* @return boolean
*/
public function getSignatureRequired()
{
return $this->signature_required;
}

/**
* @param boolean $flag
* @return $this
*/
public function setReturnOrder($flag)
{
$this->return_order = $flag;

return $this;
}

/**
* @return boolean
*/
public function getReturnOrder()
{
return $this->return_order;
}

/**
* @param string $Currency
* @return $this
Expand Down Expand Up @@ -343,15 +370,15 @@ public function getSenderDetails()
}

/**
* @return string
* @return Address
*/
public function getDestination()
{
return $this->destination;
}

/**
* @param string $Destination
* @param Address $destination
* @return $this
*/
public function setDestination($destination)
Expand All @@ -362,15 +389,15 @@ public function setDestination($destination)
}

/**
* @return string
* @return Item[]
*/
public function getItems()
{
return $this->items;
}

/**
* @param string $Items
* @param Item[] $items
* @return $this
*/
public function setItems(array $items)
Expand Down
2 changes: 2 additions & 0 deletions src/Starshipit/Serializer/Starshipit.Model.Address.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Starshipit\Model\Address:
type: string
suburb:
type: string
city:
type: string
state:
type: string
post_code:
Expand Down
5 changes: 4 additions & 1 deletion src/Starshipit/Serializer/Starshipit.Model.Order.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Starshipit\Model\Order:
properties:
success:
type: int
type: boolean
errors:
type: array<Starshipit\Model\Error>
order:
type: Starshipit\Model\OrderDetails
serialized_name: order
data:
type: array
serialized_name: order

5 changes: 4 additions & 1 deletion src/Starshipit/Serializer/Starshipit.Model.OrderDetails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Starshipit\Model\OrderDetails:
order_date:
type: DateTime<'Y-m-d\TH:i:s.u\Z'>
order_number:
type: int
type: string
reference:
type: string
carrier:
Expand Down Expand Up @@ -40,4 +40,7 @@ Starshipit\Model\OrderDetails:
metadatas:
type: array<Starshipit\Model\Metadata>
serialized_name: metadatas
return_order:
type: boolean
serialized_name: return_order

20 changes: 18 additions & 2 deletions src/Starshipit/Service/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(ClientInterface $client, Authorization $authorizatio
public function post(OrderModel $order)
{
try {
$body = $this->getSerializer()->serialize($order, 'json');
$result = $this->getClient()->post(
'orders',
[
Expand All @@ -54,7 +55,7 @@ public function post(OrderModel $order)
'Ocp-Apim-Subscription-Key' => $this->getAuthorization()->getSubscriptionKey(),
'User-Agent' => $this->getAuthorization()->getUserAgent(),
],
'body' => $this->getSerializer()->serialize($order, 'json'),
'body' => $body,
]
);
} catch (BadResponseException $exception) {
Expand All @@ -68,11 +69,26 @@ public function post(OrderModel $order)
);
}

return $this->getSerializer()->deserialize(
$data = json_decode($body, true);
$typeId = $order->getTypeId();
$type = $order->getType();

/** @var OrderModel $order */
$order = $this->getSerializer()->deserialize(
(string) $result->getBody(),
OrderModel::class,
'json'
);

// Maintaining old data incase of failure
$current = $order->getData();
if (isset($data['order']) && !isset($current['order_id'])) {
$order->setData($data['order']);
}
$order->setType($type);
$order->setTypeId($typeId);

return $order;
}

/**
Expand Down

0 comments on commit 2126ca8

Please sign in to comment.