コード例 #1
0
        protected void ActivateSubscription()
        {
            try
            {
                PaypalExpressCheckout checkout = new PaypalExpressCheckout(token);
                String subscriptionId = checkout.SubscriptionId;

                Registration registration = Registrations.Load(subscriptionId);

                PaypalExpressCheckout.ProfileResultStatus status = checkout.CreateRecurringPayment(registration);
                CmsSubscription subscription = CreateSubscription(registration, status.ProfileId);

                PaypalProfileId.Text = subscription.PaypalProfileId;
                this.ActivateViews.SetActiveView(this.SuccessPaypalView);
            }
            catch (Exception e)
            {
                this.LblErrorReason.Text = e.Message;
                this.ActivateViews.SetActiveView(this.FailureView);
            }
        }
コード例 #2
0
ファイル: Manage.aspx.cs プロジェクト: beachead/gooey-cms-v2
        protected void Page_Load(object sender, EventArgs e)
        {
            this.LblStatus.Text = "";

            if (!CurrentSite.IsAvailable)
                Response.Redirect("~/Dashboard.aspx");

            if (LoggedInUser.IsDemoAccount)
            {
                BtnUpdateOptions.Visible = false;
                BtnEnableSubscription.Visible = false;
                BtnUpdateUserInfo.Visible = false;
                BtnUpgradePlan.Visible = false;
                BtnUpgradeAccount.Visible = false;
                BtnCancelPlan.Visible = false;
                LnkUpdateDomain.Visible = false;
                BtnCancelPlan2.Visible = false;
                BtnDowngradePlan.Visible = false;
            }

            String token = Request.QueryString["token"];
            if (!String.IsNullOrEmpty(token))
            {
                PaypalExpressCheckout checkout = new PaypalExpressCheckout(token);
                String subscriptionId = checkout.SubscriptionId;

                CmsSubscription subscription = SubscriptionManager.GetSubscription(subscriptionId);
                subscription.SubscriptionPlan = SubscriptionManager.GetSubscriptionPlan(Constants.SubscriptionPlans.Business);

                int freeTrialRemaining = (int)SubscriptionManager.CalculateFreeTrialRemaining(subscription);

                //Get the options cookie
                Boolean foundCookie = false;
                HttpCookie cookie = Request.Cookies["upgrade-options"];
                if (cookie != null)
                {
                    try
                    {
                        String[] arr = TextEncryption.Decode(cookie.Value).Split('|');
                        if (arr.Length == 2)
                        {
                            subscription.IsCampaignEnabled = (arr[0].Equals("true")) ? true : false;
                            subscription.IsSalesforceEnabled = (arr[1].Equals("true")) ? true : false;

                            foundCookie = true;
                        }
                    }
                    catch (Exception) { }
                }

                if (!foundCookie)
                {
                    Response.Redirect("Manage.aspx?upgrade=failure&type=missingcookie", true);
                }

                Gooeycms.Business.Paypal.PaypalExpressCheckout.ProfileResultStatus status = checkout.CreateRecurringPayment(subscription, freeTrialRemaining);
                subscription.PaypalProfileId = status.ProfileId;
                subscription.IsDisabled = false; //Always make sure to reenable the subscription
                subscription.MaxPhoneNumbers = -1; //Set back to the default value
                SubscriptionManager.Save(subscription);

                //Clear the site cache
                CurrentSite.Cache.Clear();

                BillingManager.Instance.AddHistory(subscription.Guid, subscription.PaypalProfileId, null, BillingManager.Upgrade,0,"Successfully upgrade subscription or modified subscription options and created paypal recurring payment profile: " + subscription.PaypalProfileId);
                Response.Redirect("Manage.aspx?upgrade=success", true);
            }

            if (!Page.IsPostBack)
            {
                LoadInfo();
            }

            if (Request.QueryString["upgrade"] != null)
            {
                this.LblStatus.Text = "Your account was successfully upgraded!";
                this.LblStatus.ForeColor = System.Drawing.Color.Green;
            }
        }