/**
  * @param $order
  * @return Order
  */
 public function fromApi($order)
 {
     $billingAddress = new Address(['id' => $order->billing_address->id, 'address1' => $order->billing_address->address1, 'address2' => $order->billing_address->address2, 'address3' => $order->billing_address->address3, 'city' => $order->billing_address->city, 'state' => $order->billing_address->state, 'postcode' => $order->billing_address->postcode, 'countryId' => $order->billing_address->country_id]);
     $shippingAddress = new Address(['id' => $order->shipping_address->id, 'address1' => $order->shipping_address->address1, 'address2' => $order->shipping_address->address2, 'address3' => $order->shipping_address->address3, 'city' => $order->shipping_address->city, 'state' => $order->shipping_address->state, 'postcode' => $order->shipping_address->postcode, 'countryId' => $order->shipping_address->country_id]);
     // customer
     $customer = new Customer($order->customer_id, Name::fromFullName($order->customer_id ? $order->customer->fullname : $order->guest_full_name));
     $customer->setJobRole($order->customer_id ? $order->customer->jobrole : $order->guest_jobrole);
     $customer->setPrimaryEmail($order->customer_id ? $order->customer->primary_email : $order->guest_email);
     $customer->setCompanyName($order->customer_id ? $order->customer->organisation_name : $order->guest_company_name);
     $customer->setTaxNumber($order->customer_id ? $order->customer->tax_number : $order->guest_tax_number);
     // order items
     $items = [];
     foreach ($order->items as $item) {
         $items[] = new OrderItem($item->id, $item->product_variation_id, $item->tax_rate, $item->price, $item->quantity, $item->product_name, $item->product_sku, $item->is_shipping, $item->discount_amount);
     }
     $vrOrder = new Order($customer, $billingAddress, $shippingAddress, $items, null, $order->id, $order->created);
     // add the payments
     foreach ($order->payments as $payment) {
         $vrOrder->addPayment(new Payment($payment->payment_amount, $payment->created, $payment->payment_type, $payment->transaction_data, $payment->id));
     }
     // shipments
     $shipmentFactory = new ShipmentFactory();
     foreach ($order->shipments as $shipment) {
         $vrOrder->addShipment($shipmentFactory->fromApi($shipment, $vrOrder));
     }
     return $vrOrder;
 }
 /**
  * @param $shipment
  * @param Order $order
  * @return Shipment
  */
 public function fromApi($shipment, Order $order)
 {
     $deliveryWindowDate = DateWindow::make($shipment->expected_delivery_date_start, $shipment->expected_delivery_date_end);
     $deliveryWindowTime = TimeWindow::make($shipment->expected_delivery_time_start, $shipment->expected_delivery_time_end);
     $vrShipment = new Shipment($shipment->shipped_at, $shipment->shipping_company, $deliveryWindowDate, $deliveryWindowTime, $shipment->tracking_number, $shipment->tracking_url);
     foreach (explode(",", $shipment->order_items) as $orderItemId) {
         $item = $order->getItemById($orderItemId);
         $vrShipment->addItem($item);
     }
     return $vrShipment;
 }
 /**
  * @param Order $order
  * @return array
  */
 private function compose_payments(Order $order)
 {
     $payments = [];
     foreach ($order->getPayments() as $payment) {
         /* @var $payment Payment */
         $pd = $payment->getArray();
         $payments[] = ['id' => $payment->getId(), 'payment_amount' => $pd['amount'], 'payment_date' => $pd['paymentDate'], 'transaction_data' => $pd['transactionData'], 'payment_type' => $pd['paymentType']];
     }
     return $payments;
 }
 /**
  * @param Order|null $order
  * @return array
  */
 private function orderBreadcrumbs(Order $order = null)
 {
     $breadcrumbs = $this->homeCrumb();
     $breadcrumbs[] = ['title' => trans('vendirun::customer.account'), 'slug' => 'customer/account'];
     $breadcrumbs[] = ['title' => trans('vendirun::product.orderHistory'), 'slug' => 'customer/account/orders'];
     if ($order) {
         $breadcrumbs[] = ['title' => trans('vendirun::customer.account'), 'slug' => 'customer/account/orders/order/view/' . $order->getId()];
     }
     return $breadcrumbs;
 }
 /**
  * @param Order $order
  * @return \Illuminate\Http\RedirectResponse
  */
 private function noPaymentNecessary(Order $order)
 {
     return Redirect::route('vendirun.checkoutSuccess', ['orderId' => $order->getId()]);
 }