public TransactionRegistrationResponse Send(RequestContext context, string vendorTxCode, ShoppingBasket basket, Address billingAddress, Address deliveryAddress, string customerEmail) { string sagePayUrl = configuration.RegistrationUrl; string notificationUrl = urlResolver.BuildNotificationUrl(context); var registration = new TransactionRegistration( vendorTxCode, basket, notificationUrl, billingAddress, deliveryAddress, customerEmail, configuration.VendorName); var serializer = new HttpPostSerializer(); var postData = serializer.Serialize(registration); var response = requestSender.SendRequest(sagePayUrl, postData); var deserializer = new ResponseSerializer(); return deserializer.Deserialize<TransactionRegistrationResponse>(response); }
public TransactionRegistrationResponse Send(RequestContext context, string vendorTxCode, ShoppingBasket basket, Address billingAddress, Address deliveryAddress, string customerEmail, PaymentFormProfile paymentFormProfile = PaymentFormProfile.Normal, string currencyCode="GBP", MerchantAccountType accountType=MerchantAccountType.Ecommerce, TxType txType=TxType.Payment) { string sagePayUrl = configuration.RegistrationUrl; string notificationUrl = urlResolver.BuildNotificationUrl(context); var registration = new TransactionRegistration( vendorTxCode, basket, notificationUrl, billingAddress, deliveryAddress, customerEmail, configuration.VendorName, paymentFormProfile, currencyCode, accountType, txType); var serializer = new HttpPostSerializer(); var postData = serializer.Serialize(registration); var response = requestSender.SendRequest(sagePayUrl, postData); var deserializer = new ResponseSerializer(); return deserializer.Deserialize<TransactionRegistrationResponse>(response); }
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 }); }