Ejemplo n.º 1
0
        public bool FinalizeBackofficeOrder(BackofficeAddItemModel model)
        {
            _customer   = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            // This check asserts that we have enough
            // this should be handled a bit nicer for the customer.
            if (!_backoffice.SalePreparation().IsReadyToInvoice())
            {
                return(false);
            }

            var preparation = _backoffice.SalePreparation();

            // Get the shipment again
            var shippingAddress = _backoffice.SalePreparation().GetShipToAddress();

            var shipment = _backoffice.PackageBackoffice(shippingAddress).FirstOrDefault();

            // Clear any previously saved quotes (eg. the user went back to their basket and started the process over again).
            _backoffice.SalePreparation().ClearShipmentRateQuotes();

            // get the quote using the "approved shipping method"
            var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipmentKey);

            // save the quote
            _backoffice.SalePreparation().SaveShipmentRateQuote(quote);

            // for cash providers we only want to authorize the payment
            var paymentMethod = _backoffice.SalePreparation().GetPaymentMethod();

            IPaymentResult attempt;

            if (Merchello.Core.Constants.ProviderKeys.Payment.CashPaymentProviderKey == new Guid(model.PaymentProviderKey))
            {
                // AuthorizePayment will save the invoice with an Invoice Number.
                //
                attempt = preparation.AuthorizePayment(new Guid(model.PaymentKey));
            }
            else // we
            {
                // TODO wire in redirect to Credit Card view or PayPal ... etc.
                throw new NotImplementedException();
            }

            _backoffice.Empty();
            _backoffice.Save();

            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the <see cref="IBackofficeSalePreparation"/>
 /// </summary>
 /// <param name="backoffice">The backoffice with items use in the checkout</param>
 /// <returns>A <see cref="IBackofficeSalePreparation"/></returns>
 internal static BackofficeSalePreparation SalePreparation(this IBackoffice backoffice)
 {
     return(backoffice.SalePreparation(MerchelloContext.Current));
 }
Ejemplo n.º 3
0
        public bool FinalizeBackofficeOrder(BackofficeAddItemModel model)
        {
            _customer = MerchelloContext.Services.CustomerService.GetAnyByKey(new Guid(model.CustomerKey));
            _backoffice = _customer.Backoffice();

            // This check asserts that we have enough
            // this should be handled a bit nicer for the customer.
            if (!_backoffice.SalePreparation().IsReadyToInvoice()) return false;

            var preparation = _backoffice.SalePreparation();

            // Get the shipment again
            var shippingAddress = _backoffice.SalePreparation().GetShipToAddress();

            var shipment = _backoffice.PackageBackoffice(shippingAddress).FirstOrDefault();

            // Clear any previously saved quotes (eg. the user went back to their basket and started the process over again).
            _backoffice.SalePreparation().ClearShipmentRateQuotes();

            // get the quote using the "approved shipping method"
            var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipmentKey);

            // save the quote
            _backoffice.SalePreparation().SaveShipmentRateQuote(quote);

            // for cash providers we only want to authorize the payment
            var paymentMethod = _backoffice.SalePreparation().GetPaymentMethod();

            IPaymentResult attempt;

            if (Merchello.Core.Constants.ProviderKeys.Payment.CashPaymentProviderKey == new Guid(model.PaymentProviderKey))
            {
                // AuthorizePayment will save the invoice with an Invoice Number.
                //
                attempt = preparation.AuthorizePayment(new Guid(model.PaymentKey));
            }
            else // we
            {
                // TODO wire in redirect to Credit Card view or PayPal ... etc.
                throw new NotImplementedException();
            }

            _backoffice.Empty();
            _backoffice.Save();

            return true;
        }