Exemplo n.º 1
0
        /// <summary>
        /// Cancel this order.
        /// </summary>
        /// <param name="voidPayments">If true, any payments in a voidable state will have be voided.</param>
        public void Cancel(bool voidPayments)
        {
            //VOID ANY INCOMPLETED PAYMENTS
            if (voidPayments)
            {
                int paymentCount = this.Payments.Count;
                for (int i = 0; i < paymentCount; i++)
                {
                    Payment payment = this.Payments[i];
                    if (payment.IsVoidable)
                    {
                        payment.Void();
                    }
                }
            }
            // CANCEL ANY TAXES FROM INTEGRATED PROVIDERS
            TaxGatewayCollection taxGateways = Token.Instance.Store.TaxGateways;

            foreach (TaxGateway taxGateway in taxGateways)
            {
                ITaxProvider provider = taxGateway.GetProviderInstance();
                if (provider != null)
                {
                    try
                    {
                        provider.Cancel(this);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Could not cancel with the configured tax provider: " + taxGateway.ClassId, ex);
                    }
                }
                else
                {
                    Logger.Error("Could not load the configured tax provider: " + taxGateway.ClassId);
                }
            }
            //TRIGGER THE ORDER CANCELLED EVENT
            StoreEventEngine.OrderCancelled(this);
        }