Added the ability to send delivery on its way (without payment)
Tags:
Starting from V7Preview3, it is possible to prepare a delivery for dispatch, print the invoice, assign a courier, and send them on their way.
Innovations
- Delivery payment time setting PluginContext.Operations.GetHostDeliverySettings().DeliveryPaymentTimeOption — before sending or before closing. Currently, payment for deliveries via API is not supported, so only sending without payment will work.
- Delivery invoice printing time setting — manually or automatically, and if automatically, at what exact moment: PluginContext.Operations.GetHostDeliverySettings().DeliveryBillPrintTimeOption.
- Preparing delivery for dispatch (changing to “Waiting” status): PluginContext.Operations.PrepareDeliveryForSending(credentials, delivery). Here, working hours and mapping restrictions will be checked, as well as auto-added dishes and services. An optional flag throwOnChanges can be specified to abort the operation in case of changes to the order composition or cost, allowing the plugin to react to changes and check if it wants to send the delivery with these changes. By default, the flag is off, and the plugin agrees to any auto-changes.
- Printing the delivery invoice: PluginContext.Operations.PrintDeliveryBill(credentials, delivery). Delivery stickers will also be printed here if the settings specify printing them along with the invoice.
- Sending delivery on its way: PluginContext.Operations.SendDelivery(credentials, delivery).
- If automatic printing of the delivery invoice is set at the beginning of preparation or upon dispatch, it will be printed when calling the methods PrintOrderItems and SendDelivery from the plugin, respectively.
Example usage
private void CreateAndSendDelivery()
{
if (PluginContext.Operations.GetHostDeliverySettings().DeliveryPaymentTimeOption == DeliveryPaymentTimeOption.BeforeSending)
return; // not supported yet
var credentials = PluginContext.Operations.AuthenticateByPin(pin);
var delivery = CreateDelivery(false); // EditorTester.CreateDelivery method from SamplePlugin
if (PluginContext.Operations.IsDeliveryConfirmationActive())
{
Debug.Assert(delivery.DeliveryStatus == DeliveryStatus.Unconfirmed);
PluginContext.Operations.ChangeDeliveryConfirmTime(DateTime.Now, delivery, credentials);
delivery = PluginContext.Operations.GetDeliveryOrderById(delivery.Id);
}
PluginContext.Operations.PrintOrderItems(credentials, delivery, delivery.Items.OfType<IOrderCookingItem>().ToList());
Debug.Assert(delivery.DeliveryStatus == DeliveryStatus.New);
PluginContext.Operations.PrepareDeliveryForSending(credentials, delivery);
delivery = PluginContext.Operations.GetDeliveryOrderById(delivery.Id);
Debug.Assert(delivery.DeliveryStatus == DeliveryStatus.Waiting);
var courier = PluginContext.Operations.GetUsers().Single(x => x.Name == courierName);
Debug.Assert(delivery.Courier == null);
PluginContext.Operations.ChangeDeliveryCourier(true, delivery, courier, credentials);
delivery = PluginContext.Operations.GetDeliveryOrderById(delivery.Id);
Debug.Assert(Equals(delivery.Courier, courier));
Debug.Assert(!delivery.IsPrintedBillActual);
PluginContext.Operations.PrintDeliveryBill(credentials, delivery);
delivery = PluginContext.Operations.GetDeliveryOrderById(delivery.Id);
Debug.Assert(delivery.IsPrintedBillActual);
PluginContext.Operations.SendDelivery(credentials, delivery);
delivery = PluginContext.Operations.GetDeliveryOrderById(delivery.Id);
Debug.Assert(delivery.DeliveryStatus == DeliveryStatus.OnWay);
}