//private GoogleCheckOutSettingInfo GetSettingGooglePayment() //{ // GoogleCheckOutSettingInfo setting = new GoogleCheckOutSettingInfo(); // GoogleCheckOutWCFService ser = new GoogleCheckOutWCFService(); //} public static void ProcessNotification(string serialNumber) { GoogleCheckOutWCFService pw = new GoogleCheckOutWCFService(); List <GoogleCheckOutSettingKeyInfo> sf; sf = pw.GoogleCheckOutSettingKey(); MerchantID = sf[0].GoogleMerchantID; MerchantKey = sf[0].GoogleMerchantKey; Environment = sf[0].GoogleEnvironmentType; GCheckout.OrderProcessing.NotificationHistorySerialNumber sn = new NotificationHistorySerialNumber(serialNumber); GCheckout.OrderProcessing.NotificationHistoryRequest oneNotificationHistoryRequest = new NotificationHistoryRequest(MerchantID, MerchantKey, Environment, sn); //newNotificationHistorySerialNumber(serialNumber) //Response NotificationHistoryResponse oneNotificationHistoryResponse = (NotificationHistoryResponse)oneNotificationHistoryRequest.Send(); //Get type of notification object notification = GCheckout.Util.EncodeHelper.Deserialize(oneNotificationHistoryResponse.ResponseXml); //Check for the notification and call functions according to that if (notification.GetType().Equals(typeof(GCheckout.AutoGen.NewOrderNotification))) { GCheckout.AutoGen.NewOrderNotification oneNewOrderNotification = (GCheckout.AutoGen.NewOrderNotification)notification; if (oneNewOrderNotification.serialnumber.Equals(serialNumber)) { HandleNewOrderNotification(oneNewOrderNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.OrderStateChangeNotification))) { GCheckout.AutoGen.OrderStateChangeNotification oneOrderStateChangeNotification = (GCheckout.AutoGen.OrderStateChangeNotification)notification; if (oneOrderStateChangeNotification.serialnumber.Equals(serialNumber)) { HandleOrderStateChangeNotification(oneOrderStateChangeNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.RiskInformationNotification))) { GCheckout.AutoGen.RiskInformationNotification oneRiskInformationNotification = (GCheckout.AutoGen.RiskInformationNotification)notification; if (oneRiskInformationNotification.serialnumber.Equals(serialNumber)) { HandleRiskInformationNotification(oneRiskInformationNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.AuthorizationAmountNotification))) { GCheckout.AutoGen.AuthorizationAmountNotification oneAuthorizationAmountNotification = (GCheckout.AutoGen.AuthorizationAmountNotification)notification; if (oneAuthorizationAmountNotification.serialnumber.Equals(serialNumber)) { HandleAuthorizationAmountNotification(oneAuthorizationAmountNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.ChargeAmountNotification))) { GCheckout.AutoGen.ChargeAmountNotification oneChargeAmountNotification = (GCheckout.AutoGen.ChargeAmountNotification)notification; if (oneChargeAmountNotification.serialnumber.Equals(serialNumber)) { HandleChargeAmountNotification(oneChargeAmountNotification); } } else { string exceptionText = "Unhandled Type [" + notification.GetType().ToString() + "]!; serialNumber=[" + serialNumber + "];"; throw new ArgumentOutOfRangeException(exceptionText); } }
public void LoadSetting() { GoogleCheckOutWCFService pw = new GoogleCheckOutWCFService(); List <GoogleCheckOutSettingInfo> sf; OrderDetailsCollection orderdata2 = new OrderDetailsCollection(); orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"]; string itemidsWithVar = ""; foreach (var item in orderdata2.LstOrderItemsInfo) { itemidsWithVar += item.ItemID + "&" + item.Quantity + "&" + orderdata2.ObjOrderDetails.OrderID + "&" + item.Variants + ","; } string country = orderdata2.ObjShippingAddressInfo.Country.ToString(); string state = orderdata2.ObjShippingAddressInfo.State.ToString(); string zip = orderdata2.ObjShippingAddressInfo.Zip.ToString(); int addressID = Convert.ToInt32(orderdata2.ObjShippingAddressInfo.AddressID); try { sf = pw.GetAllGoogleCheckOutSetting(int.Parse(Session["GateWay"].ToString()), storeID, portalID); double amountTotal = double.Parse(Session["GrandTotalAll"].ToString()) * rate; decimal grandTotal = decimal.Parse(amountTotal.ToString(CultureInfo.InvariantCulture)); decimal totalTaxableAmount = 0; decimal subtotalAmount = 0; decimal taxSubTotal = 0; decimal shipping = Convert.ToDecimal(Convert.ToDouble(Session["ShippingCostAll"].ToString()) * rate); decimal shippingCost = decimal.Parse(shipping.ToString(CultureInfo.InvariantCulture)); decimal discountAmount = 0; decimal couponDiscountAmount = 0; decimal rewardDiscountAmount = 0; if (sf[0].GoogleEnvironmentType == "Sandbox") { CheckoutShoppingCartRequest gCartRequest = new CheckoutShoppingCartRequest(sf[0].GoogleMerchantID, sf[0].GoogleMerchantKey, GCheckout.EnvironmentType.Sandbox, sf[0].GoogleCurrencyType, 30, false); HttpContext.Current.Session["EnvironmentType"] = "Sandbox"; List <CartInfoforGoogleCheckOut> cd; cd = pw.GetCartDetailsForPG(storeID, portalID, customerID, userName, GetCurrentCultureName, sessionCode, country, state, zip, addressID); int nCount = 1; foreach (CartInfoforGoogleCheckOut oItem in cd) { string itemName = oItem.ItemName.ToString(); string description = oItem.ShortDescription.ToString(); int qty = Convert.ToInt32(oItem.Quantity.ToString()); decimal TaxRateValue = Convert.ToDecimal(Convert.ToDouble(oItem.TaxRateValue.ToString()) * rate) / qty; decimal amount = Convert.ToDecimal(Convert.ToDouble(oItem.Price.ToString()) * rate); decimal subTotal = amount;// +TaxRateValue; gCartRequest.AddItem(itemName, description, subTotal, qty); nCount++; } nCount--; //Send Discount Amount if (orderdata2.ObjOrderDetails.DiscountAmount != 0) { string itemName = "Cart Discount Amount"; string description = "Discount Applied on Cart Items"; int qty = 1; discountAmount = 0; decimal discount = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.DiscountAmount) * rate); discountAmount = decimal.Parse(discount.ToString(CultureInfo.InvariantCulture)); gCartRequest.AddItem(itemName, description, -discountAmount, qty); } //Send Coupon Amount if (orderdata2.ObjOrderDetails.CouponDiscountAmount != 0) { string itemName = "Coupon Discount Amount"; string description = "Coupon Discount Applied on Cart Items"; int qty = 1; couponDiscountAmount = 0; decimal couponDiscount = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.CouponDiscountAmount) * rate); couponDiscountAmount = decimal.Parse(couponDiscount.ToString(CultureInfo.InvariantCulture)); gCartRequest.AddItem(itemName, description, -couponDiscountAmount, qty); } //Send Reward Discount Amount if (orderdata2.ObjOrderDetails.RewardDiscountAmount != 0) { string itemName = "Reward Points Discount Amount"; string description = "Reward Points Discount Applied on Cart Items"; int qty = 1; rewardDiscountAmount = 0; decimal rewardDiscount = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.RewardDiscountAmount) * rate); rewardDiscountAmount = decimal.Parse(rewardDiscount.ToString(CultureInfo.InvariantCulture)); gCartRequest.AddItem(itemName, description, -rewardDiscountAmount, qty); } //tax if (orderdata2.ObjOrderDetails.TaxTotal != 0) { decimal tax = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.TaxTotal) * rate); taxSubTotal = decimal.Parse(tax.ToString(CultureInfo.InvariantCulture)); } subtotalAmount = grandTotal - shippingCost - taxSubTotal + discountAmount + couponDiscountAmount; totalTaxableAmount = subtotalAmount - discountAmount - couponDiscountAmount; double taxp = Convert.ToDouble((taxSubTotal * 100) / totalTaxableAmount); double taxPer = taxp / 100; gCartRequest.AddCountryTaxRule(USAreas.ALL, taxPer, false); //Shipping Cost string shippingMethod; if (HttpContext.Current.Session["ShippingMethodName"] != null) { shippingMethod = HttpContext.Current.Session["ShippingMethodName"].ToString(); } else { shippingMethod = "Default Shipping"; } //shippingMethod = "Default Shipping"; //decimal shippingcost = Convert.ToDecimal(Convert.ToDouble(Session["ShippingCostAll"].ToString()) * rate); gCartRequest.AddFlatRateShippingMethod(shippingMethod, shippingCost); //Create extra data to pass XmlDocument tempDoc = new System.Xml.XmlDocument(); tempDoc.LoadXml("<root />"); XmlNode orderIdNode = tempDoc.CreateElement("OrderID"); orderIdNode.InnerText = Session["OrderID"].ToString(); gCartRequest.AddMerchantPrivateDataNode(orderIdNode); XmlNode userIdNode = tempDoc.CreateElement("userName"); userIdNode.InnerText = userName; gCartRequest.AddMerchantPrivateDataNode(userIdNode); XmlNode amountNode = tempDoc.CreateElement("amount"); amountNode.InnerText = (double.Parse(Session["GrandTotalAll"].ToString()) * rate).ToString(); gCartRequest.AddMerchantPrivateDataNode(amountNode); XmlNode currencyNode = tempDoc.CreateElement("selectedCurrency"); currencyNode.InnerText = SelectedCurrency; gCartRequest.AddMerchantPrivateDataNode(currencyNode); XmlNode portalIDNode = tempDoc.CreateElement("portalID"); portalIDNode.InnerText = portalID.ToString(); gCartRequest.AddMerchantPrivateDataNode(portalIDNode); XmlNode customerIDNode = tempDoc.CreateElement("customerID"); customerIDNode.InnerText = customerID.ToString(); gCartRequest.AddMerchantPrivateDataNode(customerIDNode); XmlNode itemIdsNode = tempDoc.CreateElement("itemIds"); itemIdsNode.InnerText = itemidsWithVar; gCartRequest.AddMerchantPrivateDataNode(itemIdsNode); XmlNode storeIDNode = tempDoc.CreateElement("storeID"); storeIDNode.InnerText = storeID.ToString(); gCartRequest.AddMerchantPrivateDataNode(storeIDNode); XmlNode couponCodeNode = tempDoc.CreateElement("couponCode"); couponCodeNode.InnerText = couponCode; gCartRequest.AddMerchantPrivateDataNode(couponCodeNode); XmlNode sessionCodeNode = tempDoc.CreateElement("sessionCode"); sessionCodeNode.InnerText = sessionCode; gCartRequest.AddMerchantPrivateDataNode(sessionCodeNode); XmlNode pgIDNode = tempDoc.CreateElement("pgID"); pgIDNode.InnerText = Session["GateWay"].ToString(); gCartRequest.AddMerchantPrivateDataNode(pgIDNode); XmlNode MerchantIDNode = tempDoc.CreateElement("MerchantID"); MerchantIDNode.InnerText = sf[0].GoogleMerchantID; gCartRequest.AddMerchantPrivateDataNode(MerchantIDNode); XmlNode MerchantKeyNode = tempDoc.CreateElement("MerchantKey"); MerchantKeyNode.InnerText = sf[0].GoogleMerchantKey; gCartRequest.AddMerchantPrivateDataNode(MerchantKeyNode); //Get response GCheckoutResponse response = gCartRequest.Send(); // Post the request for Google checkout if (response.IsGood) { Response.Redirect(response.RedirectUrl, false); } } if (sf[0].GoogleEnvironmentType == "Production") { CheckoutShoppingCartRequest gCartRequest = new CheckoutShoppingCartRequest(sf[0].GoogleMerchantID, sf[0].GoogleMerchantKey, GCheckout.EnvironmentType.Production, sf[0].GoogleCurrencyType, 30, false); HttpContext.Current.Session["EnvironmentType"] = "Production"; List <CartInfoforGoogleCheckOut> cd; cd = pw.GetCartDetailsForPG(storeID, portalID, customerID, userName, GetCurrentCultureName, sessionCode, country, state, zip, addressID); int nCount = 1; foreach (CartInfoforGoogleCheckOut oItem in cd) { string itemName = oItem.ItemName.ToString(); string description = oItem.ShortDescription.ToString(); int qty = Convert.ToInt32(oItem.Quantity.ToString()); decimal TaxRateValue = Convert.ToDecimal(Convert.ToDouble(oItem.TaxRateValue.ToString()) * rate) / qty; decimal amount = Convert.ToDecimal(Convert.ToDouble(oItem.Price.ToString()) * rate); decimal subTotal = amount + TaxRateValue; gCartRequest.AddItem(itemName, description, subTotal, qty); nCount++; } nCount--; //Send Discount Amount if (orderdata2.ObjOrderDetails.DiscountAmount != 0) { string itemName = "Cart Discount Amount"; string description = "Discount Applied on Cart Items"; int qty = 1; discountAmount = 0; decimal discount = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.DiscountAmount) * rate); discountAmount = decimal.Parse(discount.ToString(CultureInfo.InvariantCulture)); gCartRequest.AddItem(itemName, description, -discountAmount, qty); } //Send Coupon Amount if (orderdata2.ObjOrderDetails.CouponDiscountAmount != 0) { string itemName = "Coupon Discount Amount"; string description = "Coupon Discount Applied on Cart Items"; int qty = 1; couponDiscountAmount = 0; decimal couponDiscount = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.CouponDiscountAmount) * rate); couponDiscountAmount = decimal.Parse(couponDiscount.ToString(CultureInfo.InvariantCulture)); gCartRequest.AddItem(itemName, description, -couponDiscountAmount, qty); } //Send Reward Discount Amount if (orderdata2.ObjOrderDetails.RewardDiscountAmount != 0) { string itemName = "Reward Points Discount Amount"; string description = "Reward Points Discount Applied on Cart Items"; int qty = 1; rewardDiscountAmount = 0; decimal rewardDiscount = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.RewardDiscountAmount) * rate); rewardDiscountAmount = decimal.Parse(rewardDiscount.ToString(CultureInfo.InvariantCulture)); gCartRequest.AddItem(itemName, description, -rewardDiscountAmount, qty); } //tax if (orderdata2.ObjOrderDetails.TaxTotal != 0) { decimal tax = Convert.ToDecimal(Convert.ToDouble(orderdata2.ObjOrderDetails.TaxTotal) * rate); taxSubTotal = decimal.Parse(tax.ToString(CultureInfo.InvariantCulture)); } subtotalAmount = grandTotal - shippingCost - taxSubTotal + discountAmount + couponDiscountAmount; totalTaxableAmount = subtotalAmount - discountAmount - couponDiscountAmount; double taxp = Convert.ToDouble((taxSubTotal * 100) / totalTaxableAmount); double taxPer = taxp / 100; gCartRequest.AddCountryTaxRule(USAreas.ALL, taxPer, false); //Shipping Cost string shippingMethod; if (HttpContext.Current.Session["ShippingMethodName"] != null) { shippingMethod = HttpContext.Current.Session["ShippingMethodName"].ToString(); } else { shippingMethod = "Default Shipping"; } //shippingMethod = "Default Shipping"; //decimal shippingcost = Convert.ToDecimal(Convert.ToDouble(Session["ShippingCostAll"].ToString()) * rate); gCartRequest.AddFlatRateShippingMethod(shippingMethod, shippingCost); //Create extra data to pass XmlDocument tempDoc = new System.Xml.XmlDocument(); tempDoc.LoadXml("<root />"); XmlNode orderIdNode = tempDoc.CreateElement("OrderID"); orderIdNode.InnerText = Session["OrderID"].ToString(); gCartRequest.AddMerchantPrivateDataNode(orderIdNode); XmlNode userIdNode = tempDoc.CreateElement("userName"); userIdNode.InnerText = userName; gCartRequest.AddMerchantPrivateDataNode(userIdNode); XmlNode amountNode = tempDoc.CreateElement("amount"); amountNode.InnerText = (double.Parse(Session["GrandTotalAll"].ToString()) * rate).ToString(); gCartRequest.AddMerchantPrivateDataNode(amountNode); XmlNode currencyNode = tempDoc.CreateElement("selectedCurrency"); currencyNode.InnerText = SelectedCurrency; gCartRequest.AddMerchantPrivateDataNode(currencyNode); XmlNode portalIDNode = tempDoc.CreateElement("portalID"); portalIDNode.InnerText = portalID.ToString(); gCartRequest.AddMerchantPrivateDataNode(portalIDNode); XmlNode customerIDNode = tempDoc.CreateElement("customerID"); customerIDNode.InnerText = customerID.ToString(); gCartRequest.AddMerchantPrivateDataNode(customerIDNode); XmlNode itemIdsNode = tempDoc.CreateElement("itemIds"); itemIdsNode.InnerText = itemidsWithVar; gCartRequest.AddMerchantPrivateDataNode(itemIdsNode); XmlNode storeIDNode = tempDoc.CreateElement("storeID"); storeIDNode.InnerText = storeID.ToString(); gCartRequest.AddMerchantPrivateDataNode(storeIDNode); XmlNode couponCodeNode = tempDoc.CreateElement("couponCode"); couponCodeNode.InnerText = couponCode; gCartRequest.AddMerchantPrivateDataNode(couponCodeNode); XmlNode sessionCodeNode = tempDoc.CreateElement("sessionCode"); sessionCodeNode.InnerText = sessionCode; gCartRequest.AddMerchantPrivateDataNode(sessionCodeNode); XmlNode pgIDNode = tempDoc.CreateElement("pgID"); pgIDNode.InnerText = Session["GateWay"].ToString(); gCartRequest.AddMerchantPrivateDataNode(pgIDNode); XmlNode MerchantIDNode = tempDoc.CreateElement("MerchantID"); MerchantIDNode.InnerText = sf[0].GoogleMerchantID; gCartRequest.AddMerchantPrivateDataNode(MerchantIDNode); XmlNode MerchantKeyNode = tempDoc.CreateElement("MerchantKey"); MerchantKeyNode.InnerText = sf[0].GoogleMerchantKey; gCartRequest.AddMerchantPrivateDataNode(MerchantKeyNode); //Get response GCheckoutResponse response = gCartRequest.Send(); // Post the request for Google checkout if (response.IsGood) { Response.Redirect(response.RedirectUrl, false); } } } catch (Exception ex) { lblnotity.Text = "Something goes wrong, hit refresh or go back to checkout"; clickhere.Visible = false; ProcessException(ex); } }
//private GoogleCheckOutSettingInfo GetSettingGooglePayment() //{ // GoogleCheckOutSettingInfo setting = new GoogleCheckOutSettingInfo(); // GoogleCheckOutWCFService ser = new GoogleCheckOutWCFService(); //} public static void ProcessNotification(string serialNumber) { GoogleCheckOutWCFService pw = new GoogleCheckOutWCFService(); List<GoogleCheckOutSettingKeyInfo> sf; sf = pw.GoogleCheckOutSettingKey(); MerchantID = sf[0].GoogleMerchantID; MerchantKey = sf[0].GoogleMerchantKey; Environment = sf[0].GoogleEnvironmentType; GCheckout.OrderProcessing.NotificationHistorySerialNumber sn = new NotificationHistorySerialNumber(serialNumber); GCheckout.OrderProcessing.NotificationHistoryRequest oneNotificationHistoryRequest = new NotificationHistoryRequest(MerchantID, MerchantKey, Environment, sn); //newNotificationHistorySerialNumber(serialNumber) //Response NotificationHistoryResponse oneNotificationHistoryResponse = (NotificationHistoryResponse)oneNotificationHistoryRequest.Send(); //Get type of notification object notification = GCheckout.Util.EncodeHelper.Deserialize(oneNotificationHistoryResponse.ResponseXml); //Check for the notification and call functions according to that if (notification.GetType().Equals(typeof(GCheckout.AutoGen.NewOrderNotification))) { GCheckout.AutoGen.NewOrderNotification oneNewOrderNotification = (GCheckout.AutoGen.NewOrderNotification)notification; if (oneNewOrderNotification.serialnumber.Equals(serialNumber)) { HandleNewOrderNotification(oneNewOrderNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.OrderStateChangeNotification))) { GCheckout.AutoGen.OrderStateChangeNotification oneOrderStateChangeNotification = (GCheckout.AutoGen.OrderStateChangeNotification)notification; if (oneOrderStateChangeNotification.serialnumber.Equals(serialNumber)) { HandleOrderStateChangeNotification(oneOrderStateChangeNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.RiskInformationNotification))) { GCheckout.AutoGen.RiskInformationNotification oneRiskInformationNotification = (GCheckout.AutoGen.RiskInformationNotification)notification; if (oneRiskInformationNotification.serialnumber.Equals(serialNumber)) { HandleRiskInformationNotification(oneRiskInformationNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.AuthorizationAmountNotification))) { GCheckout.AutoGen.AuthorizationAmountNotification oneAuthorizationAmountNotification = (GCheckout.AutoGen.AuthorizationAmountNotification)notification; if (oneAuthorizationAmountNotification.serialnumber.Equals(serialNumber)) { HandleAuthorizationAmountNotification(oneAuthorizationAmountNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.ChargeAmountNotification))) { GCheckout.AutoGen.ChargeAmountNotification oneChargeAmountNotification = (GCheckout.AutoGen.ChargeAmountNotification)notification; if (oneChargeAmountNotification.serialnumber.Equals(serialNumber)) { HandleChargeAmountNotification(oneChargeAmountNotification); } } else { string exceptionText = "Unhandled Type [" + notification.GetType().ToString() + "]!; serialNumber=[" + serialNumber + "];"; throw new ArgumentOutOfRangeException(exceptionText); } }