示例#1
0
        public override bool ProcessCheckout(OrderTaskContext context)
        {
            if (context.HccApp.CurrentRequestContext.RoutingContext.HttpContext != null)
            {
                try
                {
                    var settings       = new MyPaymentMethodSettings();
                    var methodSettings = context.HccApp.CurrentStore.Settings.MethodSettingsGet(PaymentMethodId);
                    settings.Merge(methodSettings);

                    // Here you can do custom processing of your payment.

                    // It can be direct post to payment service or redirection to hosted payment page
                    // In either case you have to end up on HccUrlBuilder.RouteHccUrl(HccRoute.ThirdPartyPayment) page
                    // So either you have to do such redirect here on your own
                    // or make sure that third party hosted pay page will make it in case of successfull or failed payment

                    HttpContextBase httpContext = new HccHttpContextWrapper(HttpContext.Current);
                    httpContext.Response.Redirect(HccUrlBuilder.RouteHccUrl(HccRoute.ThirdPartyPayment));
                }
                catch (Exception ex)
                {
                    EventLog.LogEvent("My Custom Checkout", "Exception occurred during call to Moneris: " + ex,
                                      EventLogSeverity.Error);
                    context.Errors.Add(new WorkflowMessage("My Custom Checkout Error",
                                                           GlobalLocalization.GetString("MonerisCheckoutError"), true));
                    return(false);
                }
            }

            return(false);
        }
