public virtual ActionResult ConfirmSale(CheckoutConfirmationForm model) { if (!ModelState.IsValid) { return(this.CurrentUmbracoPage()); } // Get the invoice number prefix from the App_Settings and modify the settings if the setting is not // null or whitespace var settings = new CheckoutContextSettings() { InvoiceNumberPrefix = WebConfigurationManager.AppSettings["Bazaar:InvoiceNumberPrefix"] }; // Get all the managers we need on this page var checkoutManager = Basket.GetCheckoutManager(settings); var customerManager = checkoutManager.Customer; var shippingManager = checkoutManager.Shipping; var paymentManager = checkoutManager.Payment; // Clear Shipment Rate Quotes shippingManager.ClearShipmentRateQuotes(); // Get the shipping address var shippingAddress = customerManager.GetShipToAddress(); // Get the shipment again var shipment = Basket.PackageBasket(shippingAddress).FirstOrDefault(); // get the quote using the "approved shipping method" var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipMethodKey); // save the quote shippingManager.SaveShipmentRateQuote(quote); var paymentMethod = GatewayContext.Payment.GetPaymentGatewayMethodByKey(model.PaymentMethodKey).PaymentMethod; paymentManager.SavePaymentMethod(paymentMethod); // AuthorizePayment will save the invoice with an Invoice Number. var attempt = this.PerformProcessPayment(checkoutManager, paymentMethod); if (!attempt.Payment.Success) { return(this.CurrentUmbracoPage()); } // store the invoice key in the CustomerContext for use on the receipt page. CustomerContext.SetValue("invoiceKey", attempt.Invoice.Key.ToString()); return(FinalizeSale(model, attempt)); }
public void Can_Show_Customer_Addresses_Are_Not_Cleared_After_VersionReset_WithCustomSettings() { //// Arrange var shipping = MockAddressMaker.GetAddress(); var billing = MockAddressMaker.GetAddress(); var settings = new CheckoutContextSettings() { ResetCustomerManagerDataOnVersionChange = false }; var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager(); checkoutManager.Customer.SaveShipToAddress(shipping); checkoutManager.Customer.SaveBillToAddress(billing); //// Act CurrentCustomer.Basket().AddItem(_product1, 10); this.CurrentCustomer.Basket().Save(); Assert.NotNull(this.CurrentCustomer.Basket().GetCheckoutManager(settings).Customer.GetShipToAddress()); Assert.NotNull(this.CurrentCustomer.Basket().GetCheckoutManager(settings).Customer.GetBillToAddress()); }
public ActionResult ConfirmSale(CheckoutConfirmationForm model) { if (!ModelState.IsValid) { return(this.CurrentUmbracoPage()); } // Get the invoice number prefix from the App_Settings and modify the settings if the setting is not // null or whitespace var settings = new CheckoutContextSettings() { InvoiceNumberPrefix = WebConfigurationManager.AppSettings["Bazaar:InvoiceNumberPrefix"] }; // Get all the managers we need on this page var checkoutManager = Basket.GetCheckoutManager(settings); var customerManager = checkoutManager.Customer; var shippingManager = checkoutManager.Shipping; var paymentManager = checkoutManager.Payment; // Clear Shipment Rate Quotes shippingManager.ClearShipmentRateQuotes(); // Get the shipping address var shippingAddress = customerManager.GetShipToAddress(); // Get the shipment again var shipment = Basket.PackageBasket(shippingAddress).FirstOrDefault(); // get the quote using the "approved shipping method" var quote = shipment.ShipmentRateQuoteByShipMethod(model.ShipMethodKey); // save the quote shippingManager.SaveShipmentRateQuote(quote); var paymentMethod = GatewayContext.Payment.GetPaymentGatewayMethodByKey(model.PaymentMethodKey).PaymentMethod; paymentManager.SavePaymentMethod(paymentMethod); // AuthorizePayment will save the invoice with an Invoice Number. var attempt = this.PerformProcessPayment(checkoutManager, paymentMethod); if (!attempt.Payment.Success) { return(this.CurrentUmbracoPage()); } // Trigger the order confirmation notification var billingAddress = attempt.Invoice.GetBillingAddress(); string contactEmail; if (string.IsNullOrEmpty(billingAddress.Email) && !CurrentCustomer.IsAnonymous) { contactEmail = ((ICustomer)CurrentCustomer).Email; } else { contactEmail = billingAddress.Email; } if (!string.IsNullOrEmpty(contactEmail)) { Notification.Trigger("OrderConfirmation", attempt, new[] { contactEmail }); } // store the invoice key in the CustomerContext for use on the receipt page. CustomerContext.SetValue("invoiceKey", attempt.Invoice.Key.ToString()); return(RedirectToUmbracoPage(model.ReceiptPageId)); }