public function makePayload(\FS\Components\Order\ShoppingOrder $order) { $payload = array(); $settings = $this->getApplicationContext()->getComponent('\\FS\\Components\\Settings'); $shipment = $order->getFlagShipRaw(); $service = $order->getShippingService(); // shipment created if ($shipment) { $payload['type'] = 'created'; $payload['shipment'] = $shipment; return $payload; } // quoted but no shipment created if (!$shipment && $service['provider'] == $settings['FLAGSHIP_SHIPPING_PLUGIN_ID']) { $payload['type'] = 'create'; $payload['service'] = $service; $payload['cod'] = array('currency' => strtoupper(get_woocommerce_currency())); } // possibly not quoted with FS if (!isset($payload['type'])) { $payload['type'] = 'unavailable'; } // requotes if ($requoteRates = $order->getAttribute('flagship_shipping_requote_rates')) { $payload['requote_rates'] = $requoteRates; } return $payload; }
public function voidShipment(\FS\Components\Order\ShoppingOrder $order) { $options = $this->getApplicationContext()->getComponent('\\FS\\Components\\Options'); $notifier = $this->getApplicationContext()->getComponent('\\FS\\Components\\Notifier'); $shipment = $order->getAttribute('flagship_shipping_raw'); $shipmentId = $order->getAttribute('flagship_shipping_shipment_id'); if (!$shipment || !$shipmentId) { $notifier->warning(sprintf('Unable to access shipment with FlagShip ID (%s)', $shipmentId)); return; } $client = $this->getApplicationContext()->getComponent('\\FS\\Components\\Http\\Client'); $response = $client->delete('/ship/shipments/' . $shipmentId); if (!$response->isSuccessful()) { $notifier->warning(sprintf('Unable to void shipment with FlagShip ID (%s)', $shipmentId)); return; } if (empty($shipment['pickup'])) { $order->deleteAttribute('flagship_shipping_raw'); return; } $this->voidPickup($order); $order->deleteAttribute('flagship_shipping_raw'); }