protected void BtnEnableSubscription_Click(Object sender, EventArgs e) { String returnurl = "http://" + GooeyConfigManager.AdminSiteHost + "/auth/Manage.aspx"; String cancelurl = returnurl; CmsSubscription subscription = SubscriptionManager.GetSubscription(CurrentSite.Guid); if (subscription.SubscriptionPlanEnum == Constants.SubscriptionPlans.Business) { PaypalExpressCheckout checkout = new PaypalExpressCheckout(); PaypalProfileInfo paypal = PaypalManager.Instance.GetProfileInfo(subscription.PaypalProfileId); if (paypal.IsSuspended) { //Simply re-enable the suspended profile checkout.Reactivate(subscription.PaypalProfileId); } else if (paypal.IsCancelled) { //Send the user to paypal to reestablish the billing profile BtnUpgradePlan_Click(sender, e); } } subscription.IsDisabled = false; SubscriptionManager.Save(subscription); //Clear the site cache CurrentSite.Cache.Clear(); Response.Redirect("~/auth/Manage.aspx"); }
public PaypalProfileInfo GetProfileInfo(string profileId) { PaypalProfileInfo info = null; if (!String.IsNullOrEmpty(profileId)) { PaypalExpressCheckout paypal = new PaypalExpressCheckout(); info = paypal.GetProfileInfo(profileId); } return info; }
protected void BtnDelete_Click(Object sender, EventArgs e) { String guid = Request.QueryString["g"]; CmsSubscription subscription = SubscriptionManager.GetSubscription(guid); String profileId = subscription.PaypalProfileId; SubscriptionManager.CancelSubscription(subscription); PaypalExpressCheckout paypal = new PaypalExpressCheckout(); PaypalProfileInfo info = paypal.GetProfileInfo(profileId); if (info != null) this.LblProfileStatus.Text = info.Status; else this.LblProfileStatus.Text = "DELETED"; this.EditPanel.Enabled = false; this.LblStatus.Text = "This subscription has been successfully deleted."; }
protected void BtnSubscribe_Click(Object sender, EventArgs e) { Registration registration = Registrations.Load(this.Guid); double total = SubscriptionManager.CalculateCost(registration); if (total > 0) { //Create all of the billing agreements PaypalExpressCheckout checkout = new PaypalExpressCheckout(); checkout.AddBillingAgreement(registration); String redirect = checkout.SetExpressCheckout(registration.Email, registration.Guid); Response.Redirect(redirect, true); } else { String encrypted = TextEncryption.Encode(registration.Guid); Response.Redirect("Activate.aspx?_ftoken=" + Server.UrlEncode(encrypted)); } }
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); } }
protected void BtnDowngradePlan_Click(Object sender, EventArgs e) { //Cancel the paypal subscription CmsSubscription subscription = SubscriptionManager.GetSubscription(CurrentSite.Guid); subscription.IsCampaignEnabled = false; subscription.IsSalesforceEnabled = false; PaypalExpressCheckout checkout = new PaypalExpressCheckout(); checkout.Cancel(subscription.PaypalProfileId); String paypalId = subscription.PaypalProfileId; subscription.SubscriptionPlan = SubscriptionManager.GetSubscriptionPlan(Constants.SubscriptionPlans.Free); SubscriptionManager.Save(subscription); //Clear the site cache CurrentSite.Cache.Clear(); BillingManager.Instance.AddHistory(subscription.Guid, paypalId, null, BillingManager.Downgrade, 0, "Paypal billing profile successfully cancelled and subscription downgraded to 'free'"); LoadInfo(); }
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; } }
protected void BtnUpgradePlan_Click(Object sender, EventArgs e) { String returnurl = "http://" + GooeyConfigManager.AdminSiteHost + "/auth/Manage.aspx"; String cancelurl = returnurl; CmsSubscription subscription = SubscriptionManager.GetSubscription(CurrentSite.Guid); subscription.IsCampaignEnabled = false; subscription.IsSalesforceEnabled = false; if (this.ChkUpgradeCampaignOption.Checked) subscription.IsCampaignEnabled = true; if (this.ChkUpgradeSalesforceOption.Checked) subscription.IsSalesforceEnabled = true; String options = String.Format("{0}|{1}",subscription.IsCampaignEnabled.StringValue(), subscription.IsSalesforceEnabled.StringValue()); options = TextEncryption.Encode(options); int freeTrialLength = (int)SubscriptionManager.CalculateFreeTrialRemaining(subscription); //Cookie the user with what options need enabled HttpCookie cookie = new HttpCookie("upgrade-options",options); Response.Cookies.Add(cookie); subscription.SubscriptionPlan = SubscriptionManager.GetSubscriptionPlan(Constants.SubscriptionPlans.Business); PaypalExpressCheckout checkout = new PaypalExpressCheckout(); checkout.AddBillingAgreement(PaypalExpressCheckout.GetBillingAgreement(subscription,freeTrialLength)); String redirect = checkout.SetExpressCheckout(LoggedInUser.Email, subscription.Guid,returnurl,cancelurl); Response.Redirect(redirect, true); }