示例#2
0
        public string Render(string controllerName, string actionName, string viewName = null, object routeValues = null)
        {
            if (routeValues == null)
            {
                routeValues = new object();
            }
            var routeData       = CreateRouteData(controllerName, actionName, new RouteValueDictionary(routeValues));
            var httpContextBase = new HccHttpContextWrapper(HttpContext.Current);

            httpContextBase.Request.RequestContext.RouteData = routeData;
            var reqContext = new RequestContext(httpContextBase, routeData);

            var viewContext = new ViewContext();

            viewContext.RouteData      = routeData;
            viewContext.RequestContext = reqContext;
            viewContext.HttpContext    = httpContextBase;
            viewContext.ViewData       = new ViewDataDictionary();

            if (!string.IsNullOrEmpty(viewName))
            {
                viewContext.ViewData["moduleViewName"] = viewName;
            }
            else if (ModuleContext != null)
            {
                var viewSettingName = string.Empty;
                var settings        = new Hashtable(ModuleContext.Settings, StringComparer.OrdinalIgnoreCase);

                //added condition to check for searchinput action also. Because that action also has settings saved as View. So this also needs to be
                //managed like all index pages.
                //Without adding search input condition issue occured when end user apply custom template for the search input view from module settings on page.
                if (actionName.Equals("Index", StringComparison.InvariantCultureIgnoreCase) ||
                    actionName.ToLower().Contains("searchinput"))
                {
                    viewSettingName = "View";
                }
                else
                {
                    viewSettingName = string.Concat(actionName, "View");
                }
                viewContext.ViewData["moduleViewName"] = (string)settings[viewSettingName];
            }

            viewContext.TempData = new TempDataDictionary();

            HtmlHelper htmlHelper = new HtmlHelper <object>(viewContext, new FakeViewDataContainer());
            var        htmlString = htmlHelper.Action(actionName, controllerName, routeValues);

            return(htmlString.ToHtmlString());
        }
        public override bool ProcessCheckout(OrderTaskContext context)
        {
            if (context.HccApp.CurrentRequestContext.RoutingContext.HttpContext != null)
            {
                try
                {
                    PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(context.HccApp.CurrentStore);

                    string cartReturnUrl = HccUrlBuilder.RouteHccUrl(HccRoute.ThirdPartyPayment, null, Uri.UriSchemeHttps);
                    string cartCancelUrl = HccUrlBuilder.RouteHccUrl(HccRoute.Checkout, null, Uri.UriSchemeHttps);

                    EventLog.LogEvent("PayPal Express Checkout", "CartCancelUrl=" + cartCancelUrl, EventLogSeverity.Information);
                    EventLog.LogEvent("PayPal Express Checkout", "CartReturnUrl=" + cartReturnUrl, EventLogSeverity.Information);

                    PaymentActionCodeType mode = PaymentActionCodeType.Authorization;
                    if (!context.HccApp.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                    {
                        mode = PaymentActionCodeType.Sale;
                    }

                    // Accelerated boarding
                    if (string.IsNullOrWhiteSpace(context.HccApp.CurrentStore.Settings.PayPal.UserName))
                    {
                        mode = PaymentActionCodeType.Sale;
                    }

                    var  solutionType  = context.HccApp.CurrentStore.Settings.PayPal.RequirePayPalAccount ? SolutionTypeType.Mark : SolutionTypeType.Sole;
                    bool isNonShipping = !context.Order.HasShippingItems;

                    bool addressSupplied = false;
                    if (context.Inputs["ViaCheckout"] != null &&
                        context.Inputs["ViaCheckout"].Value == "1")
                    {
                        addressSupplied = true;
                        context.Order.CustomProperties.Add("hcc", "ViaCheckout", "1");
                    }

                    PaymentDetailsItemType[] itemsDetails = GetOrderItemsDetails(context);

                    SetExpressCheckoutResponseType expressResponse;
                    if (addressSupplied)
                    {
                        Contacts.Address address = context.Order.ShippingAddress;

                        // in some cases, this logic will be hit with non-shipping orders, causing an exception
                        if (address == null || string.IsNullOrEmpty(address.Bvin))
                        {
                            // this is a workaround for that use case
                            address = context.Order.BillingAddress;
                        }

                        if (address.CountryData != null)
                        {
                            var itemsTotalWithoutTax = context.Order.TotalOrderAfterDiscounts;
                            if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                            {
                                itemsTotalWithoutTax -= context.Order.ItemsTax;
                            }
                            string itemsTotal = itemsTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);
                            string taxTotal   = context.Order.TotalTax.ToString("N", CultureInfo.InvariantCulture);
                            var    shippingTotalWithoutTax = context.Order.TotalShippingAfterDiscounts;
                            if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                            {
                                shippingTotalWithoutTax -= context.Order.ShippingTax;
                            }
                            string shippingTotal = shippingTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);

                            string orderTotal = context.Order.TotalGrand.ToString("N", CultureInfo.InvariantCulture);
                            expressResponse = ppAPI.SetExpressCheckout(
                                itemsDetails,
                                itemsTotal,
                                taxTotal,
                                shippingTotal,
                                orderTotal,
                                cartReturnUrl,
                                cartCancelUrl,
                                mode,
                                PayPalAPI.GetCurrencyCodeType(context.HccApp.CurrentStore.Settings.PayPal.Currency),
                                solutionType,
                                address.FirstName + " " + address.LastName,
                                address.CountryData.IsoCode,
                                address.Line1,
                                address.Line2,
                                address.City,
                                address.RegionBvin,
                                address.PostalCode,
                                address.Phone,
                                context.Order.OrderNumber + Guid.NewGuid().ToString(),
                                isNonShipping);
                            if (expressResponse == null)
                            {
                                EventLog.LogEvent("PayPal Express Checkout", "Express Response Was Null!", EventLogSeverity.Error);
                            }
                        }
                        else
                        {
                            EventLog.LogEvent("StartPaypalExpressCheckout", "Country with bvin " + address.CountryBvin + " was not found.", EventLogSeverity.Error);
                            return(false);
                        }
                    }
                    else
                    {
                        decimal includedTax = 0;
                        if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                        {
                            includedTax = context.Order.ItemsTax;
                        }
                        string taxTotal             = includedTax.ToString("N", CultureInfo.InvariantCulture);
                        var    itemsTotalWithoutTax = context.Order.TotalOrderAfterDiscounts;
                        if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                        {
                            itemsTotalWithoutTax -= context.Order.ItemsTax;
                        }
                        string itemsTotal = itemsTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);
                        string orderTotal = context.Order.TotalOrderAfterDiscounts.ToString("N", CultureInfo.InvariantCulture);
                        expressResponse = ppAPI.SetExpressCheckout(itemsDetails,
                                                                   itemsTotal,
                                                                   taxTotal,
                                                                   orderTotal,
                                                                   cartReturnUrl,
                                                                   cartCancelUrl,
                                                                   mode,
                                                                   PayPalAPI.GetCurrencyCodeType(context.HccApp.CurrentStore.Settings.PayPal.Currency),
                                                                   solutionType,
                                                                   context.Order.OrderNumber + Guid.NewGuid().ToString(),
                                                                   isNonShipping);
                        if (expressResponse == null)
                        {
                            EventLog.LogEvent("PayPal Express Checkout", "Express Response2 Was Null!", EventLogSeverity.Error);
                        }
                    }

                    if (expressResponse.Ack == AckCodeType.Success || expressResponse.Ack == AckCodeType.SuccessWithWarning)
                    {
                        context.Order.ThirdPartyOrderId = expressResponse.Token;

                        // Recording of this info is handled on the paypal express
                        // checkout page instead of here.
                        //Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(context.Order);
                        //payManager.PayPalExpressAddInfo(context.Order.TotalGrand, expressResponse.Token);

                        EventLog.LogEvent("PayPal Express Checkout", "Response SUCCESS", EventLogSeverity.Information);

                        Orders.OrderNote note = new Orders.OrderNote();
                        note.IsPublic = false;
                        note.Note     = "Paypal Order Accepted With Paypal Order Number: " + expressResponse.Token;
                        context.Order.Notes.Add(note);
                        if (context.HccApp.OrderServices.Orders.Update(context.Order))
                        {
                            string urlTemplate;
                            if (string.Compare(context.HccApp.CurrentStore.Settings.PayPal.Mode, "Live", true) == 0)
                            {
                                urlTemplate = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}";
                            }
                            else
                            {
                                urlTemplate = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}";
                            }
                            HttpContextBase httpContext = new HccHttpContextWrapper(HttpContext.Current);
                            httpContext.Response.Redirect(string.Format(urlTemplate, expressResponse.Token), true);
                        }
                        return(true);
                    }
                    else
                    {
                        foreach (ErrorType ppError in expressResponse.Errors)
                        {
                            context.Errors.Add(new WorkflowMessage(ppError.ErrorCode, ppError.ShortMessage, true));

                            //create a note to save the paypal error info onto the order
                            Orders.OrderNote note = new Orders.OrderNote();
                            note.IsPublic = false;
                            note.Note     = "Paypal error number: " + ppError.ErrorCode + " Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage;
                            context.Order.Notes.Add(note);

                            EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to SetExpressCheckout: Total=" + string.Format("{0:c}", context.Order.TotalOrderBeforeDiscounts) + " Cart Return Url: " + cartReturnUrl + " Cart Cancel Url: " + cartCancelUrl, EventLogSeverity.Error);
                        }
                        context.Errors.Add(new WorkflowMessage("Paypal checkout error", GlobalLocalization.GetString("PaypalCheckoutCustomerError"), true));
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    EventLog.LogEvent("Paypal Express Checkout", "Exception occurred during call to Paypal: " + ex.ToString(), EventLogSeverity.Error);
                    context.Errors.Add(new WorkflowMessage("Paypal checkout error", GlobalLocalization.GetString("PaypalCheckoutCustomerError"), true));
                    return(false);
                }
            }

            return(false);
        }
        private void OnApplicationPostResolveRequestCache(object sender, EventArgs e)
        {
            HttpContextBase context = new HccHttpContextWrapper(((HttpApplication)sender).Context);

            PostResolveRequestCache(context);
        }
        public override bool ProcessCheckout(OrderTaskContext context)
        {
            if (context.HccApp.CurrentRequestContext.RoutingContext.HttpContext != null)
            {
                try
                {
                    var settings       = new MonerisSettings();
                    var methodSettings = context.HccApp.CurrentStore.Settings.MethodSettingsGet(PaymentMethodId);
                    settings.Merge(methodSettings);

                    var order  = context.Order;
                    var amount = order.TotalGrandAfterStoreCredits(context.HccApp.OrderServices);

                    var parameters = new NameValueCollection();
                    parameters.Add("ps_store_id", settings.HostedPayPageId);
                    parameters.Add("hpp_key", settings.HostedPayPageToken);
                    parameters.Add("hpp_preload", "");
                    parameters.Add("charge_total", amount.ToString("F2", CultureInfo.InvariantCulture));

                    parameters.Add("lang", CultureInfo.CurrentCulture.Name);
                    parameters.Add("hst", order.TotalTax.ToString("F2", CultureInfo.InvariantCulture));
                    parameters.Add("shipping_cost",
                                   order.TotalShippingAfterDiscounts.ToString("F2", CultureInfo.InvariantCulture));
                    parameters.Add("email", Text.TrimToLength(order.UserEmail, 50));
                    parameters.Add("note",
                                   string.Format(CultureInfo.InvariantCulture, "Order discounts: {0:F2}", order.TotalOrderDiscounts));

                    parameters.Add("ship_first_name", Text.TrimToLength(order.ShippingAddress.FirstName, 30));
                    parameters.Add("ship_last_name", Text.TrimToLength(order.ShippingAddress.LastName, 30));
                    parameters.Add("ship_company_name", Text.TrimToLength(order.ShippingAddress.Company, 30));
                    parameters.Add("ship_address_one",
                                   Text.TrimToLength(string.Join(", ", order.ShippingAddress.Line2, order.ShippingAddress.Line1),
                                                     30));
                    parameters.Add("ship_city", Text.TrimToLength(order.ShippingAddress.City, 30));
                    if (order.ShippingAddress.RegionData != null)
                    {
                        parameters.Add("ship_state_or_province",
                                       Text.TrimToLength(order.ShippingAddress.RegionData.DisplayName, 30));
                    }
                    parameters.Add("ship_postal_code", Text.TrimToLength(order.ShippingAddress.PostalCode, 30));
                    parameters.Add("ship_country", Text.TrimToLength(order.ShippingAddress.CountryData.DisplayName, 30));
                    parameters.Add("ship_phone", Text.TrimToLength(order.ShippingAddress.Phone, 30));

                    parameters.Add("bill_first_name", Text.TrimToLength(order.BillingAddress.FirstName, 30));
                    parameters.Add("bill_last_name", Text.TrimToLength(order.BillingAddress.LastName, 30));
                    parameters.Add("bill_company_name", Text.TrimToLength(order.BillingAddress.Company, 30));
                    parameters.Add("bill_address_one",
                                   string.Join(", ", order.BillingAddress.Line2, order.BillingAddress.Line1));
                    parameters.Add("bill_city", Text.TrimToLength(order.BillingAddress.City, 30));
                    if (order.BillingAddress.RegionData != null)
                    {
                        parameters.Add("bill_state_or_province",
                                       Text.TrimToLength(order.BillingAddress.RegionData.DisplayName, 30));
                    }
                    parameters.Add("bill_postal_code", Text.TrimToLength(order.BillingAddress.PostalCode, 30));
                    parameters.Add("bill_country", Text.TrimToLength(order.BillingAddress.CountryData.DisplayName, 30));
                    parameters.Add("bill_phone", Text.TrimToLength(order.BillingAddress.Phone, 30));

                    for (var i = 0; i < order.Items.Count; i++)
                    {
                        var item = order.Items[i];
                        parameters.Add("id" + (i + 1), item.ProductSku);
                        parameters.Add("description" + (i + 1), item.ProductName);
                        parameters.Add("quantity" + (i + 1), item.Quantity.ToString());
                        parameters.Add("price" + (i + 1),
                                       item.AdjustedPricePerItem.ToString("F2", CultureInfo.InvariantCulture));
                        parameters.Add("subtotal" + (i + 1), item.LineTotal.ToString("F2", CultureInfo.InvariantCulture));
                    }

                    MonerisHPPDPResponse monerisResponse;
                    var url = settings.DeveloperMode ? DevelopmentUrl : ProductionUrl;
                    using (var client = new WebClient())
                    {
                        if (settings.DebugMode)
                        {
                            EventLog.LogEvent("Moneris Checkout", Url.BuldQueryString(parameters),
                                              EventLogSeverity.Debug);
                        }

                        var responseBytes = client.UploadValues(url, "POST", parameters);
                        var responseBody  = Encoding.UTF8.GetString(responseBytes);

                        if (settings.DebugMode)
                        {
                            EventLog.LogEvent("Moneris Checkout", responseBody, EventLogSeverity.Debug);
                        }

                        using (var configFile = new StringReader(responseBody))
                        {
                            var serializer = new XmlSerializer(typeof(MonerisHPPDPResponse));
                            monerisResponse = (MonerisHPPDPResponse)serializer.Deserialize(configFile);
                        }
                    }

                    var             urlTemplate = "{0}?hpp_id={1}&ticket={2}&hpp_preload";
                    HttpContextBase httpContext = new HccHttpContextWrapper(HttpContext.Current);
                    httpContext.Response.Redirect(
                        string.Format(urlTemplate, url, monerisResponse.HostedPayPageId, monerisResponse.Ticket), true);
                }
                catch (Exception ex)
                {
                    EventLog.LogEvent("Moneris Checkout", "Exception occurred during call to Moneris: " + ex,
                                      EventLogSeverity.Error);
                    context.Errors.Add(new WorkflowMessage("Moneris Checkout Error",
                                                           GlobalLocalization.GetString("MonerisCheckoutError"), true));
                    return(false);
                }
            }

            return(false);
        }
