/** * @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 Customer $originator * @param Customer $receiver * @param string $link * @return \AlistairShaw\Vendirun\App\Lib\VendirunApi\Base\VendirunResponse */ public function recommendFriend(Customer $originator, Customer $receiver, $link) { $params = ['originator_id' => $originator->getId(), 'receiver_id' => $receiver->getId(), 'link' => $link]; return VendirunApi::makeRequest('customer/recommendFriend', $params); }