public ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> > GetUserOrders(string userName) { if (userName == null) { throw new ArgumentNullException(nameof(userName)); } var user = this.AccountManager.GetUser(userName); if (!user.ServiceProviderResult.Success || user.Result == null) { throw new ArgumentException("Could not find the user, invalid userName.", nameof(userName)); } var request = new GetVisitorOrdersRequest(user.Result.ExternalId, StorefrontContext.Current.ShopName); var result = OrderServiceProvider.GetVisitorOrders(request); if (result.Success && result.OrderHeaders != null && result.OrderHeaders.Count > 0) { return(new ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> >(result, result.OrderHeaders.ToList())); } result.WriteToSitecoreLog(); //no orders found returns false - we treat it as success if (!result.Success && !result.SystemMessages.Any()) { result.Success = true; } return(new ManagerResponse <GetVisitorOrdersResult, IEnumerable <OrderHeader> >(result, new List <OrderHeader>())); }
public OrderManager(ILogService <CommonLog> logService, IConnectServiceProvider connectServiceProvider) : base( logService) { Assert.ArgumentNotNull(connectServiceProvider, nameof(connectServiceProvider)); this.orderServiceProvider = connectServiceProvider.GetOrderServiceProvider(); }
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)); }
// GET public ActionResult Index() { var orderService = new OrderServiceProvider(); var visitorOrdersRequest = new GetVisitorOrdersRequest("Entity-Customer-34d758ae2d2d472d89014954d0cc4440", "CommerceEngineDefaultStorefront"); var result = orderService.GetVisitorOrders(visitorOrdersRequest); return(View(result)); }
/// <summary> /// Initializes a new instance of the <see cref="OrderManager" /> class. /// </summary> /// <param name="orderServiceProvider">The order service provider.</param> /// <param name="cartManager">The cart manager.</param> public OrderManager( CommerceOrderServiceProvider orderServiceProvider, ICartManager cartManager) { Assert.ArgumentNotNull(orderServiceProvider, "orderServiceProvider"); Assert.ArgumentNotNull(cartManager, "cartManager"); this._orderServiceProvider = orderServiceProvider; this._cartManager = cartManager; }
public OrderManagerTests() { var connectServiceProvider = Substitute.For <IConnectServiceProvider>(); var logService = Substitute.For <ILogService <CommonLog> >(); this.orderServiceProvider = Substitute.For <OrderServiceProvider>(); connectServiceProvider.GetOrderServiceProvider().Returns(this.orderServiceProvider); this.manager = Substitute.For <OrderManager>(logService, connectServiceProvider); this.fixture = new Fixture(); }
public OrderManager(OrderServiceProvider orderServiceProvider, CartManager cartManager, CartCacheHelper cartCacheHelper, MailManager mailManager, StorefrontContext storefrontContext, AccountManager accountManager) { Assert.ArgumentNotNull(orderServiceProvider, nameof(orderServiceProvider)); Assert.ArgumentNotNull(cartManager, nameof(cartManager)); OrderServiceProvider = orderServiceProvider; CartManager = cartManager; CartCacheHelper = cartCacheHelper; MailManager = mailManager; StorefrontContext = storefrontContext; AccountManager = accountManager; }
public ManagerResponse <GetVisitorOrderResult, CommerceOrder> GetOrderDetails(string userId, string orderId) { Assert.ArgumentNotNullOrEmpty(userId, nameof(userId)); Assert.ArgumentNotNullOrEmpty(orderId, nameof(orderId)); if (StorefrontContext.Current == null) { throw new InvalidOperationException("Cannot be called without a valid storefront context."); } var request = new GetVisitorOrderRequest(orderId, userId, StorefrontContext.Current.ShopName); var result = OrderServiceProvider.GetVisitorOrder(request); result.WriteToSitecoreLog(); return(new ManagerResponse <GetVisitorOrderResult, CommerceOrder>(result, result.Order as CommerceOrder)); }
public ActionResult Confirm() { var cart = Cart; cart.Email = "*****@*****.**"; var result = new OrderServiceProvider().SubmitVisitorOrder(new SubmitVisitorOrderRequest(cart)); if (!result.Success) { throw new InvalidOperationException(string.Join(",", result.SystemMessages.Select(x => x.Message))); } string redirectUrl = new HeidelpayServiceProvider().RequestPayment((CommerceOrder)result.Order); return(Redirect(redirectUrl)); }
/// <summary> /// Initializes a new instance of the <see cref="OrderService"/> class. /// </summary> /// <param name="serviceProvider">The orders service provider.</param> /// <param name="contactFactory">The contact factory.</param> /// <param name="cartService">The carts service.</param> /// <param name="shopName">The shop name.</param> public OrderService( [NotNull] OrderServiceProvider serviceProvider, [NotNull] ContactFactory contactFactory, [NotNull] ICartService cartService, [NotNull] string shopName) { Assert.ArgumentNotNull(serviceProvider, "serviceProvider"); Assert.ArgumentNotNull(contactFactory, "contactFactory"); Assert.ArgumentNotNull(cartService, "cartService"); Assert.ArgumentNotNullOrEmpty(shopName, "shopName"); this.serviceProvider = serviceProvider; this.contactFactory = contactFactory; this.cartService = cartService; this.shopName = shopName; }
public ManagerResponse <CartResult, CommerceCart> Reorder(string userId, ReorderInputModel inputModel) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); Assert.ArgumentNotNullOrEmpty(inputModel.OrderId, nameof(inputModel.OrderId)); var request = new ReorderByCartNameRequest { CustomerId = userId, OrderId = inputModel.OrderId, ReorderLineExternalIds = inputModel.ReorderLineExternalIds, CartName = CommerceConstants.CartSettings.DefaultCartName, OrderShippingPreferenceType = ShippingOptionType.ShipToAddress }; var result = OrderServiceProvider.Reorder(request); result.WriteToSitecoreLog(); return(new ManagerResponse <CartResult, CommerceCart>(result, result.Cart as CommerceCart)); }
public ManagerResponse <VisitorCancelOrderResult, bool> CancelOrder(string userId, CancelOrderInputModel inputModel) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); Assert.ArgumentNotNullOrEmpty(inputModel.OrderId, nameof(inputModel.OrderId)); if (StorefrontContext.Current == null) { throw new InvalidOperationException("Cannot be called without a valid storefront context."); } var request = new VisitorCancelOrderRequest(inputModel.OrderId, userId, StorefrontContext.Current.ShopName) { OrderLineExternalIds = inputModel.OrderLineExternalIds }; var result = OrderServiceProvider.VisitorCancelOrder(request); result.WriteToSitecoreLog(); return(new ManagerResponse <VisitorCancelOrderResult, bool>(result, result.Success)); }
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); }
public CountryManager(OrderServiceProvider orderServiceProvider) { Assert.ArgumentNotNull(orderServiceProvider, nameof(orderServiceProvider)); OrderServiceProvider = orderServiceProvider; }
public OrderManager(IConnectServiceProvider connectServiceProvider) { Assert.ArgumentNotNull((object)connectServiceProvider, nameof(connectServiceProvider)); this.orderServiceProvider = connectServiceProvider.GetOrderServiceProvider(); }
public BraintreeController() { _cartServiceProvider = new CartServiceProvider(); _orderServiceProvider = new OrderServiceProvider(); }
public SampleController() { _cartServiceProvider = new CartServiceProvider(); _orderServiceProvider = new OrderServiceProvider(); }
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 MockOrderManager(OrderServiceProvider orderServiceProvider, ICartManager cartManager) { _orderServiceProvider = orderServiceProvider; _cartManager = cartManager; }