示例#6
0
        public override bool ProcessCheckout(OrderTaskContext context)
        {
            if (context.HccApp.CurrentRequestContext.RoutingContext.HttpContext != null)
            {
                try
                {
                    var settings       = new OgoneSettings();
                    var methodSettings = context.HccApp.CurrentStore.Settings.MethodSettingsGet(PaymentMethodId);
                    settings.Merge(methodSettings);

                    var order = context.Order;

                    var decimalAmount = order.TotalGrandAfterStoreCredits(context.HccApp.OrderServices);
                    var intAmount     = (int)(decimalAmount * 100);

                    var parameters = new NameValueCollection();
                    parameters.Add("PSPID", settings.PaymentServiceProviderId);
                    // We can't use order.bvin here because Ogone won't allow us try to pay failed order again
                    parameters.Add("ORDERID", "order" + DateTime.UtcNow.Ticks);
                    parameters.Add("AMOUNT", intAmount.ToString());
                    var regionInfo = new RegionInfo(context.HccApp.CurrentStore.Settings.CurrencyCultureCode);
                    parameters.Add("CURRENCY", regionInfo.ISOCurrencySymbol);
                    var language = CultureInfo.CurrentCulture.Name.Replace("-", "_");
                    parameters.Add("LANGUAGE", language);
                    parameters.Add("EMAIL", order.UserEmail);

                    var address = order.BillingAddress;
                    parameters.Add("CN", string.Join(" ", address.FirstName, address.LastName));
                    parameters.Add("OWNERADDRESS", string.Join(", ", address.Line2, address.Line1));
                    parameters.Add("OWNERZIP", address.PostalCode);
                    parameters.Add("OWNERTOWN", address.City);
                    parameters.Add("OWNERCTY", address.CountryDisplayName);
                    parameters.Add("OWNERTELNO", address.Phone);

                    parameters.Add("OPERATION", "SAL");
                    if (!string.IsNullOrWhiteSpace(settings.TemplatePage))
                    {
                        parameters.Add("TP", settings.TemplatePage);
                    }

                    var returnUrl = HccUrlBuilder.RouteHccUrl(HccRoute.ThirdPartyPayment);
                    var cancelUrl = HccUrlBuilder.RouteHccUrl(HccRoute.Checkout);
                    parameters.Add("ACCEPTURL", returnUrl);
                    parameters.Add("DECLINEURL", returnUrl);
                    parameters.Add("EXCEPTIONURL", returnUrl);
                    parameters.Add("CANCELURL", cancelUrl);

                    var shaSign = OgoneUtils.CalculateShaHash(parameters, settings.HashAlgorithm,
                                                              settings.ShaInPassPhrase);
                    parameters.Add("SHASIGN", shaSign);

                    HttpContextBase httpContext = new HccHttpContextWrapper(HttpContext.Current);

                    var url       = settings.DeveloperMode ? DevelopmentUTF8Url : ProductionUTF8Url;
                    var urlParams = Url.BuldQueryString(parameters);

                    if (settings.DebugMode)
                    {
                        EventLog.LogEvent("Ogone Checkout", urlParams, EventLogSeverity.Debug);
                    }

                    var urlTemplate = "{0}?{1}";
                    httpContext.Response.Redirect(string.Format(urlTemplate, url, urlParams), true);
                }
                catch (Exception ex)
                {
                    EventLog.LogEvent("Ogone Checkout", "Exception occurred during call to Ogone: " + ex,
                                      EventLogSeverity.Error);
                    context.Errors.Add(new WorkflowMessage("Ogone Checkout Error",
                                                           GlobalLocalization.GetString("OgoneCheckoutError"), true));
                    return(false);
                }
            }

            return(false);
        }