public ManagerResponse <SubmitVisitorOrderResult, Order> SubmitVisitorOrder(Cart cart) { var request = new SubmitVisitorOrderRequest(cart); try { SubmitVisitorOrderResult visitorOrderResult = this.orderServiceProvider.SubmitVisitorOrder(request); SubmitVisitorOrderResult serviceProviderResult = visitorOrderResult; return(new ManagerResponse <SubmitVisitorOrderResult, Order>( serviceProviderResult, serviceProviderResult.Order)); } catch (Exception ex) { Log.Error(ex.Message, ex, this); // ToDo: fix issues during order submitting: down there: temp implementation of the submit result if (this.TryResolveSubmittedOrder(cart, out ManagerResponse <SubmitVisitorOrderResult, Order> managerResponse)) { return(managerResponse); } throw; } }
public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder(string userId, SubmitOrderInputModel inputModel) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); var errorResult = new SubmitVisitorOrderResult { Success = false }; var response = CartManager.GetCart(userId, true); if (!response.ServiceProviderResult.Success || response.Result == null) { response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m)); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null)); } var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (cart.Lines.Count == 0) { errorResult.SystemMessages.Add(new SystemMessage { Message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Submit Order Has Empty Cart", "Cannot submit and order with an empty cart.") }); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null)); } cart.Email = inputModel.UserEmail; var request = new SubmitVisitorOrderRequest(cart); RefreshCartOnOrdersRequest(request); errorResult = OrderServiceProvider.SubmitVisitorOrder(request); if (errorResult.Success && errorResult.Order != null && errorResult.CartWithErrors == null) { CartCacheHelper.InvalidateCartCache(userId); try { var wasEmailSent = MailManager.SendMail("PurchaseConfirmation", inputModel.UserEmail, string.Join(" ", cart.Parties.FirstOrDefault()?.FirstName, cart.Parties.FirstOrDefault()?.LastName), errorResult.Order.TrackingNumber, errorResult.Order.OrderDate, string.Join(", ", cart.Lines.Select(x => x.Product.ProductName)), cart.Total.Amount.ToCurrency(cart.Total.CurrencyCode)); if (!wasEmailSent) { var message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Could Not Send Email Error", "Sorry, the email could not be sent"); //errorResult.SystemMessages.Add(new SystemMessage(message)); } } catch (Exception ex) { Log.Error("Could not send Purchase Confirmation mail message", ex, this); var message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Could Not Send Email Error", "Sorry, the email could not be sent"); errorResult.SystemMessages.Add(new SystemMessage(message)); } } errorResult.WriteToSitecoreLog(); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, errorResult.Order as CommerceOrder)); }
public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.Request"); Assert.ArgumentNotNull(args.Result, "args.Result"); Assert.IsTrue((bool)(args.Request is SubmitVisitorOrderRequest), "args.Request is SubmitVisitorOrderRequest"); Assert.IsTrue((bool)(args.Result is SubmitVisitorOrderResult), "args.Result is SubmitVisitorOrderResult"); SubmitVisitorOrderRequest request = (SubmitVisitorOrderRequest)args.Request; SubmitVisitorOrderResult result = (SubmitVisitorOrderResult)args.Result; CartPipelineContext context = CartPipelineContext.Get(request.RequestContext); Assert.IsNotNull(context, "cartContext"); if (((context.Basket != null) && !context.HasBasketErrors) && result.Success) { foreach (OrderForm orderForm in context.Basket.OrderForms) { foreach (LineItem lineItem in orderForm.LineItems) { var cartLine = request.Cart.Lines.FirstOrDefault(l => l.ExternalCartLineId.Equals(lineItem.LineItemId.ToString("B"), StringComparison.OrdinalIgnoreCase)); if (cartLine == null) { continue; } // Store the image as a string since a dictionary is not serializable and causes problems in C&OM. StringBuilder imageList = new StringBuilder(); foreach (MediaItem image in ((CustomCommerceCartLine)cartLine).Images) { if (image != null) { if (imageList.Length > 0) { imageList.Append("|"); } imageList.Append(image.ID.ToString()); imageList.Append(","); imageList.Append(image.MediaPath); } } lineItem["Images"] = imageList.ToString(); } } PurchaseOrder orderGroup = context.Basket.SaveAsOrder(); TranslateOrderGroupToEntityRequest request2 = new TranslateOrderGroupToEntityRequest(context.UserId, context.ShopName, orderGroup); TranslateOrderGroupToEntityResult result2 = PipelineUtility.RunCommerceConnectPipeline <TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>("translate.orderGroupToEntity", request2); result.Order = result2.Cart as Order; } }
/// <summary> /// Submits the visitor order. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="inputModel">The input model.</param> /// <returns> /// The manager response where the new CommerceOrder is returned in the Result. /// </returns> public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder([NotNull] CommerceStorefront storefront, [NotNull] IVisitorContext visitorContext, [NotNull] SubmitOrderInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(inputModel, "inputModel"); SubmitVisitorOrderResult errorResult = new SubmitVisitorOrderResult { Success = false }; var response = this._cartManager.GetCurrentCart(storefront, visitorContext, true); if (!response.ServiceProviderResult.Success || response.Result == null) { response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m)); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null)); } var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (cart.Lines.Count == 0) { errorResult.SystemMessages.Add(new SystemMessage { Message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.SubmitOrderHasEmptyCart) }); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null)); } var cartChanges = new CommerceCart(); cartChanges.Properties["Email"] = inputModel.UserEmail; var updateCartResult = this._cartManager.UpdateCart(storefront, visitorContext, cart, cartChanges); if (!updateCartResult.ServiceProviderResult.Success) { response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m)); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null)); } var request = new SubmitVisitorOrderRequest(cart); request.RefreshCart(true); errorResult = this._orderServiceProvider.SubmitVisitorOrder(request); if (errorResult.Success && errorResult.Order != null && errorResult.CartWithErrors == null) { var cartCache = ContextTypeLoader.CreateInstance <CartCacheHelper>(); cartCache.InvalidateCartCache(visitorContext.GetCustomerId()); } //Helpers.LogSystemMessages(errorResult.SystemMessages, errorResult); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, errorResult.Order as CommerceOrder)); }
public ActionResult Index(string emailAddress = "*****@*****.**") { var loadCartRequest = new LoadCartRequest("CommerceEngineDefaultStorefront", "Default", "1234"); var loadCartResult = _cartServiceProvider.LoadCart(loadCartRequest); var cart = loadCartResult.Cart as CommerceCart; cart.Email = emailAddress; // Save the cart as an order var submitVisitorOrderRequest = new SubmitVisitorOrderRequest(cart); var submitVisitorOrderResult = _orderServiceProvider.SubmitVisitorOrder(submitVisitorOrderRequest); return(View("Order", submitVisitorOrderResult)); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.Request"); Assert.ArgumentNotNull(args.Result, "args.Result"); Assert.ArgumentCondition(args.Request is SubmitVisitorOrderRequest, "args.Request", "args.Request is SubmitVisitorOrderRequest"); Assert.ArgumentCondition(args.Result is SubmitVisitorOrderResult, "args.Result", "args.Result is SubmitVisitorOrderResult"); if (args.Result.Success) { SubmitVisitorOrderRequest request = (SubmitVisitorOrderRequest)args.Request; SubmitVisitorOrderResult result = (SubmitVisitorOrderResult)args.Result; Assert.ArgumentNotNull(result.Order, "result.Order"); Assert.IsNotNullOrEmpty(result.Order.ShopName, "result.Order.ShopName"); Assert.IsNotNullOrEmpty(result.Order.ExternalId, "result.Order.ExternalId"); string shopName = request.Cart.ShopName; var userId = Tracker.Current.Contact.Identifiers.Identifier; string engagementPlanName = string.Format(CultureInfo.InvariantCulture, "{0} {1}", new object[] { shopName, this.EngagementPlanName }); Tuple <ID, ID> engagementPlan = this._engagementPlanProvider.GetEaPlanId(shopName, engagementPlanName, this.InitialStateName); this.AddContactToPlan(userId, result.Order, engagementPlan.Item1, engagementPlan.Item2); } }
public PipelineExecutionResult Execute(PurchaseOrder subject) { var cartServiceProvider = new CartServiceProvider(); var contactFactory = new ContactFactory(); string userId = contactFactory.GetContact(); var createCartRequest = new CreateOrResumeCartRequest(Context.GetSiteName(), userId); var cart = cartServiceProvider.CreateOrResumeCart(createCartRequest).Cart; var orderService = new OrderServiceProvider(); var request = new SubmitVisitorOrderRequest(cart); // Pass the PurchaseOrder object to Commerce Connect, so it can set use the data for // the page events, etc. request.Properties.Add("UCommerceOrder", subject); var result = orderService.SubmitVisitorOrder(request); return(PipelineExecutionResult.Success); }
/// <summary> /// Submits the visitor order. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="inputModel">The input model.</param> /// <returns> /// The manager response where the new CommerceOrder is returned in the Result. /// </returns> public ManagerResponse<SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] SubmitOrderInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(inputModel, "inputModel"); SubmitVisitorOrderResult errorResult = new SubmitVisitorOrderResult { Success = false }; var response = this.CartManager.GetCurrentCart(storefront, visitorContext, true); if (!response.ServiceProviderResult.Success || response.Result == null) { response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m)); return new ManagerResponse<SubmitVisitorOrderResult, CommerceOrder>(errorResult, null); } var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (cart.Lines.Count == 0) { errorResult.SystemMessages.Add(new SystemMessage { Message = StorefrontManager.GetSystemMessage("SubmitOrderHasEmptyCart") }); return new ManagerResponse<SubmitVisitorOrderResult, CommerceOrder>(errorResult, null); } var cartChanges = new CommerceCart(); cartChanges.Properties["Email"] = inputModel.UserEmail; var updateCartResult = this.CartManager.UpdateCart(storefront, visitorContext, cart, cartChanges); if (!updateCartResult.ServiceProviderResult.Success) { response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m)); return new ManagerResponse<SubmitVisitorOrderResult, CommerceOrder>(errorResult, null); } var request = new SubmitVisitorOrderRequest(cart); request.RefreshCart(true); errorResult = this.OrderServiceProvider.SubmitVisitorOrder(request); if (errorResult.Success && errorResult.Order != null && errorResult.CartWithErrors == null) { var cartCache = CommerceTypeLoader.CreateInstance<CartCacheHelper>(); cartCache.InvalidateCartCache(visitorContext.GetCustomerId()); } Helpers.LogSystemMessages(errorResult.SystemMessages, errorResult); return new ManagerResponse<SubmitVisitorOrderResult, CommerceOrder>(errorResult, errorResult.Order as CommerceOrder); }
public ActionResult RequestPayment() { // If you are OK with calling a uCommerce API at this point, you can simply call: // --- BEGIN uCommerce API. // TransactionLibrary.RequestPayments(); // return Redirect("/confirmation"); // This line is only required when using the DefaultPaymentMethod for the demo store. // --- END uCommerce API. // If you want to use the FederatedPayment parts of Commerce Connect. This is what you need to do, to make it work var cart = GetCart(); // For this demo store, it is assumed, that there is only one payment info associated with the order. // 1. You need to get the payment service URL for the payment var paymentService = new PaymentServiceProvider(); var baseUrl = HttpUtility.UrlDecode(paymentService.GetPaymentServiceUrl(new GetPaymentServiceUrlRequest()).Url) ?? string.Empty; // 2. You then need to add the payment method id and the payment id to the Url returned from the service. var paymentInfo = cart.Payment.First(); var completeUrl = string.Format(baseUrl, paymentInfo.PaymentMethodID, paymentInfo.ExternalId); // 3. In an IFrame set the url to the url from step 2. // Because this is a demo store, there is no actual payment gateway involved // Therefore at this point we need to manually set the status of the payment to Authorized. // ONLY CALLED FOR DEMO PURPOSES SetPaymentStatusToAuthorized(paymentInfo.ExternalId); // You should redirect the IFrame to the "completeUrl". // If you have configured your payment method to run the Checkout pipeline, // upon completion, then you do not need to do anything else. // The uCommerce framework takes care of the rest. // It checks that the transaction was authorized, and it redirects the customer to the accept url. // And it calls the Commerce Connect. SubmitVisitorOrder pipeline. // So you are done! // If you insist on doing the payment in the full Commerce Connect experience, // you should configure the uCommerce payment method to not run any pipeline on completion. // And in that case, you need to check that the payment was OK, and do the SubmitVisitorOrder calls yourself. // These steps are described below. // 4. When you believe that the transaction has been completed on the hosted page, you need to check if the payment is OK. // In the uCommerce implementation of the Commerce Connect API, this is done by passing the payment id as the access code. var actionResult = paymentService.GetPaymentServiceActionResult(new GetPaymentServiceActionResultRequest() { PaymentAcceptResultAccessCode = paymentInfo.ExternalId }); var paymentWasOk = actionResult.AuthorizationResult == "OK"; // 5. If the payment is OK, then you can Submit the Order. This corresponds to running the "Checkout" pipeline in uCommerce. if (paymentWasOk) { var orderService = new OrderServiceProvider(); var request = new SubmitVisitorOrderRequest(cart); orderService.SubmitVisitorOrder(request); } return(Redirect("/confirmation")); }
public ActionResult BasketToOrder() { var shopName = "CommerceEngineDefaultStorefront"; // Better use a configured store, not CommerceEngineDefaultStorefront as it's not really configured var cartName = "Default"; var userId = "Entity-Customer-34d758ae2d2d472d89014954d0cc4440"; var domain = Context.User.Domain; // Get a cart var loadCartRequest = new LoadCartByNameRequest(shopName, cartName, userId); var cartResult = _cartServiceProvider.LoadCart(loadCartRequest); Assert.IsTrue(cartResult.Success, String.Join("|", cartResult.SystemMessages.Select(e => e.Message))); var cart = cartResult.Cart; var quantity = 0.0M; // Get initial quantity if (cart.Lines.Count > 0) { quantity = cart.Lines[0].Quantity; } // Add a cart line: note that adding a line for the same product twice will update the quantity, not add a line: this is configured in commerce engine (look for RollupCartLinesPolicy) var lines = new List <CartLine>(); var cartLine = new CommerceCartLine("Neu", "47838_aus_allen_sternen_liebe_cd", "", 1.0M); lines.Add(cartLine); var addLinesRequest = new AddCartLinesRequest(cart, lines); var addLinesResult = _cartServiceProvider.AddCartLines(addLinesRequest); Assert.IsTrue(addLinesResult.Success, String.Join("|", addLinesResult.SystemMessages.Select(e => e.Message))); var updatedCart = addLinesResult.Cart; Assert.IsTrue(updatedCart.Lines.Count > 0, "Updated cart should have at least one line"); Assert.IsTrue(quantity + 1 == updatedCart.Lines[0].Quantity, "new quantity should be one more than before"); var reloadCartRequest = new LoadCartByNameRequest(shopName, cartName, userId); var reloadedCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(reloadedCartResult.Success, String.Join("|", reloadedCartResult.SystemMessages.Select(e => e.Message))); var reloadedCart = reloadedCartResult.Cart; Assert.IsTrue(reloadedCart.Lines.Count > 0, "Reloaded cart should have at least one line"); Assert.IsTrue(quantity + 1 == reloadedCart.Lines[0].Quantity, "reloaded cart quantity should be one more than before"); // Switching cart :-) cart = reloadedCart; // Add a shipping address CommerceParty shippingAddress = new CommerceParty(); shippingAddress.ExternalId = "Shipping"; shippingAddress.PartyId = shippingAddress.ExternalId; shippingAddress.Name = "Shipping"; shippingAddress.Address1 = "Barbara Strozzilaan 201"; shippingAddress.Company = "Sitecore"; shippingAddress.Country = "Canada"; shippingAddress.State = "ON"; // State is checked by commerce engine: you can configure it in Commerce shippingAddress.CountryCode = "CA"; // Country is checked by commerce engine shippingAddress.LastName = "Werkman"; shippingAddress.FirstName = "Erwin"; shippingAddress.City = "Amsterdam"; shippingAddress.ZipPostalCode = "1030AC"; var cartParties = cart.Parties.ToList(); cartParties.Add(shippingAddress); cart.Parties = cartParties; ShippingOptionType shippingOptionType = ShippingOptionType.ShipToAddress; ICollection <CommerceShippingInfo> shippingInfoList = new List <CommerceShippingInfo>(); var commerceShippingInfo = new CommerceShippingInfo(); commerceShippingInfo.ShippingOptionType = ShippingOptionType.ShipToAddress; commerceShippingInfo.PartyID = shippingAddress.ExternalId; commerceShippingInfo.ShippingMethodID = "B146622D-DC86-48A3-B72A-05EE8FFD187A"; // Ship Items > Ground commerceShippingInfo.ShippingMethodName = "Ground"; // Method id and name have to match what is configured in Sitecore Commerce Control Panel shippingInfoList.Add(commerceShippingInfo); var csShippingInfoList = new List <ShippingInfo>(); foreach (var shippingInfo in shippingInfoList) { csShippingInfoList.Add(shippingInfo); } // Add a shipping address and shipping method var addShippingInfoRequest = new Sitecore.Commerce.Engine.Connect.Services.Carts.AddShippingInfoRequest(cart, csShippingInfoList, shippingOptionType); var result = _cartServiceProvider.AddShippingInfo(addShippingInfoRequest); Assert.IsTrue(result.Success, String.Join("|", result.SystemMessages.Select(e => e.Message))); // Reload the cart so we have the latest information on how much we need to pay reloadedCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(reloadedCartResult.Success, String.Join("|", reloadedCartResult.SystemMessages.Select(e => e.Message))); cart = reloadedCartResult.Cart; // Add billing address CommerceParty billingAddress = new CommerceParty(); billingAddress.ExternalId = "Billing"; // This should correspond to the PartyId you are setting for the payment info billingAddress.PartyId = billingAddress.ExternalId; billingAddress.Name = "Billing"; billingAddress.Address1 = "Dorpsstraat 50"; billingAddress.Company = "Sitecore"; billingAddress.Country = "Canada"; billingAddress.State = "ON"; // State is checked: you can configure it in Commerce billingAddress.CountryCode = "CA"; billingAddress.LastName = "Werkman"; billingAddress.FirstName = "Erwin"; billingAddress.City = "Amsterdam"; billingAddress.ZipPostalCode = "1234AK"; cart.Parties.Add(billingAddress); // Add a payment address and payment method var payments = new List <PaymentInfo>(); /* * For federated payment info to work, you need to set up the Braintree integration * var federatedPaymentInfo = new FederatedPaymentInfo(); * * federatedPaymentInfo.PartyID = billingAddress.ExternalId; * federatedPaymentInfo.PaymentMethodID = "0CFFAB11-2674-4A18-AB04-228B1F8A1DEC"; // Federated Payment * federatedPaymentInfo.Amount = cart.Total.Amount; // Total payment (of all payment methods for a cart) should always be the same as the total amount of the order * federatedPaymentInfo.CardToken = "payment-nonce"; // This should be valid b * * payments.Add(federatedPaymentInfo); */ var giftCardPaymentInfo = new GiftCardPaymentInfo(); giftCardPaymentInfo.PaymentMethodID = "B5E5464E-C851-4C3C-8086-A4A874DD2DB0"; // GiftCard giftCardPaymentInfo.Amount = cart.Total.Amount; giftCardPaymentInfo.ExternalId = "GC1000000"; // This is the number of the giftcard giftCardPaymentInfo.PartyID = billingAddress.ExternalId; payments.Add(giftCardPaymentInfo); var addPaymentInfoRequest = new AddPaymentInfoRequest(cart, payments); var addPaymentInfoResult = _cartServiceProvider.AddPaymentInfo(addPaymentInfoRequest); Assert.IsTrue(addPaymentInfoResult.Success, String.Join("|", addPaymentInfoResult.SystemMessages.Select(e => e.Message))); var freshCartRequest = new LoadCartByNameRequest(shopName, cartName, userId); var freshCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(freshCartResult.Success, String.Join("|", freshCartResult.SystemMessages.Select(e => e.Message))); cart.Email = "*****@*****.**"; // This is necessary otherwise the cart will not become an order // Save the cart as an order var submitVisitorOrderRequest = new SubmitVisitorOrderRequest(cart); var submitVisitorOrderResult = _orderServiceProvider.SubmitVisitorOrder(submitVisitorOrderRequest); Assert.IsTrue(submitVisitorOrderResult.Success, String.Join("|", submitVisitorOrderResult.SystemMessages.Select(e => e.Message))); return(View("Cart", freshCartResult)); }
public ActionResult SubmitPayment(string paymentNonce) { var loadCartRequest = new LoadCartRequest("CommerceEngineDefaultStorefront", "Default", "1234"); var loadCartResult = _cartServiceProvider.LoadCart(loadCartRequest); var cart = loadCartResult.Cart as CommerceCart; // Add a shipping address CommerceParty shippingAddress = new CommerceParty(); shippingAddress.ExternalId = "Shipping"; shippingAddress.PartyId = shippingAddress.ExternalId; shippingAddress.Name = "Shipping"; shippingAddress.Address1 = "Barbara Strozzilaan 201"; shippingAddress.Company = "Sitecore"; shippingAddress.Country = "Canada"; shippingAddress.State = "NB"; // State is checked by commerce engine: you can configure it in Commerce shippingAddress.CountryCode = "CA"; // Country is checked by commerce engine shippingAddress.LastName = "Werkman"; shippingAddress.FirstName = "Erwin"; shippingAddress.City = "Amsterdam"; shippingAddress.ZipPostalCode = "1030AC"; var cartParties = cart.Parties.ToList(); cartParties.Add(shippingAddress); cart.Parties = cartParties; ShippingOptionType shippingOptionType = ShippingOptionType.ShipToAddress; ICollection <CommerceShippingInfo> shippingInfoList = new List <CommerceShippingInfo>(); var commerceShippingInfo = new CommerceShippingInfo(); commerceShippingInfo.ShippingOptionType = ShippingOptionType.ShipToAddress; commerceShippingInfo.PartyID = shippingAddress.ExternalId; commerceShippingInfo.ShippingMethodID = "B146622D-DC86-48A3-B72A-05EE8FFD187A"; // Ship Items > Ground commerceShippingInfo.ShippingMethodName = "Ground"; // Method id and name have to match what is configured in Sitecore Commerce Control Panel shippingInfoList.Add(commerceShippingInfo); var csShippingInfoList = new List <ShippingInfo>(); foreach (var shippingInfo in shippingInfoList) { csShippingInfoList.Add(shippingInfo); } // Add a shipping address and shipping method var addShippingInfoRequest = new Sitecore.Commerce.Engine.Connect.Services.Carts.AddShippingInfoRequest(cart, csShippingInfoList, shippingOptionType); var result = _cartServiceProvider.AddShippingInfo(addShippingInfoRequest); Assert.IsTrue(result.Success, String.Join("|", result.SystemMessages.Select(e => e.Message))); // Reload the cart so we have the latest information on how much we need to pay var reloadCartRequest = new LoadCartRequest("CommerceEngineDefaultStorefront", "Default", "1234"); var reloadedCartResult = _cartServiceProvider.LoadCart(reloadCartRequest); Assert.IsTrue(reloadedCartResult.Success, String.Join("|", reloadedCartResult.SystemMessages.Select(e => e.Message))); cart = reloadedCartResult.Cart as CommerceCart; CommerceParty billingAddress = new CommerceParty(); billingAddress.ExternalId = "Billing"; // This should correspond to the PartyId you are setting for the payment info billingAddress.PartyId = billingAddress.ExternalId; billingAddress.Name = "Billing"; billingAddress.Address1 = "Dorpsstraat 50"; billingAddress.Company = "Sitecore"; billingAddress.Country = "Canada"; billingAddress.State = "NB"; // State is checked: you can configure it in Commerce billingAddress.CountryCode = "CA"; billingAddress.LastName = "Werkman"; billingAddress.FirstName = "Erwin"; billingAddress.City = "Amsterdam"; billingAddress.ZipPostalCode = "1234AK"; cart.Parties.Add(billingAddress); var payments = new List <PaymentInfo>(); var federatedPaymentInfo = new FederatedPaymentInfo(); federatedPaymentInfo.PartyID = billingAddress.ExternalId; federatedPaymentInfo.PaymentMethodID = "0CFFAB11-2674-4A18-AB04-228B1F8A1DEC"; // Federated Payment federatedPaymentInfo.Amount = cart.Total.Amount; // Total payment (of all payment methods for a cart) should always be the same as the total amount of the order federatedPaymentInfo.CardToken = paymentNonce; payments.Add(federatedPaymentInfo); var addPaymentInfoRequest = new AddPaymentInfoRequest(cart, payments); var addPaymentInfoResult = _cartServiceProvider.AddPaymentInfo(addPaymentInfoRequest); Assert.IsTrue(addPaymentInfoResult.Success, String.Join("|", addPaymentInfoResult.SystemMessages.Select(e => e.Message))); cart.Email = "*****@*****.**"; // This is necessary otherwise the cart will not become an order // Save the cart as an order var submitVisitorOrderRequest = new SubmitVisitorOrderRequest(cart); var submitVisitorOrderResult = _orderServiceProvider.SubmitVisitorOrder(submitVisitorOrderRequest); Assert.IsTrue(submitVisitorOrderResult.Success, String.Join("|", submitVisitorOrderResult.SystemMessages.Select(e => e.Message))); return(View(submitVisitorOrderResult)); }