Skip to content

Commit

Permalink
Return a sales order entity from the OrderDetailsService
Browse files Browse the repository at this point in the history
  • Loading branch information
imkingdavid committed Jun 28, 2021
1 parent 0ed4321 commit 075faf2
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/SubscribePro/Service/OrderDetails/OrderDetailsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace SubscribePro\Service\OrderDetails;

use SubscribePro\Service\AbstractService;
use SubscribePro\Service\SalesOrder\SalesOrderFactory;
use SubscribePro\Service\SalesOrder\SalesOrderService;

class OrderDetailsService extends AbstractService
{
const NAME = 'order_details';

CONST API_NAME_ORDER_DETAILS = 'order_details';
const API_NAME_ORDER_DETAILS = 'order_details';
const API_NAME_SALES_ORDER = 'sales_order';

/**
* @param array $orderDetails
Expand All @@ -28,7 +31,8 @@ public function saveNewOrderDetails(OrderDetails $orderDetails)
$response = $this->httpClient->post('/services/v2/order-details.json', [
self::API_NAME_ORDER_DETAILS => $orderDetails->getOrderDetails(),
]);
return $this->retrieveItem($response, self::API_NAME_ORDER_DETAILS);
$salesOrderFactory = new SalesOrderFactory('\SubscribePro\Service\SalesOrder\SalesOrder');
return $salesOrderFactory->create($response[self::API_NAME_SALES_ORDER]);
}

/**
Expand All @@ -40,6 +44,7 @@ public function saveNewOrUpdateExistingOrderDetails(OrderDetails $orderDetails)
$response = $this->httpClient->post('services/v2/order-details/create-or-update.json', [
self::API_NAME_ORDER_DETAILS => $orderDetails->getOrderDetails(),
]);
return $this->retrieveItem($response, self::API_NAME_ORDER_DETAILS);;
$salesOrderFactory = new SalesOrderFactory('\SubscribePro\Service\SalesOrder\SalesOrder');
return $salesOrderFactory->create($response[self::API_NAME_SALES_ORDER]);
}
}
184 changes: 184 additions & 0 deletions src/SubscribePro/Service/SalesOrder/SalesOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php

namespace SubscribePro\Service\SalesOrder;

use SubscribePro\Service\DataObject;

class SalesOrder extends DataObject implements SalesOrderInterface
{
/**
* @return string|null
*/
public function getId()
{
return $this->getData(self::ID);
}
/**
* @param string $id
* @return $this
*/
public function setId($id)
{
return $this->setData(self::ID, (int) $id);
}

/**
* @return SubscribePro\Service\DataInterface|null
*/
public function getCustomer()
{
return $this->getData(self::CUSTOMER);
}
/**
* @param SubscribePro\Service\DataInterface $customer
* @return $this
*/
public function setCustomer(\SubscribePro\Service\DataInterface $customer)
{
return $this->setData(self::CUSTOMER, $customer);
}

/**
* @return bool
*/
public function getIsSubscriptionOrder()
{
return $this->getData(self::IS_SUBSCRIPTION_ORDER);
}
/**
* @param $bool $isSubscriptionOrder
* @return $this
*/
public function setIsSubscriptionOrder($isSubscriptionOrder = false)
{
return $this->setData(self::IS_SUBSCRIPTION_ORDER, (bool) $isSubscriptionOrder);
}

/**
* @return string|null
*/
public function getOrderNumber()
{
return $this->getData(self::ORDER_NUMBER);
}
/**
* @param string $orderNumber
* @return $this
*/
public function setOrderNumber($orderNumber = '')
{
return $this->setData(self::ORDER_NUMBER, $orderNumber);
}

/**
* @return string|null
*/
public function getOrderStatus()
{
return $this->getData(self::ORDER_STATUS);
}
/**
* @param string $orderStatus
* @return $this
*/
public function setOrderStatus($orderStatus = '')
{
return $this->setData(self::ORDER_STATUS, $orderStatus);
}

/**
* @return string|null
*/
public function getOrderDateTime()
{
return $this->getData(self::ORDER_DATE_TIME);
}
/**
* @param string $orderDateTime
* @return $this
*/
public function setOrderDateTime($orderDateTime = '')
{
return $this->setData(self::ORDER_DATE_TIME, $orderDateTime);
}

/**
* @return string|null
*/
public function getTotal()
{
return $this->getData(self::TOTAL);
}
/**
* @param string $total
* @return $this
*/
public function setTotal($total = '')
{
return $this->setData(self::TOTAL, $total);
}

/**
* @return array|null
*/
public function getItems()
{
return $this->getData(self::ITEMS);
}
/**
* @param array $items
* @return $this
*/
public function setItems($items = [])
{
return $this->setData(self::ITEMS, $items);
}

/**
* @return array|null
*/
public function getSubscriptions()
{
return $this->getData(self::SUBSCRIPTIONS);
}
/**
* @param array $subscriptions
* @return $this
*/
public function setSubscriptions($subscriptions = [])
{
return $this->setData(self::SUBSCRIPTIONS, $subscriptions);
}

/**
* @return string|null
*/
public function getCreated()
{
return $this->getData(self::CREATED);
}
/**
* @param string $created
* @return $this
*/
public function setCreated($created = '')
{
return $this->setData(self::CREATED, $created);
}

/**
* @return string|null
*/
public function getUpdated()
{
return $this->getData(self::UPDATED);
}
/**
* @param string $updated
* @return $this
*/
public function setUpdated($updated = '')
{
return $this->setData(self::UPDATED, $updated);
}
}
48 changes: 48 additions & 0 deletions src/SubscribePro/Service/SalesOrder/SalesOrderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace SubscribePro\Service\SalesOrder;

use SubscribePro\Service\DataFactoryInterface;
use SubscribePro\Exception\InvalidArgumentException;

/**
* @codeCoverageIgnore
*/
class SalesOrderFactory implements DataFactoryInterface
{
/**
* @var string
*/
protected $instanceName;

/**
* @param string $instanceName
*/
public function __construct(
$instanceName = '\SubscribePro\Service\SalesOrder\SalesOrder'
) {
if (!is_subclass_of($instanceName, '\SubscribePro\Service\SalesOrder\SalesOrderInterface')) {
throw new InvalidArgumentException("{$instanceName} must implement \\SubscribePro\\Service\\SalesOrder\\SalesOrderInterface.");
}
$this->instanceName = $instanceName;
}

/**
* @param array $data
* @return \SubscribePro\Service\SalesOrder\SalesOrderInterface
*/
public function create(array $data = [])
{
return new $this->instanceName($data);
}

/**
* @param array $data
* @param string $field
* @return mixed[]
*/
protected function getFieldData($data, $field)
{
return !empty($data[$field]) ? $data[$field] : [];
}
}
Loading

0 comments on commit 075faf2

Please sign in to comment.