コード例 #1
0
 /// <summary>
 /// Create a new subscription item passing in the item and the payment
 /// </summary>
 /// <param name="recurrentItem"></param>
 /// <param name="payment"></param>
 /// <param name="period">The period attribute specifies how frequently
 /// you will charge the customer for the subscription</param>
 /// <param name="type">
 /// The type attribute identifies the type of subscription that you are creating.
 /// The valid values for this attribute are merchant and google,
 /// and this specifies who handles the recurrences.
 /// </param>
 public Subscription(IShoppingCartItem recurrentItem, SubscriptionPayment payment,
                     AutoGen.DatePeriod period, SubscriptionType type)
 {
     this.RecurrentItem = recurrentItem;
     this.Payments.Add(payment);
     this.Period = period;
     this.Type   = type;
 }
        /// <summary>
        /// Clone the object
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            SubscriptionPayment retVal = new SubscriptionPayment();

            retVal.MaximumCharge = this.MaximumCharge;
            retVal.Times         = this.Times;
            return(retVal);
        }
        // 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>");
              //}
        }
コード例 #4
0
 /// <summary>
 /// Add a payment to the subscription
 /// </summary>
 /// <param name="payment"></param>
 public void AddSubscriptionPayment(SubscriptionPayment payment)
 {
     if (_payments.Count > 0)
     {
         throw new ApplicationException(
                   "Only one payment is supported for a subscription item.");
     }
     _payments.Add(payment);
 }
        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>");
              //}
        }
コード例 #6
0
 /// <summary>
 /// Create a new subscription item passing in the item and the payment
 /// </summary>
 /// <param name="recurrentItem"></param>
 /// <param name="payment"></param>
 /// <param name="period">The period attribute specifies how frequently 
 /// you will charge the customer for the subscription</param>
 /// <param name="type">
 /// The type attribute identifies the type of subscription that you are creating. 
 /// The valid values for this attribute are merchant and google, 
 /// and this specifies who handles the recurrences.
 /// </param>
 public Subscription(IShoppingCartItem recurrentItem, SubscriptionPayment payment,
     AutoGen.DatePeriod period, SubscriptionType type)
 {
     this.RecurrentItem = recurrentItem;
       this.Payments.Add(payment);
       this.Period = period;
       this.Type = type;
 }
コード例 #7
0
 /// <summary>
 /// Add a payment to the subscription
 /// </summary>
 /// <param name="payment"></param>
 public void AddSubscriptionPayment(SubscriptionPayment payment)
 {
     if (_payments.Count > 0)
     throw new ApplicationException(
       "Only one payment is supported for a subscription item.");
       _payments.Add(payment);
 }
 /// <summary>
 /// Clone the object
 /// </summary>
 /// <returns></returns>
 public object Clone()
 {
     SubscriptionPayment retVal = new SubscriptionPayment();
       retVal.MaximumCharge = this.MaximumCharge;
       retVal.Times = this.Times;
       return retVal;
 }
        /// <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);
        }