public ActionResult Payment(int orderID = 0) { if (orderID > 0) { tbl_Orders order = ECommerceService.GetOrderByID(orderID); if (order == null) { throw new Exception("No order has been found"); } else { string currencyCode = DomainService.GetSettingsValue(BL.SettingsKey.payPalCurrencyCode, this.DomainID); ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.Initialized, currencyCode); string payPalUrl = SetExpressCheckout(order, PayPalLandingPageUrl, PayPalLandingPageUrl, DomainService.GetSettingsValue(BL.SettingsKey.payPalUsername, this.DomainID), DomainService.GetSettingsValue(BL.SettingsKey.payPalPassword, this.DomainID), DomainService.GetSettingsValue(BL.SettingsKey.payPalSignature, this.DomainID), currencyCode, PayPalApiUrlNvp, DomainService.GetSettingsValue(BL.SettingsKey.payPalCgiUrl, this.DomainID), order.OrderID.ToString(), DomainService.GetSettingsValue(BL.SettingsKey.payPalLanguageCode, this.DomainID)); if (!string.IsNullOrEmpty(payPalUrl)) { return(new RedirectResult(payPalUrl)); } } } return(RedirectToRoute("Website", new { action = "PaymentError", orderID = orderID.ToString() })); }
public ActionResult Payment(int orderID = 0) { if (orderID > 0) { tbl_Orders order = ECommerceService.GetOrderByID(orderID); if (order == null) { throw new Exception("No order has been found"); } string currencyCode = DomainService.GetSettingsValue(SettingsKey.secureTradingCurrencyCode, this.DomainID); ECommerceService.UpdateOrderPaymentStatus(order.OrderID, PaymentStatus.Initialized, currencyCode); return(new RedirectResult(UrlConstructor(order))); } return(RedirectToRoute("Website", new { action = "PaymentError", orderID = orderID.ToString() })); }
public ActionResult Payment(int orderID = 0) { if (orderID <= 0) { return(RedirectToRoute("Website", new { action = "PaymentError", orderID = orderID.ToString() })); } tbl_Orders order = _eCommerceService.GetOrderByID(orderID); if (order == null) { throw new Exception("No order has been found"); } return(View()); }
public ActionResult Payment(int orderID) { string errorMessage = string.Empty; tbl_Orders order = ECommerceService.GetOrderByID(orderID); if (order == null) { return(RedirectToAction("PaymentError", "Website", new { orderID = orderID, errorMessage = "Can not find order." })); } SagePayMvc.Configuration.Configure(SagePayConfiguration); var shoppingBasket = new ShoppingBasket(order.OrderID.ToString()); shoppingBasket.Add(new BasketItem(1, "Order number: " + order.OrderID, order.TotalAmountToPay)); var billingAddress = new Address() { Address1 = order.BillingAddress1, Address2 = order.BillingAddress2 + " " + order.BillingAddress3, City = order.BillingCity, Country = order.BillingCountry, Firstnames = order.BillingFirstnames, Phone = order.BillingPhone, PostCode = order.BillingPostCode, State = order.BillingCountry == StateCountryCode?order.BillingState.Substring(0, 2) : String.Empty, Surname = order.BillingSurname }; var deliveryAddress = order.IsDeliverable ? new Address() { Address1 = order.DeliveryAddress1, Address2 = order.DeliveryAddress2 + " " + order.DeliveryAddress3, City = order.DeliveryCity, Country = order.DeliveryCountry, Firstnames = order.DeliveryFirstnames, Phone = order.DeliveryPhone, PostCode = order.DeliveryPostCode, State = order.DeliveryCountry == StateCountryCode?order.DeliveryState.Substring(0, 2) : String.Empty, Surname = order.DeliverySurname } : null; var creditCard = SessionManager.CreditCard; var cardInfo = creditCard == null ? new CreditCardInfo() : new CreditCardInfo() { CardHolder = creditCard.CardHolder, CardNumber = creditCard.CardNumber, CardType = creditCard.CardType.ToString(), CV2 = creditCard.CV2, ExpiryDate = creditCard.ExpiryDate }; string vendorTxCode = Guid.NewGuid().ToString(); TransactionRegistrar request; TransactionRegistrationResponse response; string currency = DomainService.GetSettingsValue(BL.SettingsKey.sagePayCurrencyCode, this.DomainID); try { request = new SagePayMvc.TransactionRegistrar(SagePayConfiguration, UrlResolver.Current, new HttpRequestSender()); response = request.Send(Request.RequestContext, vendorTxCode, shoppingBasket, billingAddress, order.IsDeliverable ? deliveryAddress : billingAddress, order.CustomerEMail, cardInfo, PaymentFormProfile.Normal, currency, order.GiftAid.GetValueOrDefault(false)); } catch (Exception e) { errorMessage = "Sage Pay payment error."; Log.Fatal(errorMessage, e); return(RedirectToAction("PaymentError", "Website", new { orderID = order.OrderID, errorMessage })); } if (response != null) { ECommerceService.UpdateOrderPayment(vendorTxCode, response.AddressResult, String.Empty, response.AVSCV2, response.CAVV, response.CV2Result, order.GiftAid.GetValueOrDefault(false), response.PostCodeResult, String.Empty, string.Empty, response.SecurityKey, response.Status.ToString(), response.TxAuthNo, response.VPSTxId, response.ThreeDSecureStatus.ToString(), BL.SagePayTxType.PAYMENT.ToString(), currency, orderID); if (PaymentType == PaymentType.Server && response.Status == ResponseType.Ok && response.TxAuthNo != 0) { return(Redirect(response.NextURL)); } else if (PaymentType == PaymentType.Direct && (response.Status == ResponseType.Ok || response.Status == ResponseType.Registered || response.Status == ResponseType.Authenticated) && response.TxAuthNo != 0) { ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.Paid); return(RedirectToAction("ThankYou", "Website", new { orderID = order.OrderID })); } else if (PaymentType == PaymentType.Direct && response.Status == ResponseType.ThreeDAuth && !string.IsNullOrWhiteSpace(response.ACSURL)) { return(RedirectToAction("OrderSummaryWithIFrame", "Website", new { md = response.MD, pareq = response.PAReq, vendorTxCode = vendorTxCode, ACSURL = response.ACSURL })); } errorMessage = response.StatusDetail; Log.Warn(String.Format("Payment failed for order '{0}', status: '{1}', details '{2}' ", vendorTxCode, response.Status.ToString(), response.StatusDetail)); } else { ECommerceService.UpdateOrderPayment(vendorTxCode, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, (bool?)null, String.Empty, String.Empty, String.Empty, String.Empty, ResponseType.Error.ToString(), 0, String.Empty, String.Empty, BL.SagePayTxType.PAYMENT.ToString(), String.Empty, orderID); } return(RedirectToAction("PaymentError", "Website", new { orderID = order.OrderID, errorMessage })); }