public void TestMerchantCalcTaxes() { CheckoutShoppingCartRequest request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120); request.MerchantCalculatedTax = true; Assert.AreEqual(true, request.MerchantCalculatedTax); byte[] xml = null; try { xml = request.GetXml(); Assert.Fail("You should not be able to obtain the xml:MerchantCalculatedTax"); } catch (Exception ex) { if (ex.Message.IndexOf("MerchantCalculatedTax=true, you must add at least one tax rule.") == -1) { Assert.Fail(ex.Message); } } //now we want to set a tax table and let it blow up because the callback url was not set. request.AddStateTaxRule("OH", .06, true); try { xml = request.GetXml(); Assert.Fail("You should not be able to obtain the xml:AddStateTaxRule"); } catch (Exception ex) { if (ex.Message.IndexOf("MerchantCalculatedTax=true, you must set MerchantCalculationsUrl.") == -1) { Assert.Fail(ex.Message); } } request.MerchantCalculatedTax = false; request.AcceptMerchantCoupons = true; try { xml = request.GetXml(); Assert.Fail("You should not be able to obtain the xml:AcceptMerchantCoupons"); } catch (Exception ex) { if (ex.Message.IndexOf("AcceptMerchantCoupons=true, you must set MerchantCalculationsUrl.") == -1) { Assert.Fail(ex.Message); } } request.AcceptMerchantCoupons = false; request.AcceptMerchantGiftCertificates = true; try { xml = request.GetXml(); Assert.Fail("You should not be able to obtain the xml:AcceptMerchantGiftCertificates"); } catch (Exception ex) { if (ex.Message.IndexOf("AcceptMerchantGiftCertificates=true, you must set") == -1) { Assert.Fail(ex.Message); } } request.AcceptMerchantGiftCertificates = false; //set to false to test carrier option request.MerchantCalculationsUrl = "http://localhost/test.aspx"; //Ship from test request.AddCarrierCalculatedShippingOption(ShippingType.Fedex_Second_Day, 4.99m); try { xml = request.GetXml(); Assert.Fail("You should not be able to obtain the xml:carrier-calculated-shipping item exists"); } catch (Exception ex) { if (ex.Message.IndexOf("a ShipFrom address must also be set") == -1) { Assert.Fail(ex.Message); } } }
public void DefaultTaxTable_AddStateTaxRule_VerifyTaxRateSetsIsSpecified() { //create a pickup shipping method var request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "GBP", 120); request.AddStateTaxRule("OH", .05, true); CheckoutShoppingCart roundTrip = EncodeHelper.Deserialize(EncodeHelper.Utf8BytesToString(request.GetXml()), typeof(CheckoutShoppingCart)) as CheckoutShoppingCart; var actualTaxTable = roundTrip.checkoutflowsupport.Item.taxtables.defaulttaxtable.taxrules[0]; Assert.AreEqual(.05, actualTaxTable.rate); Assert.IsTrue(actualTaxTable.rateSpecified); Assert.IsTrue(actualTaxTable.shippingtaxed); Assert.AreEqual(typeof(USStateArea), actualTaxTable.taxarea.Item.GetType()); }
public void TestExamples() { CheckoutShoppingCartRequest request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120); //Make sure we can add an item to the cart. request.AddItem("Item 1", "Cool Candy 1", 2.00M, 1); request.AddStateTaxRule("CT", .06, true); byte[] cart = request.GetXml(); //Console.WriteLine(EncodeHelper.Utf8BytesToString(cart)); //test to see if the item can desialize Assert.IsNotNull(GCheckout.Util.EncodeHelper.Deserialize(cart)); //example 2 request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120); //Make sure we can add an item to the cart. request.AddItem("Item 1", "Cool Candy 1", 2.00M, 1); request.AddStateTaxRule("CT", .06, true); request.AddStateTaxRule("MD", .05, false); cart = request.GetXml(); //Console.WriteLine(EncodeHelper.Utf8BytesToString(cart)); //test to see if the item can desialize Assert.IsNotNull(GCheckout.Util.EncodeHelper.Deserialize(cart)); //example 2a request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120); //Make sure we can add an item to the cart. request.AddItem("Item 1", "Cool Candy 1", 2.00M, 1); cart = request.GetXml(); //Console.WriteLine(EncodeHelper.Utf8BytesToString(cart)); //test to see if the item can desialize Assert.IsNotNull(GCheckout.Util.EncodeHelper.Deserialize(cart)); //example 3 request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120); //Make sure we can add an item to the cart. request.AddItem("Item 1", "Cool Candy 1", 2.00M, 1); request.AddZipTaxRule("100*", 0.08375, false); request.AddStateTaxRule("NY", 0.0400, true); //this should be an invalid format try { request.AddZipTaxRule("255333", .05, true); Assert.Fail("255333 should not be a correct zip code format"); } catch { } cart = request.GetXml(); //Console.WriteLine(EncodeHelper.Utf8BytesToString(cart)); //test to see if the item can desialize Assert.IsNotNull(GCheckout.Util.EncodeHelper.Deserialize(cart)); request.AddMerchantCalculatedShippingMethod("Test 1", 12.11m); request.AddMerchantCalculatedShippingMethod("Test 2", 4.95m, new ShippingRestrictions()); request.AddMerchantCalculatedShippingMethod("Test 3", 5.95m, new ShippingRestrictions()); request.AddMerchantCalculatedShippingMethod("MerchantCalc", 12.95m, new ShippingRestrictions(), new ShippingRestrictions()); //create a pickup shipping method request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120); request.AddPickupShippingMethod("Name", 4.95m); request.AddCountryTaxRule(GCheckout.AutoGen.USAreas.ALL, .05, true); request.AddWorldAreaTaxRule(.02, true); //Tax Canada at 5% request.AddPostalAreaTaxRule("CA", .05, true); //Tax all cities that start with L4L at 7% request.AddPostalAreaTaxRule("CA", "L4L*", .07, true); XmlDocument doc = new XmlDocument(); doc.LoadXml("<data />"); request.AddMerchantPrivateDataNode(doc.DocumentElement); //we must pass in a valid node try { request.AddMerchantPrivateDataNode(null); Assert.Fail("Null can't be sent to AddMerchantPrivateDataNode."); } catch { } }