protected override void handleDeliveryTypeChanged(DropDownList DeliveryType, DropDownList DropdownNickName) { CheckDSMailingAddress(false, null); DeliveryOptionType deliveryType = getDeliveryOptionTypeFromDropdown(DeliveryType); if (null != DropdownNickName) { DropdownNickName.Attributes.Remove("style"); } ShoppingCart.DeliveryInfo = null; if (deliveryType == DeliveryOptionType.Shipping || deliveryType == DeliveryOptionType.ShipToCourier) { populateShipping(); setAddressByNickName(ShoppingCart.DeliveryInfo == null ? null : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping ? ShoppingCart.DeliveryInfo.Address : null)); } else if (deliveryType == DeliveryOptionType.PickupFromCourier) { populatePickupPreference(); setAddressByNickName(ShoppingCart.DeliveryInfo == null ? null : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.PickupFromCourier ? ShoppingCart.DeliveryInfo.Address : null)); } else { if (CountryCode == "BR") { var mailingAdd = new ShippingAddress_V01(1, DistributorProfileModelHelper.DistributorName(DistributorProfileModel), ObjectMappingHelper.Instance.GetToShipping(DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, DistributorID, CountryCode)), string.Empty, string.Empty, false, string.Empty, DateTime.Now); if (CheckDSMailingAddress(true, mailingAdd)) { populatePickup(); setAddressByNickName(ShoppingCart.DeliveryInfo == null ? null : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup ? ShoppingCart.DeliveryInfo.Address : null)); } } else { populatePickup(); setAddressByNickName(ShoppingCart.DeliveryInfo == null ? null : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup ? ShoppingCart.DeliveryInfo.Address : null)); } } showShiptoOrPickup(IsStatic); }
/// <summary> /// Suggests a name for the cart to be saved. /// </summary> /// <param name="cartName">The initial cart name</param> /// <returns></returns> public static string SuggestCartName(ShippingInfo deliveryInfo, string cartName, string distributorID, string locale) { string suggestedName = cartName; if (string.IsNullOrEmpty(suggestedName)) { if (deliveryInfo != null) { if (deliveryInfo.Option == DeliveryOptionType.Shipping) { suggestedName = deliveryInfo.Address.Recipient ?? string.Empty; } else { suggestedName = DistributorProfileModelHelper.DistributorName( ((MembershipUser <DistributorProfileModel>)Membership.GetUser()).Value); } } if (string.IsNullOrEmpty(suggestedName)) { return(suggestedName); } } else { Match match = Regex.Match(suggestedName, @"([A-Za-z0-9\-\s_]+)_\d+"); if (match.Success) { suggestedName = match.Groups[1].Value; } } var savedCarts = ShoppingCartProvider.GetCarts(distributorID, locale); int index = 0; if (savedCarts != null && savedCarts.Count > 0) { index = savedCarts.Count( c => !string.IsNullOrEmpty(c.CartName) && c.CartName.ToUpper().StartsWith(suggestedName.ToUpper())); } return((index == 0) ? suggestedName : string.Format("{0}_{1}", suggestedName, index + 1)); }
//Name:GenerateXmlRequest //Description:Generate the xml file for the PayOrder Request // private string GenerateXmlRequest(string returnUrlApproved, string returnUrlDeclined) { MyHLShoppingCart myCart; SessionInfo sessionInfoMyCart = SessionInfo.GetSessionInfo(this._distributorId, this._locale); myCart = sessionInfoMyCart.ShoppingCart ?? ShoppingCartProvider.GetShoppingCart(this._distributorId, this._locale); try { #region "create Skeleton" // Create Skeleton decimal taxBrazil = 0.90m; var xmlToSend = new XDocument(); var xDeclaration = new XDeclaration("1.0", "UTF-8", "no"); xmlToSend.Declaration = xDeclaration; var xmlRoot = new XElement("payOrder"); xmlToSend.Add(xmlRoot); var order_data = new XElement("order_data"); var behavior_data = new XElement("behavior_data"); var payment_data = new XElement("payment_data"); var customer_data = new XElement("customer_data"); xmlRoot.Add(order_data); xmlRoot.Add(behavior_data); xmlRoot.Add(payment_data); xmlRoot.Add(customer_data); #endregion #region "order data section" //Fill order data section order_data.Add(new XElement("merch_ref", OrderNumber)); order_data.Add(new XElement("origin", "E-commerce")); order_data.Add(new XElement("currency", "BRL")); order_data.Add(new XElement("tax_boarding", 0)); order_data.Add(new XElement("tax_freight", 0)); order_data.Add(new XElement("tax_others", 0)); order_data.Add(new XElement("discount_plus", 0)); order_data.Add(new XElement("order_subtotal", (string.Format(getPriceFormat(_orderAmount + taxBrazil), _orderAmount + taxBrazil).Replace(".", "")) .Replace(",", ""))); // Only positive values are accepted.Value without formatting.Two last digits are cents. Eg. 1234 = 12.34. order_data.Add(new XElement("interests_value", 0)); order_data.Add(new XElement("order_total", (string.Format(getPriceFormat(_orderAmount + taxBrazil), _orderAmount + taxBrazil).Replace(".", "")) .Replace(",", ""))); var order_items = new XElement("order_items"); order_data.Add(order_items); #endregion #region "order items section" order_items.Add(new XElement("order_item", new XElement("code", "Grand Total"), new XElement("description", "Grand Total"), new XElement("units", 1), new XElement("unit_value", (string.Format( getPriceFormat(_orderAmount + taxBrazil), _orderAmount + taxBrazil).Replace(".", "")) .Replace(",", "")))); #endregion #region "behavior_data section" //Fill behavior_data section behavior_data.Add(new XElement("language", "ptbr")); behavior_data.Add(new XElement("url_post_bell", (string.Format("{0}?Agency=bankslipboldcron&Bell=bell&merch_ref={1}", returnUrlApproved, OrderNumber)))); behavior_data.Add(new XElement("url_redirect_success", (string.Format( "{0}?Agency=bankslipboldcron&merchant=herbalife&merch_ref={1}", returnUrlApproved, OrderNumber)))); behavior_data.Add(new XElement("url_redirect_error", (string.Format("{0}?Agency=bankslipboldcron", returnUrlDeclined)))); #endregion #region "payment_data section" //Fill payment_data section payment_data.Add(new XElement("payment", new XElement("payment_method", "boleto_bradesco"))); #endregion #region "Customer data section" //Fill customer_data section customer_data.Add(new XElement("customer_id", _distributorId)); customer_data.Add(new XElement("customer_eval", 0)); var customer_info = new XElement("customer_info"); customer_data.Add(customer_info); string DistributorName = DistributorProfileModelHelper.DistributorName(DistributorProfileModel); //Fill customer_information inside customer_data section customer_info.Add(new XElement("first_name", DistributorName ?? string.Empty)); customer_info.Add(new XElement("email", null != myCart.EmailAddress ? myCart.EmailAddress : string.Empty)); //Fill billing_information inside customer_data section var billing_info = new XElement("billing_info"); customer_data.Add(billing_info); billing_info.Add(new XElement("first_name", DistributorName ?? string.Empty)); billing_info.Add(new XElement("email", null != myCart.EmailAddress ? myCart.EmailAddress : string.Empty)); //Fill shipment_info inside customer_data section var shipment_info = new XElement("shipment_info"); customer_data.Add(shipment_info); shipment_info.Add(new XElement("first_name", DistributorName ?? string.Empty)); shipment_info.Add(new XElement("email", null != myCart.EmailAddress ? myCart.EmailAddress : string.Empty)); #endregion // xmlToSend.Save("C:\\XMLRequest Files\\bradesco.xml"); String xmlReadyToSend; xmlReadyToSend = xmlToSend.Declaration + xmlToSend.Root.ToString(); return(xmlReadyToSend); } catch (Exception) { throw; } }
private string BuildInfo(string transactionType) { decimal taxBrazil = 0.90m; MyHLShoppingCart myCart; SessionInfo sessionInfoMyCart = SessionInfo.GetSessionInfo(this._distributorId, this._locale); myCart = sessionInfoMyCart.ShoppingCart; if (myCart == null) { myCart = ShoppingCartProvider.GetShoppingCart(this._distributorId, this._locale); } string DistributorName = DistributorProfileModelHelper.DistributorName(DistributorProfileModel); InstallmentConfiguration _installmentsConfiguration; DateTime currentDate; OrderMonth orderMonth = new OrderMonth(myCart.CountryCode); currentDate = orderMonth.CurrentOrderMonth; var orderType = "RSO"; if (myCart.OrderCategory == OrderCategoryType.ETO) { orderType = "ETO"; } else if (myCart.OrderCategory == OrderCategoryType.APF) { orderType = "APF"; } _installmentsConfiguration = InstallmentsProvider.GetInstallmentsConfiguration(myCart.CountryCode, new DateTime(currentDate.Year, currentDate.Month, 1), orderType); if (_installmentsConfiguration == null) { DateTime today = DateTime.Today; currentDate = new DateTime(today.Year, today.Month, 1).AddMonths(1).AddDays(-1); } string paymentCode = _configHelper.GetConfigEntry("paymentCode"); string data; data = "VENDAID=" + this.OrderNumber + "@"; data = data + "VALOR=" + ((null != myCart.Totals ? _orderAmount : 0) + taxBrazil) + "@"; data = data + "NOME=" + (null != DistributorName ? DistributorName : string.Empty) + "@"; data = data + "CODPAGAMENTO=" + paymentCode + "@"; data = data + "LOGRADOURO=" + (null != myCart.DeliveryInfo.Address.Address.Line1 ? myCart.DeliveryInfo.Address.Address.Line1 : string.Empty) + "@"; data = data + "BAIRRO=" + (null != myCart.DeliveryInfo.Address.Address.Line2 ? myCart.DeliveryInfo.Address.Address.Line2 : string.Empty) + "@"; data = data + "CIDADE=" + (null != myCart.DeliveryInfo.Address.Address.City ? myCart.DeliveryInfo.Address.Address.City : string.Empty) + "@"; data = data + "ESTADO=" + (null != myCart.DeliveryInfo.Address.Address.StateProvinceTerritory ? myCart.DeliveryInfo.Address.Address.StateProvinceTerritory : string.Empty) + "@"; data = data + "CEP=" + (null != myCart.DeliveryInfo.Address.Address.PostalCode ? myCart.DeliveryInfo.Address.Address.PostalCode : string.Empty) + "@"; data = data + "INSTRUCOES=" + "Nao aceitar este boleto apos a data de vencimento # ** Tarifa Bancaria:R$ 0,90 # ** Valor da Nota Fiscal: " + _orderAmount + "@"; data = data + "EXTRA=" + (null != myCart.DistributorID ? myCart.DistributorID : string.Empty) + "@"; data = data + "PAIS=BRAZIL@"; data = data + "NOSSONUMERO=" + (null != this.OrderNumber ? this.OrderNumber.Remove(0, 2) : string.Empty) + "@"; data = data + "DATAVENCIMENTO=" + (_installmentsConfiguration == null ? currentDate.ToString("MM-dd-yyyy") : _installmentsConfiguration.TicketDueDate.ToString("yyyy-MM-dd")) + "@"; data = data + "TRANSACTIONCURRENCY=BRL@"; data = data + "TRANSACTIONCOUNTRY=BRA@"; data = data + "TRANSACTIONTYPE=" + transactionType; return(data); }
//Name:GenerateXmlRequest //Description:Generate the xml file for the BankSlip Request // private string GenerateXmlRequest(string returnUrl, string key, string password) { InstallmentConfiguration _installmentsConfiguration; #region "create Skeleton" decimal taxBrazil = 0.90m; MyHLShoppingCart myCart; SessionInfo sessionInfoMyCart = SessionInfo.GetSessionInfo(this._distributorId, this._locale); myCart = sessionInfoMyCart.ShoppingCart; if (myCart == null) { myCart = ShoppingCartProvider.GetShoppingCart(this._distributorId, this._locale); } // Create Skeleton XDocument xmlToSend = new XDocument(); XDeclaration xDeclaration = new XDeclaration("1.0", "utf-8", "no"); XNamespace aw = "http://wwww.w3.org/2001/XMLSchema-instance"; XNamespace aw1 = "http://wwww.w3.org/2001/XMLSchema"; XNamespace xn = "http://www2.superpag.com.br/Schemas"; xmlToSend.Declaration = xDeclaration; XElement xmlRoot = new XElement(xn + "RequisicaoPagamento", new XAttribute(XNamespace.Xmlns + "xsi", aw), new XAttribute(XNamespace.Xmlns + "xsd", aw1)); xmlToSend.Add(xmlRoot); XElement EstabelecimentoComercial_data = new XElement(xn + "EstabelecimentoComercial", new XAttribute("ChaveAutenticacao", key), new XAttribute("SenhaAutenticacao", password)); XElement Pagamento_data = new XElement(xn + "OrdemPagamento", new XAttribute("Codigo", this.OrderNumber)); EstabelecimentoComercial_data.Add(Pagamento_data); xmlRoot.Add(EstabelecimentoComercial_data); XElement Consumidor = new XElement(xn + "Consumidor"); Pagamento_data.Add(Consumidor); XElement DetalhesPessoaisDoConsumidor = new XElement(xn + "DetalhesPessoaisDoConsumidor"); Consumidor.Add(DetalhesPessoaisDoConsumidor); string DistributorName = DistributorProfileModelHelper.DistributorName(DistributorProfileModel); DetalhesPessoaisDoConsumidor.Add(new XElement(xn + "PessoaFisica", new XAttribute("Nome", null != DistributorName ? DistributorName : string.Empty))); XElement Emails = new XElement(xn + "Emails"); Consumidor.Add(Emails); Emails.Add(new XElement(xn + "Email", new XAttribute("Endereco", null != myCart.EmailAddress ? myCart.EmailAddress : string.Empty))); XElement Telefones = new XElement(xn + "Telefones"); Consumidor.Add(Telefones); Telefones.Add(new XElement(xn + "Telefone", new XAttribute("Tipo", "1"), new XAttribute("CodigoPais", "55"), new XAttribute("DDD", null != myCart.DeliveryInfo.Address.AreaCode ? myCart.DeliveryInfo.Address.AreaCode : string.Empty), new XAttribute("Numero", null != myCart.DeliveryInfo.Address.Phone ? myCart.DeliveryInfo.Address.Phone : string.Empty))); XElement EnderecoCobranca = new XElement(xn + "EnderecoCobranca", ""); Pagamento_data.Add(EnderecoCobranca); string address = string.Empty; if (myCart.DeliveryInfo.Address.Address.Line1 != null && myCart.DeliveryInfo.Address.Address.Line1.Length > 60) { address = myCart.DeliveryInfo.Address.Address.Line1.Substring(0, 60); } else { address = myCart.DeliveryInfo.Address.Address.Line1; } EnderecoCobranca.Add(new XElement(xn + "Endereco", new XAttribute("Logradouro", null != myCart.DeliveryInfo.Address.Address.Line1 ? address : string.Empty), new XAttribute("Numero", ""), new XAttribute("Cep", null != myCart.DeliveryInfo.Address.Address.PostalCode ? myCart.DeliveryInfo.Address.Address.PostalCode : string.Empty), new XAttribute("Complemento", ""), new XAttribute("Bairro", null != myCart.DeliveryInfo.Address.Address.Line2 ? myCart.DeliveryInfo.Address.Address.Line2 : string.Empty), new XAttribute("Cidade", null != myCart.DeliveryInfo.Address.Address.City ? myCart.DeliveryInfo.Address.Address.City : string.Empty), new XAttribute("UF", null != myCart.DeliveryInfo.Address.Address.StateProvinceTerritory ? myCart.DeliveryInfo.Address.Address.StateProvinceTerritory : string.Empty), new XAttribute("Pais", "BRAZIL"))); XElement EnderecoEntrega = new XElement(xn + "EnderecoEntrega", ""); Pagamento_data.Add(EnderecoEntrega); EnderecoEntrega.Add(new XElement(xn + "Endereco", new XAttribute("Logradouro", null != myCart.DeliveryInfo.Address.Address.Line1 ? address : string.Empty), new XAttribute("Numero", ""), new XAttribute("Cep", null != myCart.DeliveryInfo.Address.Address.PostalCode ? myCart.DeliveryInfo.Address.Address.PostalCode : string.Empty), new XAttribute("Complemento", ""), new XAttribute("Bairro", null != myCart.DeliveryInfo.Address.Address.Line2 ? myCart.DeliveryInfo.Address.Address.Line2 : string.Empty), new XAttribute("Cidade", null != myCart.DeliveryInfo.Address.Address.City ? myCart.DeliveryInfo.Address.Address.City : string.Empty), new XAttribute("UF", null != myCart.DeliveryInfo.Address.Address.StateProvinceTerritory ? myCart.DeliveryInfo.Address.Address.StateProvinceTerritory : string.Empty), new XAttribute("Pais", "BRAZIL"))); #region Items XElement ItemsDaOrdem = new XElement(xn + "ItensDaOrdem"); Pagamento_data.Add(ItemsDaOrdem); // Fill order items section foreach (var item in myCart.ShoppingCartItems) { ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", item.ID), new XAttribute("Valor", Math.Round((item.DiscountPrice / item.Quantity), 2)), new XAttribute("Quantidade", item.Quantity), new XAttribute("Descricao", item.Description))); } OrderTotals_V01 totals = myCart.Totals as OrderTotals_V01; //ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", "01"), // new XAttribute("Valor", myCart.Totals.DiscountedItemsTotal), // new XAttribute("Quantidade", 1), // new XAttribute("Descricao", "Desconto"))); ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", "02"), new XAttribute("Valor", null != totals ? totals.TaxAmount : 0), new XAttribute("Quantidade", 1), new XAttribute("Descricao", "Impostos"))); Charge_V01 pHCharge = new Charge_V01(); Charge_V01 freightCharge = new Charge_V01(); if (null != totals && null != totals.ChargeList) { pHCharge = GetCharge(totals.ChargeList, ChargeTypes.PH); freightCharge = GetCharge(totals.ChargeList, ChargeTypes.FREIGHT); } ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", "03"), new XAttribute("Valor", (null != pHCharge ? pHCharge.Amount : 0) + (null != freightCharge ? freightCharge.Amount : 0)), new XAttribute("Quantidade", 1), new XAttribute("Descricao", "Manuseio"))); ItemsDaOrdem.Add(new XElement(xn + "Item", new XAttribute("Codigo", "04"), new XAttribute("Valor", taxBrazil), new XAttribute("Quantidade", 1), new XAttribute("Descricao", "Tarifa Bancaria"))); #endregion XElement Pagamento = new XElement(xn + "Pagamento", new XAttribute("ValorTotal", (null != myCart.Totals ? _orderAmount : 0) + taxBrazil), new XAttribute("Data", System.DateTime.Now.Date.ToString("yyyy-MM-dd")), new XAttribute("Batch", "False"), new XAttribute("Email", null != myCart.EmailAddress ? myCart.EmailAddress : string.Empty)); Pagamento_data.Add(Pagamento); XElement DetalheDoMeioDePagamento = new XElement(xn + "DetalheDoMeioDePagamento", new XAttribute("MeioPagamento", "BLT")); Pagamento.Add(DetalheDoMeioDePagamento); DateTime currentDate; OrderMonth orderMonth = new OrderMonth(myCart.CountryCode); currentDate = orderMonth.CurrentOrderMonth; var orderType = "RSO"; if (myCart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.ETO) { orderType = "ETO"; } else if (myCart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.APF) { orderType = "APF"; } _installmentsConfiguration = InstallmentsProvider.GetInstallmentsConfiguration(myCart.CountryCode, new DateTime(currentDate.Year, currentDate.Month, 1), orderType); if (_installmentsConfiguration == null) { DateTime today = DateTime.Today; currentDate = new DateTime(today.Year, today.Month, 1).AddMonths(1).AddDays(-1); } DetalheDoMeioDePagamento.Add(new XElement(xn + "Boleto", new XAttribute("Banco", "237"), new XAttribute("DataVencimento", (_installmentsConfiguration == null) ? currentDate.ToString("yyyy-MM-dd") : _installmentsConfiguration.TicketDueDate.ToString("yyyy-MM-dd")), new XAttribute("NossoNumero", this.OrderNumber.Remove(0, 2)), new XAttribute("Instrucoes", "Nao aceitar este boleto apos a data de vencimento # ** Tarifa Bancaria:R$ 0,90 # ** Valor da Nota Fiscal: " + _orderAmount + " "))); XElement Parcelamento = new XElement(xn + "Parcelamento"); Pagamento.Add(Parcelamento); Parcelamento.Add(new XElement(xn + "Parcelas", new XAttribute("Quantidade", "1"), new XAttribute("Juros", "00.00"), new XAttribute("TipoJuros", "Aquirer"), new XAttribute("FormaParcelamento", "Integral"))); XElement Setup = new XElement(xn + "Setup", ""); Pagamento_data.Add(Setup); Setup.Add(new XElement(xn + "PostRetorno", new XAttribute("Url", (string.Format("{0}?Agency=BankSlip", returnUrl))))); String xmlReadyToSend; xmlReadyToSend = xmlToSend.Declaration.ToString() + xmlToSend.Root.ToString(); return(xmlReadyToSend); #endregion }