public void TestShippingResult() { ShippingResult sr = new ShippingResult(); sr.Shippable = true; sr.ShippingRate = 12.975m; Assert.IsTrue(sr.Shippable); Assert.AreEqual(12.98, sr.ShippingRate); }
/// <summary> /// Example showing how shipping is calculated for a callback /// </summary> /// <param name="ShipMethodName">Identifies a shipping method for which /// costs need to be calculated.</param> /// <param name="ThisOrder">The Order to perform the calculation</param> /// <param name="Address">contains a possible shipping address for an order. /// This address should be used to calculate taxes and shipping costs /// for the order.</param> /// <returns></returns> public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address) { ShippingResult RetVal = new ShippingResult(); if (ShipMethodName == "UPS Ground" && Address.Region != "HI" && Address.Region != "AL") { RetVal.Shippable = true; RetVal.ShippingRate = 20; } else if (ShipMethodName == "SuperShip") { RetVal.Shippable = true; RetVal.ShippingRate = 0; } else { //next we will look at the merchant-private-item-data //if the supplier-id is "ABC Candy Company" then you will get free shipping. //do not assume the nodes will be in the same order, we will walk the node //list looking for a node with the name of "supplier-id" //you can just as easily import all the nodes into an XmlDocument and perform //XPath statements. //You can also create a string dictionary by performing a foreach statement //on the nodes and using the node name as the key and the innerText as the //value. //We are just showing one of many ways to work with an array of XmlNodes. //As you can see from the sample code, you may also have children on any //of the MerchantPrivateDataNodes. string supplierID = "ABC Candy Company".ToUpper(); foreach (OrderLine Line in ThisOrder) { foreach (System.Xml.XmlNode node in Line.MerchantPrivateDataNodes) { if (node.Name == "supplier-id") { if (supplierID == node.InnerText.ToUpper()) { RetVal.Shippable = true; RetVal.ShippingRate = 0; break; } } } } } return(RetVal); }
public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address) { ShippingResult RetVal = new ShippingResult(); if (ShipMethodName == "UPS Ground" && Address.Region != "HI" && Address.Region != "AL") { RetVal.Shippable = true; RetVal.ShippingRate = 20; } if (ShipMethodName == "SuperShip") { RetVal.Shippable = true; RetVal.ShippingRate = 0; } return RetVal; }
public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address) { ShippingResult RetVal = new ShippingResult(); if (ShipMethodName == "UPS Ground" && Address.Region != "HI" && Address.Region != "AL") { RetVal.Shippable = true; RetVal.ShippingRate = 20; } if (ShipMethodName == "SuperShip") { RetVal.Shippable = true; RetVal.ShippingRate = 0; } return(RetVal); }
/// <summary> /// Process the Xml Message /// </summary> /// <param name="CallbackXML">The Callback message to process</param> /// <returns>The <see cref="AutoGen.MerchantCalculationResults"/> /// that is returned to Google Checkout</returns> public byte[] Process(string CallbackXML) { // Deserialize the callback request. AutoGen.MerchantCalculationCallback Callback = (AutoGen.MerchantCalculationCallback) EncodeHelper.Deserialize (CallbackXML, typeof(AutoGen.MerchantCalculationCallback)); // Create the callback response. AutoGen.MerchantCalculationResults RetVal = new AutoGen.MerchantCalculationResults(); // Create the order. Order ThisOrder = new Order(Callback); // Are there shipping methods? string[] ShippingMethods = new string[1] { "" }; if (Callback.calculate.shipping != null && Callback.calculate.shipping.Length > 0) { ShippingMethods = new string[Callback.calculate.shipping.Length]; for (int s = 0; s < ShippingMethods.Length; s++) { ShippingMethods[s] = Callback.calculate.shipping[s].name; } } RetVal.results = new AutoGen.Result [Callback.calculate.addresses.Length * ShippingMethods.Length]; int ResultIndex = 0; for (int a = 0; a < Callback.calculate.addresses.Length; a++) { for (int s = 0; s < ShippingMethods.Length; s++) { AutoGen.Result ThisResult = new AutoGen.Result(); ThisResult.addressid = Callback.calculate.addresses[a].id; AnonymousAddress ThisAddress = new AnonymousAddress(Callback.calculate.addresses[a]); // Check shipping, if requested. if (ShippingMethods[s] != string.Empty) { ThisResult.shippingname = ShippingMethods[s]; ShippingResult SResult = _Rules.GetShippingResult (ShippingMethods[s], ThisOrder, ThisAddress); ThisResult.shippableSpecified = true; ThisResult.shippable = SResult.Shippable; ThisResult.shippingrate = new AutoGen.ResultShippingrate(); ThisResult.shippingrate.currency = _currency; ThisResult.shippingrate.Value = SResult.ShippingRate; } // Check tax, if requested. if (Callback.calculate.tax) { ThisResult.totaltax = new AutoGen.ResultTotaltax(); ThisResult.totaltax.currency = _currency; ThisResult.totaltax.Value = _Rules.GetTaxResult (ThisOrder, ThisAddress, (ThisResult.shippingrate != null ? ThisResult.shippingrate.Value : 0)); } // Check merchant codes. if (Callback.calculate.merchantcodestrings != null) { ThisResult.merchantcoderesults = new AutoGen.ResultMerchantcoderesults(); ThisResult.merchantcoderesults.Items = new object[Callback.calculate.merchantcodestrings.Length]; ArrayList UsedMerchantCodes = new ArrayList(); for (int c = 0; c < Callback.calculate.merchantcodestrings.Length; c++) { MerchantCodeResult MCR; string CurrentMerchantCode = Callback.calculate.merchantcodestrings[c].code; if (UsedMerchantCodes.Contains(CurrentMerchantCode.ToUpper())) { AutoGen.CouponResult CouponResult = new AutoGen.CouponResult(); CouponResult.calculatedamount = new AutoGen.CouponResultCalculatedamount(); CouponResult.calculatedamount.currency = _currency; CouponResult.calculatedamount.Value = 0; CouponResult.code = CurrentMerchantCode; CouponResult.message = "Code already used."; CouponResult.valid = false; ThisResult.merchantcoderesults.Items[c] = CouponResult; } else { MCR = _Rules.GetMerchantCodeResult (ThisOrder, ThisAddress, CurrentMerchantCode, (ThisResult.shippingrate != null ? ThisResult.shippingrate.Value : 0)); if (MCR.Type == MerchantCodeType.GiftCertificate) { AutoGen.GiftCertificateResult GCResult = new AutoGen.GiftCertificateResult(); GCResult.calculatedamount = new AutoGen.GiftCertificateResultCalculatedamount(); GCResult.calculatedamount.currency = _currency; GCResult.calculatedamount.Value = MCR.Amount; GCResult.code = CurrentMerchantCode; GCResult.message = MCR.Message; GCResult.valid = MCR.Valid; ThisResult.merchantcoderesults.Items[c] = GCResult; UsedMerchantCodes.Add(CurrentMerchantCode.ToUpper()); } else { AutoGen.CouponResult CouponResult = new AutoGen.CouponResult(); CouponResult.calculatedamount = new AutoGen.CouponResultCalculatedamount(); CouponResult.calculatedamount.currency = _currency; CouponResult.calculatedamount.Value = MCR.Amount; CouponResult.code = CurrentMerchantCode; CouponResult.message = MCR.Message; CouponResult.valid = MCR.Valid; ThisResult.merchantcoderesults.Items[c] = CouponResult; UsedMerchantCodes.Add(CurrentMerchantCode.ToUpper()); } } } } RetVal.results[ResultIndex] = ThisResult; ResultIndex++; } } return(EncodeHelper.Serialize(RetVal)); }
/// <summary> /// Example showing how shipping is calculated for a callback /// </summary> /// <param name="ShipMethodName">Identifies a shipping method for which /// costs need to be calculated.</param> /// <param name="ThisOrder">The Order to perform the calculation</param> /// <param name="Address">contains a possible shipping address for an order. /// This address should be used to calculate taxes and shipping costs /// for the order.</param> /// <returns></returns> public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address) { ShippingResult RetVal = new ShippingResult(); if (ShipMethodName == "UPS Ground" && Address.Region != "HI" && Address.Region != "AL") { RetVal.Shippable = true; RetVal.ShippingRate = 20; } else if (ShipMethodName == "SuperShip") { RetVal.Shippable = true; RetVal.ShippingRate = 0; } else { //next we will look at the merchant-private-item-data //if the supplier-id is "ABC Candy Company" then you will get free shipping. //do not assume the nodes will be in the same order, we will walk the node //list looking for a node with the name of "supplier-id" //you can just as easily import all the nodes into an XmlDocument and perform //XPath statements. //You can also create a string dictionary by performing a foreach statement //on the nodes and using the node name as the key and the innerText as the //value. //We are just showing one of many ways to work with an array of XmlNodes. //As you can see from the sample code, you may also have children on any //of the MerchantPrivateDataNodes. string supplierID = "ABC Candy Company".ToUpper(); foreach (OrderLine Line in ThisOrder) { foreach (System.Xml.XmlNode node in Line.MerchantPrivateDataNodes) { if (node.Name == "supplier-id") { if (supplierID == node.InnerText.ToUpper()) { RetVal.Shippable = true; RetVal.ShippingRate = 0; break; } } } } } return RetVal; }