public CheckoutShoppingCartRequest CreateRequest(ShoppingCart shoppingCart) { var request = new CheckoutShoppingCartRequest(_configuration.MerchantId, _configuration.MerchantKey, _configuration.EnvironmentType, "GBP", 0); foreach (var item in shoppingCart.Items) request.AddItem(item.Name, item.Description, item.MerchantItemId, item.UnitPriceExTax, item.Quantity); foreach (var discount in shoppingCart.Discounts) request.AddItem(discount.Name, discount.Description, -Math.Abs(discount.AmountExTax), discount.Quantity ?? 1); // TODO: Support different tax rates request.AddWorldAreaTaxRule(.2d, true); return request; }
public void VerifyTaxRateSetsIsSpecified() { //create a pickup shipping method var request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "GBP", 120); request.AddPickupShippingMethod("Name", 4.95m); request.AddCountryTaxRule(GCheckout.AutoGen.USAreas.ALL, .05, true); request.AddWorldAreaTaxRule(.02, true); //Tax GB at 5% request.AddPostalAreaTaxRule("GB", .05, true); CheckoutShoppingCart roundTrip = EncodeHelper.Deserialize(EncodeHelper.Utf8BytesToString(request.GetXml()), typeof(CheckoutShoppingCart)) as CheckoutShoppingCart; Assert.IsTrue(roundTrip.checkoutflowsupport.Item.taxtables.defaulttaxtable.taxrules[0].rateSpecified); Assert.IsTrue(roundTrip.checkoutflowsupport.Item.taxtables.defaulttaxtable.taxrules[0].shippingtaxed); Assert.IsTrue(roundTrip.checkoutflowsupport.Item.taxtables.defaulttaxtable.taxrules[0].shippingtaxedSpecified); }
public void DefaultTaxTable_AddWorldAreaTaxRule_VerifyTaxRateSetsIsSpecified() { //create a pickup shipping method var request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "GBP", 120); request.AddWorldAreaTaxRule(.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(WorldArea), 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 { } }