public ActionResult Index() { var settings = new OgoneSettings(); var methodSettings = HccApp.CurrentStore.Settings.MethodSettingsGet(PaymentMethods.OgoneId); settings.Merge(methodSettings); var response = GetOgoneResponse(); if (settings.DebugMode) { EventLog.LogEvent("Ogone Checkout", Request.RawUrl, EventLogSeverity.Debug); } var parameters = GetOgoneHashableParameters(); var shaSignCalc = OgoneUtils.CalculateShaHash(parameters, settings.HashAlgorithm, settings.ShaOutPassPhrase); var model = new CheckoutViewModel(); model.CurrentOrder = HccApp.OrderServices.CurrentShoppingCart(); if (shaSignCalc == response.ShaSignature) { // SHA Signature Match if (response.Status == 5 || response.Status == 51 || response.Status == 9 || response.Status == 91) { // Approved SavePaymentInfo(model, response); ProcessOrder(model); } else { // Declined FlashFailure(Localization.GetString("ErrorOccured")); } } else { // SHA Signature Mismatch FlashFailure(Localization.GetString("ShaSignatureMismatch.Text")); } // Render Error Summary foreach (var v in model.Violations) { FlashFailure(v.ErrorMessage); } return(View(model)); }
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); }