protected void Page_Load(object sender, EventArgs e) { //GCheckoutButton1 = new GCheckoutButton(); //CheckoutShoppingCartRequest Req = GCheckoutButton1.CreateRequest(); //Req.AddItem("Snickers", "Packed with peanuts.", 0.75m, 2); //GCheckout.Util.GCheckoutResponse Resp = Req.Send(); //Response.Redirect(Resp.RedirectUrl, true); //GCheckout.Util.GCheckoutResponse responce = histroey.Send(); //GCheckout.Checkout.CheckoutShoppingCartRequest sad = new GCheckout.Checkout.CheckoutShoppingCartRequest("417255259260942", "LzWjnZDmrxRiA0UlIUfeSg", GCheckout.EnvironmentType.Sandbox, "GBP", 10, false); GCheckout.Checkout.CheckoutShoppingCartRequest CheckoutShoppingCartRequest = new GCheckout.Checkout.CheckoutShoppingCartRequest("417255259260942", "LzWjnZDmrxRiA0UlIUfeSg", GCheckout.EnvironmentType.Sandbox, "GBP", 10, false); GCheckout.Checkout.ShoppingCartItem ShoppingCartItem = new GCheckout.Checkout.ShoppingCartItem(); ShoppingCartItem.Description = "itsm one DEsc"; ShoppingCartItem.Name = "item 01 "; ShoppingCartItem.Price = Convert.ToDecimal("10.00"); ShoppingCartItem.Quantity = 1; ShoppingCartItem.MerchantPrivateItemData = "<Orderid>10</Orderid>"; CheckoutShoppingCartRequest.AddItem(ShoppingCartItem); GCheckout.Util.GCheckoutResponse Resp = CheckoutShoppingCartRequest.Send(); Response.Redirect(Resp.RedirectUrl,true); //https://417255259260942:[email protected]/checkout/api/checkout/v2/requestForm/Merchant/417255259260942 string serial = Request["serial-number"]; // do my stuff var ack = new GCheckout.AutoGen.NotificationAcknowledgment(); ack.serialnumber = serial; StringBuilder stb = new StringBuilder(); stb.Append(GCheckout.Util.EncodeHelper.Serialize(ack)); // Response.BinaryWrite(GCheckout.Util.EncodeHelper.Serialize(ack)); /// Response.StatusCode = 200; }
void btnGoogleCheckout_Click(object sender, ImageClickEventArgs e) { if ( (store != null) && (cart != null) ) { //&& (IsValidForCheckout()) ? int cartTimeoutInMinutes = 30; CheckoutShoppingCartRequest Req = new CheckoutShoppingCartRequest( commerceConfig.GoogleMerchantID, commerceConfig.GoogleMerchantKey, commerceConfig.GoogleEnvironment, siteSettings.GetCurrency().Code, cartTimeoutInMinutes); foreach (CartOffer cartOffer in cartOffers) { Req.AddItem( cartOffer.Name, string.Empty, cartOffer.OfferPrice, cartOffer.Quantity); } //Req.AddMerchantCalculatedShippingMethod //Req.AnalyticsData //Req.ContinueShoppingUrl //Req.EditCartUrl //Req.RequestInitialAuthDetails //Req.AddParameterizedUrl // we need to serialize the cart and it items to xml here // so when we get it back from google // we can validate against the existing cart // as its possible items were added to the cart // after we passed the user to google //Req.MerchantPrivateData = cart.CartGuid.ToString(); //cart.SerializeCartOffers(); //Req.MerchantPrivateData = SerializationHelper.SerializeToSoap(cart); cart.SerializeCartOffers(); MerchantData merchantData = new MerchantData(); merchantData.ProviderName = "WebStoreGCheckoutNotificationHandlerProvider"; merchantData.SerializedObject = SerializationHelper.RemoveXmlDeclaration(SerializationHelper.SerializeToString(cart)); Req.MerchantPrivateData = SerializationHelper.RemoveXmlDeclaration(SerializationHelper.SerializeToString(merchantData)); Req.RequestBuyerPhoneNumber = true; // flat rate shipping example //Req.AddFlatRateShippingMethod("UPS Ground", 5); //Add a rule to tax all items at 7.5% for Ohio //Req.AddStateTaxRule("NC", .15, true); //TODO: lookup tax GCheckoutResponse Resp = Req.Send(); if (Resp.IsGood) { Response.Redirect(Resp.RedirectUrl, true); } else { lblMessage.Text = Resp.ErrorMessage; } } }
/// <summary> /// Post cart to google /// </summary> /// <param name="req">Pre-generated request</param> /// <param name="cart">Shopping cart</param> /// <returns>Response</returns> public GCheckoutResponse PostCartToGoogle(CheckoutShoppingCartRequest req, IList<Core.Domain.Orders.ShoppingCartItem> cart) { //there's no need to round prices (Math.Round(,2)) because GCheckout library does it for us //items foreach (Core.Domain.Orders.ShoppingCartItem sci in cart) { var productVariant = sci.ProductVariant; if (productVariant != null) { decimal taxRate = decimal.Zero; string description = _productAttributeFormatter.FormatAttributes(productVariant, sci.AttributesXml, _workContext.CurrentCustomer, ", ", false, true, true, true, false); string fullName = ""; if (!String.IsNullOrEmpty(sci.ProductVariant.GetLocalized(x => x.Name))) fullName = string.Format("{0} ({1})", sci.ProductVariant.Product.GetLocalized(x => x.Name), sci.ProductVariant.GetLocalized(x => x.Name)); else fullName = sci.ProductVariant.Product.GetLocalized(x => x.Name); decimal unitPrice = _taxService.GetProductPrice(sci.ProductVariant, _priceCalculationService.GetUnitPrice(sci, true), out taxRate); req.AddItem(fullName, description, sci.Id.ToString(), unitPrice, sci.Quantity); } } if (cart.RequiresShipping()) { //AddMerchantCalculatedShippingMethod //AddCarrierCalculatedShippingOption var shippingOptions = _shippingService.GetShippingOptions(cart, null); foreach (ShippingOption shippingOption in shippingOptions.ShippingOptions) { //adjust rate Discount appliedDiscount = null; var shippingTotal = _orderTotalCalculationService.AdjustShippingRate( shippingOption.Rate, cart, out appliedDiscount); decimal shippingRateBase = _taxService.GetShippingPrice(shippingTotal, _workContext.CurrentCustomer); req.AddFlatRateShippingMethod(shippingOption.Name, shippingRateBase); } } //add only US, GB states //CountryCollection countries = IoC.Resolve<ICountryService>().GetAllCountries(); //foreach (Country country in countries) //{ // foreach (StateProvince state in country.StateProvinces) // { // TaxByStateProvinceCollection taxByStateProvinceCollection = TaxByIoC.Resolve<IStateProvinceService>().GetAllByStateProvinceID(state.StateProvinceID); // foreach (TaxByStateProvince taxByStateProvince in taxByStateProvinceCollection) // { // if (!String.IsNullOrEmpty(state.Abbreviation)) // { // Req.AddStateTaxRule(state.Abbreviation, (double)taxByStateProvince.Percentage, false); // } // } // } //} //if (subTotalDiscountBase > decimal.Zero) //{ // req.AddItem("Discount", string.Empty, string.Empty, (decimal)(-1.0) * subTotalDiscountBase, 1); //} //foreach (AppliedGiftCard agc in appliedGiftCards) //{ // req.AddItem(string.Format("Gift Card - {0}", agc.GiftCard.GiftCardCouponCode), string.Empty, string.Empty, (decimal)(-1.0) * agc.AmountCanBeUsed, 1); //} var customerInfoDoc = new XmlDocument(); XmlElement customerInfo = customerInfoDoc.CreateElement("CustomerInfo"); customerInfo.SetAttribute("CustomerID", _workContext.CurrentCustomer.Id.ToString()); customerInfo.SetAttribute("CustomerLanguageID", _workContext.WorkingLanguage.Id.ToString()); customerInfo.SetAttribute("CustomerCurrencyID", _workContext.WorkingCurrency.Id.ToString()); req.AddMerchantPrivateDataNode(customerInfo); req.ContinueShoppingUrl = _webHelper.GetStoreLocation(false); req.EditCartUrl = _webHelper.GetStoreLocation(false) + "cart"; GCheckoutResponse resp = req.Send(); return resp; }
/// <summary> /// Post cart to google /// </summary> /// <param name="Req">Pre-generated request</param> /// <param name="Cart">Shopping cart</param> /// <returns>Response</returns> public GCheckoutResponse PostCartToGoogle(CheckoutShoppingCartRequest Req, NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCart Cart) { foreach (NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCartItem sci in Cart) { ProductVariant productVariant = sci.ProductVariant; if (productVariant != null) { string pvAttributeDescription = ProductAttributeHelper.FormatAttributes(productVariant, sci.AttributesXML, NopContext.Current.User, ", ", false); string fullName = productVariant.FullProductName; string description = pvAttributeDescription; decimal unitPrice = TaxManager.GetPrice(sci.ProductVariant, PriceHelper.GetUnitPrice(sci, NopContext.Current.User, true)); Req.AddItem(fullName, description, sci.ShoppingCartItemID.ToString(), unitPrice, sci.Quantity); } } decimal shoppingCartSubTotalDiscount; decimal shoppingCartSubTotal = ShoppingCartManager.GetShoppingCartSubTotal(Cart, NopContext.Current.User, out shoppingCartSubTotalDiscount); if (shoppingCartSubTotalDiscount > decimal.Zero) Req.AddItem("Discount", string.Empty, string.Empty, (decimal)(-1.0) * shoppingCartSubTotalDiscount, 1); bool shoppingCartRequiresShipping = ShippingManager.ShoppingCartRequiresShipping(Cart); if (shoppingCartRequiresShipping) { string shippingError = string.Empty; //TODO AddMerchantCalculatedShippingMethod //TODO AddCarrierCalculatedShippingOption ShippingOptionCollection shippingOptions = ShippingManager.GetShippingOptions(Cart, NopContext.Current.User, null, ref shippingError); foreach (ShippingOption shippingOption in shippingOptions) Req.AddFlatRateShippingMethod(shippingOption.Name, TaxManager.GetShippingPrice(shippingOption.Rate, NopContext.Current.User)); } //add only US, GB states //CountryCollection countries = CountryManager.GetAllCountries(); //foreach (Country country in countries) //{ // foreach (StateProvince state in country.StateProvinces) // { // TaxByStateProvinceCollection taxByStateProvinceCollection = TaxByStateProvinceManager.GetAllByStateProvinceID(state.StateProvinceID); // foreach (TaxByStateProvince taxByStateProvince in taxByStateProvinceCollection) // { // if (!String.IsNullOrEmpty(state.Abbreviation)) // { // Req.AddStateTaxRule(state.Abbreviation, (double)taxByStateProvince.Percentage, false); // } // } // } //} XmlDocument customerInfoDoc = new XmlDocument(); XmlElement customerInfo = customerInfoDoc.CreateElement("CustomerInfo"); customerInfo.SetAttribute("CustomerID", NopContext.Current.User.CustomerID.ToString()); customerInfo.SetAttribute("CustomerLanguageID", NopContext.Current.WorkingLanguage.LanguageID.ToString()); customerInfo.SetAttribute("CustomerCurrencyID", NopContext.Current.WorkingCurrency.CurrencyID.ToString()); Req.AddMerchantPrivateDataNode(customerInfo); Req.ContinueShoppingUrl = CommonHelper.GetStoreLocation(false); Req.EditCartUrl = CommonHelper.GetStoreLocation(false) + "ShoppingCart.aspx"; GCheckoutResponse Resp = Req.Send(); return Resp; }
/// <summary> /// Post cart to google /// </summary> /// <param name="req">Pre-generated request</param> /// <param name="cart">Shopping cart</param> /// <returns>Response</returns> public GCheckoutResponse PostCartToGoogle(CheckoutShoppingCartRequest req, NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCart cart) { //items foreach (NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCartItem sci in cart) { ProductVariant productVariant = sci.ProductVariant; if (productVariant != null) { decimal taxRate = decimal.Zero; string description = ProductAttributeHelper.FormatAttributes(productVariant, sci.AttributesXml, NopContext.Current.User, ", ", false); string fullName = productVariant.LocalizedFullProductName; decimal unitPrice = TaxManager.GetPrice(sci.ProductVariant, PriceHelper.GetUnitPrice(sci, NopContext.Current.User, true), out taxRate); req.AddItem(fullName, description, sci.ShoppingCartItemId.ToString(), unitPrice, sci.Quantity); } } //decimal subtotalBase = decimal.Zero; //string subTotalError = ShoppingCartManager.GetShoppingCartSubTotal(cart, // NopContext.Current.User, out subtotalBase); bool shoppingCartRequiresShipping = ShippingManager.ShoppingCartRequiresShipping(cart); if (shoppingCartRequiresShipping) { string shippingError = string.Empty; //AddMerchantCalculatedShippingMethod //AddCarrierCalculatedShippingOption List<ShippingOption> shippingOptions = ShippingManager.GetShippingOptions(cart, NopContext.Current.User, null, ref shippingError); foreach (ShippingOption shippingOption in shippingOptions) req.AddFlatRateShippingMethod(shippingOption.Name, TaxManager.GetShippingPrice(shippingOption.Rate, NopContext.Current.User)); } //add only US, GB states //CountryCollection countries = CountryManager.GetAllCountries(); //foreach (Country country in countries) //{ // foreach (StateProvince state in country.StateProvinces) // { // TaxByStateProvinceCollection taxByStateProvinceCollection = TaxByStateProvinceManager.GetAllByStateProvinceID(state.StateProvinceID); // foreach (TaxByStateProvince taxByStateProvince in taxByStateProvinceCollection) // { // if (!String.IsNullOrEmpty(state.Abbreviation)) // { // Req.AddStateTaxRule(state.Abbreviation, (double)taxByStateProvince.Percentage, false); // } // } // } //} //if (subTotalDiscountBase > decimal.Zero) //{ // req.AddItem("Discount", string.Empty, string.Empty, (decimal)(-1.0) * subTotalDiscountBase, 1); //} //foreach (AppliedGiftCard agc in appliedGiftCards) //{ // req.AddItem(string.Format("Gift Card - {0}", agc.GiftCard.GiftCardCouponCode), string.Empty, string.Empty, (decimal)(-1.0) * agc.AmountCanBeUsed, 1); //} XmlDocument customerInfoDoc = new XmlDocument(); XmlElement customerInfo = customerInfoDoc.CreateElement("CustomerInfo"); customerInfo.SetAttribute("CustomerID", NopContext.Current.User.CustomerId.ToString()); customerInfo.SetAttribute("CustomerLanguageID", NopContext.Current.WorkingLanguage.LanguageId.ToString()); customerInfo.SetAttribute("CustomerCurrencyID", NopContext.Current.WorkingCurrency.CurrencyId.ToString()); req.AddMerchantPrivateDataNode(customerInfo); req.ContinueShoppingUrl = CommonHelper.GetStoreLocation(false); req.EditCartUrl = CommonHelper.GetStoreLocation(false) + "ShoppingCart.aspx"; GCheckoutResponse resp = req.Send(); return resp; }