Exemplo n.º 1
0
        public void SendCancellationEmail(CmsSubscription subscription)
        {
            String template = GooeyConfigManager.GetEmailTemplate(EmailTemplates.Cancel);
            String body = PerformReplacements(template,subscription);

            EmailInfo info = GetEmailInfo(body, subscription.PrimaryUser.Email);
            SendEmail(info);
        }
Exemplo n.º 2
0
        public void SendRegistrationEmail(CmsSubscription subscription, Registration registration)
        {
            String template = GooeyConfigManager.GetEmailTemplate(EmailTemplates.Signup);
            String body = PerformReplacements(template,subscription: subscription, registration: registration);

            EmailInfo info = GetEmailInfo(body, subscription.PrimaryUser.Email);
            SendEmail(info);
        }
Exemplo n.º 3
0
        private static void AddSalesforceLead(Registration registration, CmsSubscription subscription)
        {
            try
            {
                if (GooeyConfigManager.Salesforce.IsEnabled)
                {
                    Dictionary<String, String> fields = new Dictionary<string, string>();
                    fields.Add("FirstName", registration.Firstname);
                    fields.Add("LastName", registration.Lastname);
                    fields.Add("Company", registration.Company);
                    fields.Add("Email", registration.Email);
                    fields.Add("Gooey_CMS_Site__c", registration.Sitename + ".gooeycms.net");

                    fields.Add("subscription_type__c", subscription.SubscriptionPlanSku);
                    fields.Add("PayPal_Profile__c", subscription.PaypalProfileId);
                    fields.Add("Subscription_ID__c", subscription.Guid);

                    SalesforcePartnerClient salesforce = new SalesforcePartnerClient();
                    try
                    {
                        salesforce.Login(GooeyConfigManager.Salesforce.SalesforceUsername, GooeyConfigManager.Salesforce.ApiPassword);
                        salesforce.AddLead(fields, null);
                    }
                    finally
                    {
                        salesforce.Logout();
                    }
                }
                else
                {
                    Logging.Database.Write("salesforce-client", "Salesforce has not been setup for tracking registration leads");
                }
            }
            catch (Exception e)
            {
                Logging.Database.Write("salesforce-client", "Failed to create the salesforce lead:" + e.Message);
            }
        }
