public void BindView() { var currentCustomer = AspDotNetStorefrontCore.Customer.Current; var shoppingCart = new AspDotNetStorefrontCore.ShoppingCart(currentCustomer.SkinID, currentCustomer, AspDotNetStorefrontCore.CartTypeEnum.ShoppingCart, 0, false); decimal shipTotal = Math.Round(this.ShoppingCartModel.ShippingTotal, 2, MidpointRounding.AwayFromZero); decimal subTotal = Math.Round(this.ShoppingCartModel.SubTotal, 2, MidpointRounding.AwayFromZero); decimal discount = Math.Round(this.ShoppingCartModel.Discount1, 2, MidpointRounding.AwayFromZero); decimal total = Math.Round(this.ShoppingCartModel.Total, 2, MidpointRounding.AwayFromZero); this.ShipMethodAmount.Text = Localization.CurrencyStringForDisplayWithExchangeRate(shipTotal, currentCustomer.CurrencySetting); this.TaxAmount.Text = Localization.CurrencyStringForDisplayWithExchangeRate(this.ShoppingCartModel.TaxTotal, currentCustomer.CurrencySetting); this.SubTotal.Text = Localization.CurrencyStringForDisplayWithExchangeRate(subTotal, currentCustomer.CurrencySetting); this.ShippingMethod.Text = this.ShoppingCartModel.ShippingMethod; QuantityDiscountRow.Visible = (this.ShoppingCartModel.Discount2 > decimal.Zero); LabelQuantityDiscountAmount.Text = Localization.CurrencyStringForDisplayWithExchangeRate(this.ShoppingCartModel.Discount2 * -1, currentCustomer.CurrencySetting); Decimal lineItemDiscount = shoppingCart.DiscountResults.Sum(dr => dr.LineItemTotal); Decimal orderItemDiscount = shoppingCart.DiscountResults.Sum(dr => dr.OrderTotal); LineItemDiscountRow.Visible = lineItemDiscount < 0; OrderItemDiscountRow.Visible = orderItemDiscount < 0; LineItemDiscountLabel.Text = "shoppingcart.cs.200".StringResource(); OrderItemDiscountLabel.Text = "shoppingcart.cs.201".StringResource(); LineItemDiscount.Text = Localization.CurrencyStringForDisplayWithExchangeRate(lineItemDiscount, currentCustomer.CurrencySetting); OrderItemDiscount.Text = Localization.CurrencyStringForDisplayWithExchangeRate(orderItemDiscount, currentCustomer.CurrencySetting); this.Total.Text = Localization.CurrencyStringForDisplayWithExchangeRate(total, currentCustomer.CurrencySetting); trTaxAmounts.Visible = !AppLogic.AppConfigBool("VAT.Enabled") || AspDotNetStorefrontCore.Customer.Current.VATSettingReconciled != VATSettingEnum.ShowPricesInclusiveOfVAT; }
public ExternalPaymentMethodContext BeginCheckout(AspDotNetStorefrontCore.ShoppingCart cart) { decimal amount = cart.Total(true); GatewayMoneybookers.PaymentType paymentType = GatewayMoneybookers.PaymentType.Capture; string customerIpAddress = CommonLogic.CustomerIpAddress(); if (customerIpAddress == "::1") { customerIpAddress = "127.0.0.1"; } else if (customerIpAddress.Contains(":")) { throw new Exception("The Moneybookers payment gateway does not support IPv6."); } // Generate payment request GatewayMoneybookers.PaymentRequestBuilder requestBuilder = new GatewayMoneybookers.PaymentRequestBuilder(); var paymentRequest = requestBuilder.BuildQuickCheckoutRequest( GetEncryptedTransactionId(cart, amount), cart.ThisCustomer.CustomerID, cart.ThisCustomer.EMail, cart.ThisCustomer.PrimaryBillingAddress.FirstName, cart.ThisCustomer.PrimaryBillingAddress.LastName, cart.ThisCustomer.PrimaryBillingAddress.Address1, cart.ThisCustomer.PrimaryBillingAddress.City, CommonLogic.IIF(String.IsNullOrEmpty(cart.ThisCustomer.PrimaryBillingAddress.State), null, cart.ThisCustomer.PrimaryBillingAddress.State), cart.ThisCustomer.PrimaryBillingAddress.Zip, cart.ThisCustomer.PrimaryBillingAddress.Country, customerIpAddress, amount); GatewayMoneybookers.PaymentXmlTransformer <GatewayMoneybookers.VirtualAccountPaymentMethod> paymentTransformer = new GatewayMoneybookers.PaymentXmlTransformer <GatewayMoneybookers.VirtualAccountPaymentMethod>(); var paymentRequestData = paymentTransformer.TransformRequest(paymentRequest, new VirtualAccountPaymentMethodXmlTransformer()); // Submit request and get response string paymentResponseData = null; string result = String.Empty; int maxAttempts = AppLogic.AppConfigUSInt("GatewayRetries") + 1; for (int attemptCount = 0; attemptCount < maxAttempts; attemptCount++) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestUri); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; try { using (var requestStream = request.GetRequestStream()) { using (StreamWriter requestWriter = new StreamWriter(requestStream)) { requestWriter.Write("load={0}", Uri.EscapeDataString(paymentRequestData)); requestWriter.Close(); } requestStream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (var responseStream = response.GetResponseStream()) { using (StreamReader responseReader = new StreamReader(responseStream)) { paymentResponseData = responseReader.ReadToEnd(); responseReader.Close(); } responseStream.Close(); } break; } #if DEBUG catch (WebException exception) { using (var responseStream = exception.Response.GetResponseStream()) { using (StreamReader responseReader = new StreamReader(responseStream)) { result = String.Format("Error calling Skrill (Moneybookers) payment gateway. {0}{1}", exception.Message, responseReader.ReadToEnd()); responseReader.Close(); } responseStream.Close(); } } #endif catch (Exception exception) { result = String.Format("Error calling Skrill (Moneybookers) payment gateway. {0}", exception.Message); } } // Process response if (paymentResponseData != null) { GatewayMoneybookers.PaymentResponse paymentResponse = paymentTransformer.TransformResponse(paymentResponseData); result = String.Format("{0} - {1} - {2} - {3}", paymentResponse.Result, paymentResponse.Status, paymentResponse.Reason, paymentResponse.Return); if (paymentResponse.Result.ToUpperInvariant() == "ACK") { return(new ExternalPaymentMethodContext(result, paymentResponse.RedirectUrl, paymentResponse.RedirectParameters)); } else { if (result.Length == 0) { result = "Unspecified Error"; } return(new ExternalPaymentMethodContext(result)); } } else { return(new ExternalPaymentMethodContext(result)); } }
private string GetEncryptedTransactionId(AspDotNetStorefrontCore.ShoppingCart cart, decimal cartTotal) { return(Security.MungeString(GenerateTransactionId(cart, cartTotal))); }
private string GenerateTransactionId(AspDotNetStorefrontCore.ShoppingCart cart, decimal cartTotal) { return(String.Format("{0}{1}{2}{3}", cart.ShipCalcID, cart.ThisCustomer.CustomerGUID, cartTotal, cart.FirstCartItem.ShoppingCartRecordID)); }