/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public virtual void Process(PipelineArgs args) { Assert.ArgumentNotNull(args, "args"); ShoppingCart shoppingCart = Context.Entity.GetInstance <ShoppingCart>(); PaymentProvider paymentProvider = Context.Entity.Resolve <PaymentProvider>(shoppingCart.PaymentSystem.Code); PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver(); PaymentArgs paymentArgs = new PaymentArgs { ShoppingCart = shoppingCart, PaymentUrls = paymentUrlResolver.Resolve(), }; StringBuilder description = new StringBuilder(); foreach (ShoppingCartLine shoppingCartLine in shoppingCart.ShoppingCartLines) { description.Append(shoppingCartLine.Product.Title); description.Append(", "); } paymentArgs.Description = description.ToString().Trim().TrimEnd(','); paymentProvider.Invoke(shoppingCart.PaymentSystem, paymentArgs); args.AbortPipeline(); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <exception cref="ValidatorException">Order could not be created.</exception> protected void Page_Load(object sender, EventArgs e) { DomainModel.Carts.ShoppingCart shoppingCart = Sitecore.Ecommerce.Context.Entity.GetInstance<DomainModel.Carts.ShoppingCart>(); if (string.IsNullOrEmpty(shoppingCart.PaymentSystem.Code)) { return; } PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver(); PaymentArgs paymentArgs = new PaymentArgs { PaymentUrls = paymentUrlResolver.Resolve(), ShoppingCart = shoppingCart }; ITransactionData transactionData = Sitecore.Ecommerce.Context.Entity.Resolve<ITransactionData>(); PaymentProvider paymentProvider = Sitecore.Ecommerce.Context.Entity.Resolve<PaymentProvider>(shoppingCart.PaymentSystem.Code); DomainModel.Payments.PaymentSystem paymentSystem = shoppingCart.PaymentSystem; try { paymentProvider.ProcessCallback(paymentSystem, paymentArgs); } catch (Exception exception) { IOrderManager<Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>(); shoppingCart.OrderNumber = orderManager.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); HttpContext.Current.Session["paymentErrorMessage"] = exception.Message; this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl); return; } switch (paymentProvider.PaymentStatus) { case PaymentStatus.Succeeded: { IOrderManager<Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>(); Order order = orderManager.CreateOrder(shoppingCart); if (order != null) { // Redirect to order confirmation page string orderId = shoppingCart.OrderNumber; ICheckOut checkOut = Sitecore.Ecommerce.Context.Entity.Resolve<ICheckOut>(); if (checkOut is CheckOut) { ((CheckOut)checkOut).ResetCheckOut(); } if (MainUtil.IsLoggedIn()) { orderId = string.Format("orderid={0}", orderId); } else { string encryptKey = Crypto.EncryptTripleDES(orderId, "5dfkjek5"); orderId = string.Format("key={0}", Uri.EscapeDataString(encryptKey)); } this.StartOrderCreatedPipeline(order.OrderNumber); if (!string.IsNullOrEmpty(orderId)) { UrlString url = new UrlString(paymentArgs.PaymentUrls.SuccessPageUrl); url.Append(new UrlString(orderId)); this.Response.Redirect(url.ToString()); } } else { IOrderManager<Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>(); shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); HttpContext.Current.Session["paymentErrorMessage"] = "Order could not be created."; this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl); } break; } case PaymentStatus.Canceled: { IOrderManager<Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>(); shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); HttpContext.Current.Session["paymentErrorMessage"] = "Payment has been aborted by user."; this.Response.Redirect(paymentArgs.PaymentUrls.CancelPageUrl); break; } case PaymentStatus.Failure: { IOrderManager<Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>(); shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl); break; } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <exception cref="ValidatorException">Order could not be created.</exception> protected void Page_Load(object sender, EventArgs e) { DomainModel.Carts.ShoppingCart shoppingCart = Sitecore.Ecommerce.Context.Entity.GetInstance <DomainModel.Carts.ShoppingCart>(); if (string.IsNullOrEmpty(shoppingCart.PaymentSystem.Code)) { return; } PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver(); PaymentArgs paymentArgs = new PaymentArgs { PaymentUrls = paymentUrlResolver.Resolve(), ShoppingCart = shoppingCart }; ITransactionData transactionData = Sitecore.Ecommerce.Context.Entity.Resolve <ITransactionData>(); PaymentProvider paymentProvider = Sitecore.Ecommerce.Context.Entity.Resolve <PaymentProvider>(shoppingCart.PaymentSystem.Code); DomainModel.Payments.PaymentSystem paymentSystem = shoppingCart.PaymentSystem; try { paymentProvider.ProcessCallback(paymentSystem, paymentArgs); } catch (Exception exception) { IOrderManager <Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >(); shoppingCart.OrderNumber = orderManager.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); HttpContext.Current.Session["paymentErrorMessage"] = exception.Message; this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl); return; } switch (paymentProvider.PaymentStatus) { case PaymentStatus.Succeeded: { IOrderManager <Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >(); Order order = orderManager.CreateOrder(shoppingCart); if (order != null) { // Redirect to order confirmation page string orderId = shoppingCart.OrderNumber; ICheckOut checkOut = Sitecore.Ecommerce.Context.Entity.Resolve <ICheckOut>(); if (checkOut is CheckOut) { ((CheckOut)checkOut).ResetCheckOut(); } if (MainUtil.IsLoggedIn()) { orderId = string.Format("orderid={0}", orderId); } else { string encryptKey = Crypto.EncryptTripleDES(orderId, "5dfkjek5"); orderId = string.Format("key={0}", Uri.EscapeDataString(encryptKey)); } this.StartOrderCreatedPipeline(order.OrderNumber); if (!string.IsNullOrEmpty(orderId)) { UrlString url = new UrlString(paymentArgs.PaymentUrls.SuccessPageUrl); url.Append(new UrlString(orderId)); this.Response.Redirect(url.ToString()); } } else { IOrderManager <Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >(); shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); HttpContext.Current.Session["paymentErrorMessage"] = "Order could not be created."; this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl); } break; } case PaymentStatus.Canceled: { IOrderManager <Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >(); shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); HttpContext.Current.Session["paymentErrorMessage"] = "Payment has been aborted by user."; this.Response.Redirect(paymentArgs.PaymentUrls.CancelPageUrl); break; } case PaymentStatus.Failure: { IOrderManager <Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >(); shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber(); transactionData.DeletePersistentValue(shoppingCart.OrderNumber); this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl); break; } } }