Exemplo n.º 4
0
        private String PerformReplacements(String body, CmsSubscription subscription = null, Registration registration = null, Receipt receipt = null)
        {
            UserInfo user = null;
            if (receipt == null)
                user = MembershipUtil.FindByUserGuid(subscription.PrimaryUserGuid).UserInfo;
            else
                user = MembershipUtil.FindByUserGuid(receipt.UserGuid).UserInfo;

            body = body.Replace("{email}", user.Email);
            body = body.Replace("{firstname}", user.Firstname);
            body = body.Replace("{lastname}", user.Lastname);
            body = body.Replace("{username}", user.Username);
            body = body.Replace("{current-date}", UtcDateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"));

            if (subscription != null)
            {
                Double totalCost = SubscriptionManager.CalculateCost(subscription);
                body = body.Replace("{domain}", subscription.Domain);
                body = body.Replace("{staging-domain}", subscription.StagingDomain);
                body = body.Replace("{subscription-cost}", String.Format("{0:c}", totalCost));
                body = body.Replace("{subscription-description}", SubscriptionManager.GetSubscriptionDescription(subscription).ToString());
                body = body.Replace("{paypal-id}", subscription.PaypalProfileId);
            }
            else
            {
                body = body.Replace("{domain}", String.Empty);
                body = body.Replace("{staging}", String.Empty);
                body = body.Replace("{subscription-cost}", String.Empty);
                body = body.Replace("{subscription-description}", String.Empty);
                body = body.Replace("{paypal-id}", String.Empty);
            }

            if (registration != null)
            {
                String password = TextEncryption.Decode(registration.EncryptedPassword);
                body = body.Replace("{password}", password);
            }
            else
            {
                body = body.Replace("{password}", String.Empty);
            }

            if (receipt != null)
            {
                String packageGuid = receipt.PackageGuid;
                Package package = SitePackageManager.NewInstance.GetPackage(packageGuid);

                body = body.Replace("{purchase-type}", package.PackageType.ToString());
                body = body.Replace("{purchase-date}", receipt.Created.ToString("MM/dd/yyyy"));
                body = body.Replace("{purchase-amount}", String.Format("{0:c}",receipt.Amount));
                body = body.Replace("{purchase-name}", package.Title);
                body = body.Replace("{purchase-txid}", receipt.TransactionId);
            }

            return body.Trim();
        }
        /// <summary>
        /// Gets all of the billing agreements for the specified registration
        /// </summary>
        /// <param name="registration"></param>
        /// <returns></returns>
        public static NvpBaItem GetBillingAgreement(CmsSubscription subscription, int freeTrialLength = -1)
        {
            if (freeTrialLength == -1)
                freeTrialLength = GooeyConfigManager.FreeTrialLength;

            StringBuilder description = new StringBuilder();
            CmsSubscriptionPlan plan = subscription.SubscriptionPlan;
            Double totalPrice = (Double)plan.Price;

            description.AppendFormat("{0} / {1:c} ", plan.Name, plan.Price);
            if (subscription.IsCampaignEnabled)
            {
                description.AppendFormat(" +Campaigns / {0:c} ", GooeyConfigManager.CampaignOptionPrice);
                totalPrice += GooeyConfigManager.CampaignOptionPrice;
            }

            if (subscription.IsSalesforceEnabled)
            {
                description.AppendFormat(" +Salesforce / {0:c} ", GooeyConfigManager.SalesForcePrice);
                totalPrice += GooeyConfigManager.SalesForcePrice;
            }
            description.AppendFormat(". Total: {0:c} / month",totalPrice);

            if (freeTrialLength > 0)
                description.AppendFormat(" after {0} days free.", freeTrialLength);

            return PaypalExpressCheckout.GetBillingAgreement(subscription.Guid, description.ToString());
        }
        public ProfileResultStatus CreateRecurringPayment(CmsSubscription subscription, int freeTrial = -1)
        {
            //Check if they have an existing billing profile active, if so, cancel it, so we can create the new one
            PaypalProfileInfo existingProfile = GetProfileInfo(subscription.PaypalProfileId);
            if ((existingProfile != null) && (existingProfile.IsActive))
            {
                try
                {
                    this.Cancel(existingProfile.ProfileId);
                }
                catch (Exception ex)
                {
                    Logging.Database.Write("paypal-error", "There was a problem cancelling existing profile. Subscription: " + subscription.Guid + ", Paypal Profile Id:" + existingProfile.ProfileId + ", Error: " + ex.Message);
                    throw new ApplicationException("There was a problem upgrading your account. There seems to be an active billing profile which we were unable to automatically cancel. Please contact custom support.");
                }
            }

            //Create the new agreement
            NvpBaItem agreement = GetBillingAgreement(subscription, freeTrial);
            Double total = SubscriptionManager.CalculateCost(subscription);

            return CreateRecurringPayment(agreement, total, freeTrial);
        }
Exemplo n.º 7
0
 public static void DeleteAllAccounts(CmsSubscription subscription)
 {
     if (subscription != null)
     {
         IList<UserInfo> users = GetUsersBySite(subscription.Id);
         foreach (UserInfo user in users)
         {
             DeleteUser(user);
         }
     }
 }
Exemplo n.º 8
0
        public void DeployDemoPackage(Data.Guid packageGuid, IPackageStatusNotifier notifier)
        {
            DoNotify(notifier, "Deploying Demo Package");

            PackageDao dao = new PackageDao();
            Package package = dao.FindByPackageGuid(packageGuid);
            if (package != null)
            {
                //Get the owner's subscription for this package
                CmsSubscription owner = SubscriptionManager.GetSubscription(package.OwnerSubscriptionId);
                DoNotify(notifier, "Creating Demo Account");

                //Check if our demo account exists
                MembershipUserWrapper wrapper = MembershipUtil.FindByUsername(MembershipUtil.DemoAccountUsername);
                if (!wrapper.IsValid())
                    wrapper = MembershipUtil.CreateDemoAccount();

                //Find a free subdomain name
                String subdomain = "demo-" + owner.Subdomain;
                Boolean isAvailable = SubscriptionManager.IsSubdomainAvailable(subdomain);
                int i = 1;
                while (!isAvailable)
                {
                    i++;
                    subdomain = "demo" + i.ToString() + "-" + owner.Subdomain;
                    isAvailable = SubscriptionManager.IsSubdomainAvailable(subdomain);
                }

                //Create a new subscription for the demo account
                CmsSubscription subscription = new CmsSubscription();
                subscription.Guid = package.Guid;
                subscription.Created = UtcDateTime.Now;
                subscription.Subdomain = subdomain;
                subscription.StagingDomain = subscription.Subdomain + GooeyConfigManager.DefaultCmsDomain;
                subscription.SubscriptionPlan = SubscriptionManager.GetSubscriptionPlan(SubscriptionPlans.Demo);
                subscription.PrimaryUser= wrapper.UserInfo;
                subscription.IsDemo = true;
                subscription.IsCampaignEnabled = true;
                subscription.Expires = DateTime.MaxValue;
                subscription.Culture = GooeyConfigManager.DefaultCulture;
                SubscriptionManager.Create(wrapper, subscription);

                DoNotify(notifier, "Reading Package From Archive");
                //Deploy the package into the demo site
                IStorageClient client = StorageHelper.GetStorageClient();
                byte [] zipped = client.Open(PackageContainer, PackageDirectory, package.Guid + PackageExtension);

                Compression.ZipHandler zip = new Compression.ZipHandler(zipped);
                byte [] serialized = zip.Decompress()[0].Data;

                SitePackage sitepackage = Serializer.ToObject<SitePackage>(serialized);

                Data.Guid guid = Data.Guid.New(subscription.Guid);

                DoNotify(notifier, "Deploying Package Themes To Site");
                DeployThemes(sitepackage, guid, notifier);

                DoNotify(notifier, "Deploying Package Pages To Site");
                DeployPages(sitepackage, guid, notifier);

                DoNotify(notifier, "Deploying Package Content Types To Site");
                DeployContentTypes(sitepackage, guid);

                DoNotify(notifier, "Deploying Package Content To Site");
                DeployContent(sitepackage, guid);
            }
        }
 /// <summary>
 /// Detect if the cancellation is for simply the campaign option or for the subscription itself
 /// </summary>
 /// <param name="subscription"></param>
 private void ProcessCancellation(CmsSubscription subscription)
 {
     if (subscription.SubscriptionPlanEnum == Constants.SubscriptionPlans.Free)
     {
         subscription.IsCampaignEnabled = false;
         SubscriptionManager.Save(subscription);
     }
     else
     {
         SubscriptionManager.DisableSubscription(subscription);
     }
 }