// Methods
        public static void InitialCharge()
        {
            //http://code.google.com/apis/checkout/developer/Google_Checkout_Beta_Subscriptions.html
              //using an initial charge with a recurring charge using a different item.

              CheckoutShoppingCartRequest cartRequest
            = new CheckoutShoppingCartRequest("123456", "merchantkey", EnvironmentType.Sandbox, "USD", 120);

              //if you are using a web page and it has the Google Checkout button, you would use this syntax.
              //= GCheckoutButton1.CreateRequest()

              ShoppingCartItem initialItem = new ShoppingCartItem();
              ShoppingCartItem recurrentItem = new ShoppingCartItem();

              initialItem.Price = decimal.Zero;
              initialItem.Quantity = 1;
              initialItem.Name = "Item that shows in cart";
              initialItem.Description = "This is the item that shows in the cart";

              recurrentItem.Price = 2M;
              recurrentItem.Quantity = 1;
              recurrentItem.Name = "Item that is charged every month";
              recurrentItem.Description = "Description for item that is charged every month";

              Subscription subscription = new Subscription();
              subscription.Period = GCheckout.AutoGen.DatePeriod.MONTHLY;
              subscription.Type = SubscriptionType.merchant;

              SubscriptionPayment payment = new SubscriptionPayment();
              payment.MaximumCharge = 120M;
              payment.Times = 12;

              subscription.AddSubscriptionPayment(payment);

              //You must set the item that will be charged for every month.
              subscription.RecurrentItem = recurrentItem;

              //you must set the subscription for the item
              initialItem.Subscription = subscription;

              cartRequest.AddItem(initialItem);

              Debug.WriteLine(EncodeHelper.Utf8BytesToString(cartRequest.GetXml()));

              //Send the request to Google
              //GCheckout.Util.GCheckoutResponse resp = cartRequest.Send();

              //Uncommment this line or perform additional actions
              //if (resp.IsGood) {
              //Response.Redirect(resp.RedirectUrl, True)
              //}
              //else{
              //Response.Write("Resp.ResponseXml = " & Resp.ResponseXml & "<br>");
              //Response.Write("Resp.RedirectUrl = " & Resp.RedirectUrl & "<br>");
              //Response.Write("Resp.IsGood = " & Resp.IsGood & "<br>");
              //Response.Write("Resp.ErrorMessage = " & Resp.ErrorMessage & "<br>");
              //}
        }
        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;
        }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// do not have &lt;merchant-private-item-data&gt; XML blocks associated 
 /// with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="subscription">The subscription item</param>
 public ShoppingCartItem AddItem(string Name, string Description,
     int Quantity, Subscription subscription)
 {
     ShoppingCartItem retVal = new ShoppingCartItem(Name, Description,
     string.Empty, 0, Quantity);
       retVal.Subscription = subscription;
       _items.Add(retVal);
       return retVal;
 }
 /// <summary>
 /// This method adds an item to an order.
 /// </summary>
 /// <param name="item">The shopping cart item to add.</param>
 public ShoppingCartItem AddItem(ShoppingCartItem item)
 {
     if (item == null)
     throw new ArgumentNullException("item must not be null");
       _items.Add(item);
       return item;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// have &lt;merchant-private-item-data&gt; XML blocks associated with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely 
 /// identifies the product in your system.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="MerchantPrivateItemDataNodes">An array of XML nodes that
 /// should be 
 /// associated with the item in the Checkout API request. This value 
 /// corresponds to the value of the value of the 
 /// &lt;merchant-private-item-data&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="digitalItem">
 /// The &lt;digital-content&gt; tag contains information relating to
 /// digital delivery of an item.
 /// </param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID,
     decimal Price, int Quantity, DigitalItem digitalItem,
     params XmlNode[] MerchantPrivateItemDataNodes)
 {
     ShoppingCartItem item = new ShoppingCartItem(Name, Description,
     MerchantItemID, Price, Quantity, AlternateTaxTable.Empty,
     MerchantPrivateItemDataNodes);
       item.DigitalContent = digitalItem;
       _items.Add(item);
       return item;
 }
        public static void RecurringChargeRightAway()
        {
            CheckoutShoppingCartRequest cartRequest
            = new CheckoutShoppingCartRequest("123456", "merchantkey", EnvironmentType.Sandbox, "USD", 120);
              //if you are using a web page and it has the Google Checkout button, you would use this syntax.
              //= GCheckoutButton1.CreateRequest()

              Subscription gSubscription = new Subscription();
              SubscriptionPayment maxCharge = new SubscriptionPayment();

              DigitalItem urlDigitalItem = new DigitalItem(new Uri("http://www.url.com/login.aspx"),
            "Congratulations, your account has been created!");

              DigitalItem urlDigitalItemSubscription = new DigitalItem(new Uri("http://www.url.com/login.aspx"),
            "You may now continue to login to your account.");

              ShoppingCartItem gRecurrentItem = new ShoppingCartItem();
              maxCharge.MaximumCharge = 29.99M;

              gRecurrentItem.Name = "Entry Level Plan";
              gRecurrentItem.Description = "Allows for basic stuff. Monthly Subscription:";
              gRecurrentItem.Quantity = 1;
              gRecurrentItem.Price = 29.99M;
              gRecurrentItem.DigitalContent = urlDigitalItemSubscription;
              gRecurrentItem.DigitalContent.Disposition = DisplayDisposition.Pessimistic;

              urlDigitalItem.Disposition = DisplayDisposition.Pessimistic;

              gSubscription.Type = SubscriptionType.google;
              gSubscription.Period = GCheckout.AutoGen.DatePeriod.MONTHLY;
              gSubscription.AddSubscriptionPayment(maxCharge);
              gSubscription.RecurrentItem = gRecurrentItem;

              cartRequest.AddItem("Entry Level Plan", "Allows for basic stuff.", 1, gSubscription);
              cartRequest.AddItem("Entry Level Plan", "First Month:", 29.99M, 1, urlDigitalItem);

              cartRequest.MerchantPrivateData = "UserName:Joe87";

              Debug.WriteLine(EncodeHelper.Utf8BytesToString(cartRequest.GetXml()));

              //Send the request to Google
              //GCheckout.Util.GCheckoutResponse resp = cartRequest.Send();

              //Uncommment this line or perform additional actions
              //if (resp.IsGood) {
              //Response.Redirect(resp.RedirectUrl, True)
              //}
              //else{
              //Response.Write("Resp.ResponseXml = " & Resp.ResponseXml & "<br>");
              //Response.Write("Resp.RedirectUrl = " & Resp.RedirectUrl & "<br>");
              //Response.Write("Resp.IsGood = " & Resp.IsGood & "<br>");
              //Response.Write("Resp.ErrorMessage = " & Resp.ErrorMessage & "<br>");
              //}
        }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// do not have &lt;merchant-private-item-data&gt; XML blocks associated 
 /// with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely
 /// identifies the product in your system.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="taxTable">The <see cref="AlternateTaxTable"/> 
 /// To assign to the item </param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID, decimal Price, int Quantity,
     AlternateTaxTable taxTable)
 {
     _alternateTaxTables.VerifyTaxRule(taxTable);
       ShoppingCartItem retVal
     = new ShoppingCartItem(Name, Description, MerchantItemID, Price,
     Quantity, taxTable);
       _items.Add(retVal);
       return retVal;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// do not have &lt;merchant-private-item-data&gt; XML blocks associated 
 /// with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely
 /// identifies the product in your system.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="digitalItem">
 /// The &lt;digital-content&gt; tag contains information relating to
 /// digital delivery of an item.
 /// </param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID,
     decimal Price, int Quantity, DigitalItem digitalItem)
 {
     ShoppingCartItem item = new ShoppingCartItem(Name, Description,
     MerchantItemID, Price, Quantity);
       item.DigitalContent = digitalItem;
       _items.Add(item);
       return item;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// have &lt;merchant-private-item-data&gt; XML blocks associated with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="MerchantPrivateItemData">An XML block that should be 
 /// associated with the item in the Checkout API request. This value 
 /// corresponds to the value of the value of the 
 /// &lt;merchant-private-item-data&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="subscription">The subscription information.</param>
 public ShoppingCartItem AddItem(string Name, string Description,
     int Quantity, string MerchantPrivateItemData, Subscription subscription)
 {
     ShoppingCartItem retVal
     = new ShoppingCartItem(Name, Description, string.Empty, 0,
     Quantity, AlternateTaxTable.Empty, MakeXmlElement(MerchantPrivateItemData));
       retVal.Subscription = subscription;
       _items.Add(retVal);
       return retVal;
 }
        public ActionResult Google()
        {
            Customer customer = ViewBag.customer;
            customer.GetFromStorage();
            if (!customer.LoggedIn()) {
                return RedirectToAction("Index", "Authenticate", new { referrer = "https://" + Request.Url.Host + "/Cart/Checkout" });
            }

            if (customer.Cart.payment_id > 0) {
                UDF.ExpireCart(customer.ID);
                return RedirectToAction("Index", "Cart");
            }

            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Settings settings = ViewBag.settings;
            CheckoutShoppingCartRequest req = gButton.CreateRequest();
            if (Request.Url.Host.Contains("127.0.0") || Request.Url.Host.Contains("localhost") || settings.Get("GoogleCheckoutEnv") == "override") {
                req.MerchantID = settings.Get("GoogleDevMerchantId");
                req.MerchantKey = settings.Get("GoogleDevMerchantKey");
                req.Environment = GCheckout.EnvironmentType.Sandbox;
            } else {
                req.MerchantID = settings.Get("GoogleMerchantId");
                req.MerchantKey = settings.Get("GoogleMerchantKey");
                req.Environment = GCheckout.EnvironmentType.Production;
            }
            if (settings.Get("GoogleAnalyticsCode") != "") {
                req.AnalyticsData = Request.Form["analyticsdata"];
            }
            req.ContinueShoppingUrl = Request.Url.Scheme + "://" + Request.Url.Host;
            //req.EditCartUrl = Request.Url.Host + "/Cart";

            foreach (CartItem item in customer.Cart.CartItems) {
                ShoppingCartItem sitem = new ShoppingCartItem {
                    Name = "CURT Part #" + item.partID,
                    Description = item.shortDesc,
                    Price = item.price,
                    Quantity = item.quantity,
                    Weight = Convert.ToDouble(item.weight)
                };
                req.AddItem(sitem);
            }
            System.Xml.XmlDocument tempDoc = new System.Xml.XmlDocument();
            System.Xml.XmlNode tempNode = tempDoc.CreateElement("OrderNumber");
            tempNode.InnerText = customer.Cart.ID.ToString();
            req.AddMerchantPrivateDataNode(tempNode);

            req.AddShippingPackage("0", customer.Cart.Shipping.city, customer.Cart.Shipping.State1.state1, customer.Cart.Shipping.postal_code);
            req.AddFlatRateShippingMethod(customer.Cart.shipping_type, customer.Cart.shipping_price);

            Country country = db.Countries.Where(x => x.abbr.Equals("US")).FirstOrDefault();
            if(country != null) {
                foreach(State state in country.States) {
                    req.AddStateTaxRule(state.abbr, Convert.ToDouble(state.taxRate / 100), true);
                }
            }

            GCheckoutResponse resp = req.Send();
            if (resp.IsGood) {
                customer.Cart.AddPayment("Google Checkout", "", "Pending");

                Cart new_cart = new Cart().Save();
                new_cart.UpdateCart(customer.ID);
                DateTime cookexp = Request.Cookies["hdcart"].Expires;
                HttpCookie cook = new HttpCookie("hdcart", new_cart.ID.ToString());
                cook.Expires = cookexp;
                Response.Cookies.Add(cook);

                customer.Cart = new_cart;
                customer.Cart.BindAddresses();

                return Redirect(resp.RedirectUrl);
            } else {
                return RedirectToAction("Index", new { message = resp.ErrorMessage });
            }
        }
        /// <summary>
        /// Convert the item to an auto gen item.
        /// </summary>
        /// <param name="item">The item to convert</param>
        /// <param name="currency">The currency</param>
        /// <returns></returns>
        public static AutoGen.Item CreateAutoGenItem(IShoppingCartItem item,
                                                     string currency)
        {
            GCheckout.AutoGen.Item currentItem = new AutoGen.Item();

            currentItem.itemname        = EncodeHelper.EscapeXmlChars(item.Name);
            currentItem.itemdescription =
                EncodeHelper.EscapeXmlChars(item.Description);
            currentItem.quantity = item.Quantity;

            //if there is a subscription, you may not have a unit price

            if (item.Subscription != null && item.Price > 0)
            {
                throw new ApplicationException(
                          "The unit price must be 0 if you are using a subscription item.");
            }

            currentItem.unitprice          = new AutoGen.Money();
            currentItem.unitprice.currency = currency;
            currentItem.unitprice.Value    = item.Price;

            //TODO determine if we should try to catch if a UK customer tries to
            //use this value.
            if (item.Weight > 0)
            {
                currentItem.itemweight       = new AutoGen.ItemWeight();
                currentItem.itemweight.unit  = "LB"; //this is the only option.
                currentItem.itemweight.value = item.Weight;
            }

            if (item.MerchantItemID != null &&
                item.MerchantItemID.Length > 0)
            {
                currentItem.merchantitemid = item.MerchantItemID;
            }

            if (item.MerchantPrivateItemDataNodes != null &&
                item.MerchantPrivateItemDataNodes.Length > 0)
            {
                AutoGen.anyMultiple any = new AutoGen.anyMultiple();

                any.Any = item.MerchantPrivateItemDataNodes;
                currentItem.merchantprivateitemdata = any;
            }

            if (item.TaxTable != null &&
                item.TaxTable != AlternateTaxTable.Empty)
            {
                currentItem.taxtableselector = item.TaxTable.Name;
            }

            //if we have a digital item then we need to append the information
            if (item.DigitalContent != null)
            {
                currentItem.digitalcontent = new GCheckout.AutoGen.DigitalContent();
                //we have one of two types, email or key/url
                if (item.DigitalContent.EmailDelivery)
                {
                    currentItem.digitalcontent.emaildelivery          = true;
                    currentItem.digitalcontent.emaildeliverySpecified = true;
                }
                else
                {
                    if (item.DigitalContent.Description.Length > 0)
                    {
                        currentItem.digitalcontent.description =
                            item.DigitalContent.Description;
                    }
                    if (item.DigitalContent.Key.Length > 0)
                    {
                        currentItem.digitalcontent.key =
                            item.DigitalContent.Key;
                    }
                    if (item.DigitalContent.Url.Length > 0)
                    {
                        currentItem.digitalcontent.url =
                            item.DigitalContent.Url;
                    }
                    currentItem.digitalcontent.displaydisposition
                        = item.DigitalContent.GetSerializedDisposition();
                }
            }

            //see if we have subscription information
            if (item.Subscription != null)
            {
                if (item.Subscription.RecurrentItem == null)
                {
                    throw new ApplicationException(
                              "You must set a RecurrentItem for a subscription.");
                }
                Subscription sub = item.Subscription;
                //we have to assume the item was validated
                currentItem.subscription = new GCheckout.AutoGen.Subscription();
                GCheckout.AutoGen.Subscription autoSub = currentItem.subscription;
                if (sub.NoChargeAfter.HasValue)
                {
                    autoSub.nochargeafter          = sub.NoChargeAfter.Value;
                    autoSub.nochargeafterSpecified = true;
                }
                autoSub.payments
                    = new GCheckout.AutoGen.SubscriptionPayment[sub.Payments.Count];
                for (int sp = 0; sp < sub.Payments.Count; sp++)
                {
                    SubscriptionPayment payment = sub.Payments[sp];
                    autoSub.payments[sp] = new GCheckout.AutoGen.SubscriptionPayment();
                    autoSub.payments[sp].maximumcharge
                        = EncodeHelper.Money(currency, payment.MaximumCharge);
                    if (payment.Times > 0)
                    {
                        autoSub.payments[sp].times          = payment.Times;
                        autoSub.payments[sp].timesSpecified = true;
                    }
                    autoSub.period = sub.Period;
                    if (sub.RecurrentItem != null &&
                        sub.RecurrentItem.Subscription != null)
                    {
                        throw new ApplicationException(
                                  "A RecurrentItem may not contain a subscription.");
                    }
                    //call this method to create the recurrent item.
                    autoSub.recurrentitem
                        = ShoppingCartItem.CreateAutoGenItem(sub.RecurrentItem, currency);
                    if (sub.StartDate.HasValue)
                    {
                        autoSub.startdate          = sub.StartDate.Value;
                        autoSub.startdateSpecified = true;
                    }
                    autoSub.type = sub.Type.ToString();
                }
            }
            return(currentItem);
        }
 /// <summary>
 /// Convert the item to an autogen item
 /// </summary>
 /// <param name="currency">The currency</param>
 /// <returns></returns>
 public AutoGen.Item CreateAutoGenItem(string currency)
 {
     return(ShoppingCartItem.CreateAutoGenItem(this, currency));
 }
        public void TestSubscriptions_All_Data()
        {
            CheckoutShoppingCartRequest request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120);
              //Make sure we can add an item to the cart.
              Subscription sub = new Subscription();
              sub.AddSubscriptionPayment(new SubscriptionPayment(2, 12));
              sub.NoChargeAfter = new DateTime(2010, 1, 1);
              sub.Period = GCheckout.AutoGen.DatePeriod.DAILY;
              sub.RecurrentItem = new ShoppingCartItem("Sub Item", "Sub Item Description", "Item 1", 0, 3);
              sub.StartDate = new DateTime(2009, 7, 1);
              sub.Type = SubscriptionType.merchant;
              ShoppingCartItem item = request.AddItem("Item 1", "Cool Candy 1", 1, sub);
              //Console.WriteLine(EncodeHelper.Utf8BytesToString(request.GetXml()));

              //now deserialize it
              AutoGen.CheckoutShoppingCart cart = EncodeHelper.Deserialize(request.GetXml()) as AutoGen.CheckoutShoppingCart;
              //Console.WriteLine(EncodeHelper.Utf8BytesToString(EncodeHelper.Serialize(cart)));

              foreach (AutoGen.Item ai in cart.shoppingcart.items) {
            ShoppingCartItem ci = new ShoppingCartItem(ai);
            Assert.AreEqual(ci.Subscription.NoChargeAfter, sub.NoChargeAfter);
            SubscriptionPayment sp = new SubscriptionPayment(ai.subscription.payments[0]);
            SubscriptionPayment dp = sub.Payments[0];

            Assert.AreEqual(sp.MaximumCharge, dp.MaximumCharge);
            Assert.AreEqual(sp.Times, dp.Times);

            Assert.AreEqual(ci.Subscription.Period, sub.Period);
            Assert.AreEqual(ci.Subscription.StartDate, sub.StartDate);
            Assert.AreEqual(ci.Subscription.Type, sub.Type);

              }

              sub.NoChargeAfter = null;
              sub.Period = GCheckout.AutoGen.DatePeriod.QUARTERLY;
              sub.StartDate = null;
              sub.Type = SubscriptionType.google;

              //reset
              cart = EncodeHelper.Deserialize(request.GetXml()) as AutoGen.CheckoutShoppingCart;
              //Console.WriteLine(EncodeHelper.Utf8BytesToString(EncodeHelper.Serialize(cart)));

              foreach (AutoGen.Item ai in cart.shoppingcart.items) {
            ShoppingCartItem ci = new ShoppingCartItem(ai);
            //Console.WriteLine(ci.Subscription.NoChargeAfter);
            Assert.IsFalse(ci.Subscription.NoChargeAfter.HasValue, "NoChargeAfter should be null");
            SubscriptionPayment sp = new SubscriptionPayment(ai.subscription.payments[0]);
            SubscriptionPayment dp = sub.Payments[0];

            Assert.AreEqual(sp.MaximumCharge, dp.MaximumCharge);
            Assert.AreEqual(sp.Times, dp.Times);

            Assert.AreEqual(ci.Subscription.Period, DatePeriod.QUARTERLY);
            //Console.WriteLine(ci.Subscription.StartDate);
            //bug in .net
            //Assert.IsFalse(ci.Subscription.StartDate.HasValue, "StartDate should be null");
            Assert.AreEqual(ci.Subscription.Type, SubscriptionType.google);

              }
        }
        public void TestAddItem()
        {
            //due to the complexity of the add items. we are going to create a known set of data points and add them to the collection.
              ShoppingCartItem si = new ShoppingCartItem();
              si.Description = "Description";
              si.DigitalContent = new DigitalItem("Digital Item Key", "Digital Item Description");
              si.MerchantItemID = "Merchant Item ID";
              si.MerchantPrivateItemData = "Private Data";

              XmlDocument mpdDoc = new XmlDocument();
              mpdDoc.LoadXml("<data />");
              mpdDoc.DocumentElement.AppendChild(mpdDoc.CreateElement("node1"));
              mpdDoc.DocumentElement.AppendChild(mpdDoc.CreateElement("node2"));
              XmlNode[] mpdNodes = new XmlNode[] { mpdDoc.DocumentElement.ChildNodes[0], mpdDoc.DocumentElement.ChildNodes[1] };

              si.MerchantPrivateItemDataNodes = mpdNodes;
              si.Name = "Name";
              si.Price = 0.99m;
              si.Quantity = 1;

              AlternateTaxTable taxTable = new AlternateTaxTable("Example");
              taxTable.AddStateTaxRule("OH", .06);

              si.TaxTable = taxTable;
              si.Weight = 10.5;

              si.TaxTable.AddCountryTaxRule(GCheckout.AutoGen.USAreas.ALL, 5.0);

              CheckoutShoppingCartRequest request = new CheckoutShoppingCartRequest(MERCHANT_ID, MERCHANT_KEY, EnvironmentType.Sandbox, "USD", 120);

              request.ContinueShoppingUrl = "http://localhost/";
              request.AnalyticsData = "Test data";
              request.PlatformID = 1234567890;
              request.EditCartUrl = "http://localhost/editcart.aspx";
              request.RequestBuyerPhoneNumber = true;
              request.MerchantCalculationsUrl = "http://localhost/calculate.aspx";
              request.AcceptMerchantCoupons = true;
              request.AcceptMerchantGiftCertificates = true;
              request.SetRoundingPolicy(RoundingMode.FLOOR, RoundingRule.TOTAL);
              request.AddShippingPackage("main", "Cleveland", "OH", "44114");

              request.MerchantPrivateData = "Test Cool Stuff";
              request.AddMerchantPrivateDataNode(mpdNodes[0]);

              XmlNode[] mpdn = request.MerchantPrivateDataNodes;

              Assert.AreSame(mpdn[0], mpdNodes[0]);

              try {
            request.AddItem(null);
            Assert.Fail("Null can't be passed to the AddItem methods");
              }
              catch {
              }

              try {
            MethodInfo mi = typeof(CheckoutShoppingCartRequest).GetMethod("AddItem", new Type[] { typeof(IShoppingCartItem) });
            mi.Invoke(request, new object[] { null });
            Assert.Fail("Null can't be passed to the AddItem methods");
              }
              catch {
              }

              request.AddItem(si);
              request.AddItem(si.Clone() as IShoppingCartItem);

              MethodInfo[] methods = typeof(CheckoutShoppingCartRequest).GetMethods();

              foreach (MethodInfo mi in methods) {
            bool cancel = false;
            //we are only working with AddItems
            if (mi.Name == "AddItem") {
              Type sct = typeof(ShoppingCartItem);
              ShoppingCartItem si2 = si.Clone() as ShoppingCartItem;
              ParameterInfo[] parameters = mi.GetParameters();
              object[] setter = new object[parameters.Length];
              for (int i = 0; i < parameters.Length; i++) {
            ParameterInfo pi = parameters[i];
            if (pi.ParameterType == typeof(ShoppingCartItem) || pi.ParameterType == typeof(IShoppingCartItem)) {
              cancel = true;
              continue;
            }
            //get the property from the object
            PropertyInfo source;
            if (pi.Name != "digitalItem") {
              source = sct.GetProperty(pi.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            }
            else {
              source = sct.GetProperty("DigitalContent");
            }
            setter[i] = source.GetValue(si2, null);

            //we want to split and take the first item
            if (!pi.ParameterType.IsArray && source.PropertyType.IsArray) {
              object[] vals = setter[i] as object[];
              setter[i] = vals[0] as object;
            }
              }
              if (!cancel) {
            //now call the method
            ShoppingCartItem called = mi.Invoke(request, setter) as ShoppingCartItem;

            //this is to fix a params array issue.
            if (parameters[parameters.Length - 1].Name == "MerchantPrivateItemDataNodes") {
              called.MerchantPrivateItemDataNodes = si2.MerchantPrivateItemDataNodes;
            }
              }
            }
              }

              byte[] toXml = request.GetXml();

              //Make sure we can add an item to the cart.
              ShoppingCartItem item = request.AddItem("Item 1", "Cool Candy 1", "Merchant Item ID", 2.00M, 1);
              item.Weight = 2.2;
              item.MerchantPrivateItemData = null; //perform a null check

              //verify we can't set the price to fractions.

              item.Price = 1.975m;
              Assert.AreEqual(1.98m, item.Price);

              item.Price = 1.994m;
              Assert.AreEqual(1.99m, item.Price);

              Assert.AreEqual(2.2, item.Weight);
              Assert.AreEqual("Merchant Item ID", item.MerchantItemID);

              //this is a very specific test to make sure that if only one node exists, return it. it may be for a reason.

              XmlDocument doc = new XmlDocument();
              doc.LoadXml("<data />");
              doc.DocumentElement.SetAttribute("test", "cool");

              string xml = doc.OuterXml;
              item.MerchantPrivateItemDataNodes = new XmlNode[] { doc.DocumentElement };
              string xmlReturn = item.MerchantPrivateItemData;
              Assert.AreEqual(xml, xmlReturn);

              //create a new node
              XmlNode secondNode = doc.DocumentElement.AppendChild(doc.CreateElement("test"));
              item.MerchantPrivateItemDataNodes = new XmlNode[] { doc.DocumentElement, secondNode };

              xmlReturn = item.MerchantPrivateItemData;
              Assert.AreEqual(null, xmlReturn);

              item.MerchantPrivateItemDataNodes = null;
              Assert.AreEqual(new XmlNode[] { }, item.MerchantPrivateItemDataNodes);

              //this should throw an exception
              try {
            item.Weight = -1;
            Assert.Fail("Weight should not be allowed to be negative.");
              }
              catch {
              }

              //create a new instance of the cart item
              ShoppingCartItem testItem = new ShoppingCartItem();
        }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// do not have &lt;merchant-private-item-data&gt; XML blocks associated 
 /// with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="taxTable">The <see cref="AlternateTaxTable"/> 
 /// To assign to the item </param>
 /// <param name="digitalItem">
 /// The &lt;digital-content&gt; tag contains information relating to
 /// digital delivery of an item.
 /// </param>
 public ShoppingCartItem AddItem(string Name, string Description,
     decimal Price, int Quantity, AlternateTaxTable taxTable,
     DigitalItem digitalItem)
 {
     _alternateTaxTables.VerifyTaxRule(taxTable);
       ShoppingCartItem item = new ShoppingCartItem(Name, Description,
     string.Empty, Price, Quantity, taxTable);
       item.DigitalContent = digitalItem;
       _items.Add(item);
       return item;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// do not have &lt;merchant-private-item-data&gt; XML blocks associated 
 /// with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely
 /// identifies the product in your system.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID,
     decimal Price, int Quantity)
 {
     ShoppingCartItem retVal
     = new ShoppingCartItem(Name, Description, MerchantItemID, Price,
     Quantity);
       _items.Add(retVal);
       return retVal;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// have &lt;merchant-private-item-data&gt; XML blocks associated with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="MerchantPrivateItemDataNodes">An XML node that should be 
 /// associated with the item in the Checkout API request. This value 
 /// corresponds to the value of the value of the 
 /// &lt;merchant-private-item-data&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="taxTable">The <see cref="AlternateTaxTable"/> 
 /// To assign to the item </param>
 public ShoppingCartItem AddItem(string Name, string Description,
     decimal Price, int Quantity, XmlNode MerchantPrivateItemDataNodes,
     AlternateTaxTable taxTable)
 {
     _alternateTaxTables.VerifyTaxRule(taxTable);
       ShoppingCartItem retVal
     = new ShoppingCartItem(Name, Description, string.Empty, Price,
     Quantity, taxTable, MerchantPrivateItemDataNodes);
       _items.Add(retVal);
       return retVal;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// do not have &lt;merchant-private-item-data&gt; XML blocks associated 
 /// with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely
 /// identifies the product in your system.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="digitalItem">
 /// The &lt;digital-content&gt; tag contains information relating to
 /// digital delivery of an item.
 /// </param>
 /// <param name="subscription">The subscription item</param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID, int Quantity, DigitalItem digitalItem,
     Subscription subscription)
 {
     ShoppingCartItem retVal = new ShoppingCartItem(Name, Description,
     MerchantItemID, 0, Quantity);
       retVal.DigitalContent = digitalItem;
       retVal.Subscription = subscription;
       _items.Add(retVal);
       return retVal;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// have &lt;merchant-private-item-data&gt; XML blocks associated with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely
 /// identifies the product in your system.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="MerchantPrivateItemDataNodes">An XML node that should be 
 /// associated with the item in the Checkout API request. This value 
 /// corresponds to the value of the value of the 
 /// &lt;merchant-private-item-data&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="subscription">The subscription item.</param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID, int Quantity, XmlNode MerchantPrivateItemDataNodes,
     Subscription subscription)
 {
     ShoppingCartItem retVal
     = new ShoppingCartItem(Name, Description, MerchantItemID, 0,
     Quantity, AlternateTaxTable.Empty, MerchantPrivateItemDataNodes);
       retVal.Subscription = subscription;
       _items.Add(retVal);
       return retVal;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// do not have &lt;merchant-private-item-data&gt; XML blocks associated 
 /// with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely
 /// identifies the product in your system.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="taxTable">The <see cref="AlternateTaxTable"/> 
 /// To assign to the item </param>
 /// <param name="subscription">The subscription item</param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID, int Quantity, AlternateTaxTable taxTable,
     Subscription subscription)
 {
     _alternateTaxTables.VerifyTaxRule(taxTable);
       ShoppingCartItem retVal
     = new ShoppingCartItem(Name, Description, MerchantItemID, 0,
     Quantity, taxTable);
       retVal.Subscription = subscription;
       _items.Add(retVal);
       return retVal;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// have &lt;merchant-private-item-data&gt; XML blocks associated with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely
 /// identifies the product in your system.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="MerchantPrivateItemDataNodes">An XML node that should be 
 /// associated with the item in the Checkout API request. This value 
 /// corresponds to the value of the value of the 
 /// &lt;merchant-private-item-data&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="taxTable">The <see cref="AlternateTaxTable"/> 
 /// To assign to the item </param>
 /// <param name="digitalItem">
 /// The &lt;digital-content&gt; tag contains information relating to
 /// digital delivery of an item.
 /// </param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID,
     decimal Price, int Quantity, XmlNode MerchantPrivateItemDataNodes,
     AlternateTaxTable taxTable, DigitalItem digitalItem)
 {
     _alternateTaxTables.VerifyTaxRule(taxTable);
       ShoppingCartItem item = new ShoppingCartItem(Name, Description,
     MerchantItemID, Price, Quantity, taxTable, MerchantPrivateItemDataNodes);
       item.DigitalContent = digitalItem;
       _items.Add(item);
       return item;
 }
 /// <summary>
 /// This method adds an item to an order. This method handles items that 
 /// have &lt;merchant-private-item-data&gt; XML blocks associated with them.
 /// </summary>
 /// <param name="Name">The name of the item. This value corresponds to the 
 /// value of the &lt;item-name&gt; tag in the Checkout API request.</param>
 /// <param name="Description">The description of the item. This value 
 /// corresponds to the value of the &lt;item-description&gt; tag in the 
 /// Checkout API request.</param>
 /// <param name="MerchantItemID">The Merchant Item Id that uniquely 
 /// identifies the product in your system.</param>
 /// <param name="Price">The price of the item. This value corresponds to 
 /// the value of the &lt;unit-price&gt; tag in the Checkout API 
 /// request.</param>
 /// <param name="Quantity">The number of this item that is included in the 
 /// order. This value corresponds to the value of the &lt;quantity&gt; tag 
 /// in the Checkout API request.</param>
 /// <param name="MerchantPrivateItemDataNodes">An array of XML nodes that
 /// should be 
 /// associated with the item in the Checkout API request. This value 
 /// corresponds to the value of the value of the 
 /// &lt;merchant-private-item-data&gt; tag in the Checkout API 
 /// request.</param>
 public ShoppingCartItem AddItem(string Name, string Description,
     string MerchantItemID,
     decimal Price, int Quantity, params XmlNode[] MerchantPrivateItemDataNodes)
 {
     ShoppingCartItem retVal
     = new ShoppingCartItem(Name, Description, MerchantItemID, Price,
     Quantity, AlternateTaxTable.Empty, MerchantPrivateItemDataNodes);
       _items.Add(retVal);
       return retVal;
 }
示例#23
0
        /// <summary>
        /// This method generates the XML for a Checkout API request. This method
        /// also calls the <b>CheckPreConditions</b> method, which verifies that
        /// if the API request indicates that the merchant will calculate tax and
        /// shipping costs, that the input data for those calculations is included
        /// in the request.
        /// </summary>
        /// <returns>This method returns the XML for a Checkout API request.
        /// </returns>
        public override byte[] GetXml()
        {
            // Verify that if the API request calls for merchant calculations, the
            // input data for those calculations is included in the request.
            //
            CheckPreConditions();

            AutoGen.CheckoutShoppingCart MyCart = new AutoGen.CheckoutShoppingCart();
            MyCart.shoppingcart = new AutoGen.ShoppingCart();

            // Add the Shopping cart expiration element.
            if (_CartExpiration != DateTime.MinValue)
            {
                MyCart.shoppingcart.cartexpiration = new AutoGen.CartExpiration();
                MyCart.shoppingcart.cartexpiration.gooduntildate = _CartExpiration;
            }

            // Add the items in the shopping cart to the API request.
            MyCart.shoppingcart.items = new AutoGen.Item[_Items.Count];
            for (int i = 0; i < _Items.Count; i++)
            {
                ShoppingCartItem MyItem = (ShoppingCartItem)_Items[i];
                MyCart.shoppingcart.items[i]                    = new AutoGen.Item();
                MyCart.shoppingcart.items[i].itemname           = MyItem.Name;
                MyCart.shoppingcart.items[i].itemdescription    = MyItem.Description;
                MyCart.shoppingcart.items[i].quantity           = MyItem.Quantity;
                MyCart.shoppingcart.items[i].unitprice          = new AutoGen.Money();
                MyCart.shoppingcart.items[i].unitprice.currency = _Currency;
                MyCart.shoppingcart.items[i].unitprice.Value    = MyItem.Price;
                if (MyItem.MerchantPrivateItemData != null)
                {
                    MyCart.shoppingcart.items[i].merchantprivateitemdata =
                        MakeXmlElement(MyItem.MerchantPrivateItemData);
                }
            }

            // Add the &lt;merchant-private-data&gt; element to the API request.
            if (_MerchantPrivateData != null)
            {
                MyCart.shoppingcart.merchantprivatedata =
                    MakeXmlElement(_MerchantPrivateData);
            }

            // Add the &lt;continue-shopping-url&gt; element to the API request.
            MyCart.checkoutflowsupport =
                new AutoGen.CheckoutShoppingCartCheckoutflowsupport();
            MyCart.checkoutflowsupport.Item =
                new AutoGen.MerchantCheckoutFlowSupport();
            if (_ContinueShoppingUrl != null)
            {
                MyCart.checkoutflowsupport.Item.continueshoppingurl =
                    _ContinueShoppingUrl;
            }

            // Add the &lt;edit-cart-url&gt; element to the API request.
            if (_EditCartUrl != null)
            {
                MyCart.checkoutflowsupport.Item.editcarturl = _EditCartUrl;
            }

            // Add the &lt;request-buyer-phone-number&gt; element to the API request.
            if (_RequestBuyerPhoneNumber)
            {
                MyCart.checkoutflowsupport.Item.requestbuyerphonenumber          = true;
                MyCart.checkoutflowsupport.Item.requestbuyerphonenumberSpecified =
                    true;
            }

            // Add the shipping methods to the API request.
            MyCart.checkoutflowsupport.Item.shippingmethods = _ShippingMethods;

            // Add the tax tables to the API request.
            if (_TaxTables != null)
            {
                MyCart.checkoutflowsupport.Item.taxtables = _TaxTables;
            }

            // Add the merchant calculations URL to the API request.
            if (MerchantCalculationsUrl != null)
            {
                MyCart.checkoutflowsupport.Item.merchantcalculations =
                    new AutoGen.MerchantCalculations();
                MyCart.checkoutflowsupport.Item.merchantcalculations.
                merchantcalculationsurl = MerchantCalculationsUrl;
            }

            // Indicate whether the merchant accepts coupons and gift certificates.
            if (_AcceptMerchantCoupons)
            {
                MyCart.checkoutflowsupport.Item.merchantcalculations.
                acceptmerchantcoupons = true;
                MyCart.checkoutflowsupport.Item.merchantcalculations.
                acceptmerchantcouponsSpecified = true;
            }
            if (_AcceptMerchantGiftCertificates)
            {
                MyCart.checkoutflowsupport.Item.merchantcalculations.
                acceptgiftcertificates = true;
                MyCart.checkoutflowsupport.Item.merchantcalculations.
                acceptgiftcertificatesSpecified = true;
            }

            // Call the EncodeHelper.Serialize method to generate the XML for
            // the Checkout API request.
            return(EncodeHelper.Serialize(MyCart));
        }