public static DataAccessResponseType ProcessStripeCustomerDelinquencyChangedEvent(string accountId, string storagePartition, bool newDelinquencyStatus)
        {
            var response = new DataAccessResponseType();

            if (newDelinquencyStatus == false)
            {
                //Account is no longer delinquent according to stripe.

                //Turn off Delinquent state
                AccountManager.UpdateAccountDelinquentStatus(accountId, false);

                //Clear DunningAttempts Table:
                PlatformBillingManager.ClearAutomaticDunningAttempt(accountId, storagePartition);
            }
            else if (newDelinquencyStatus == true)
            {
                //Account is delinquent according to stripe.

                //Turn on Delinquent state:
                AccountManager.UpdateAccountDelinquentStatus(accountId, true);
            }

            response.isSuccess = true;

            return(response);
        }
        public static DataAccessResponseType ProcessStripeSubscriptionStatusChangedEvent(Account account, string newSubscriptionStatus, string previousSubscriptionStatus)
        {
            var response = new DataAccessResponseType();


            if (newSubscriptionStatus == "active" && previousSubscriptionStatus == "unpaid" ||
                newSubscriptionStatus == "active" && previousSubscriptionStatus == "past_due")
            {
                // Turn off delinquncy, clear dunning & reactive the account
                AccountManager.UpdateAccountActiveState(account.AccountID.ToString(), true);
                AccountManager.UpdateAccountDelinquentStatus(account.AccountID.ToString(), false);
                PlatformBillingManager.ClearAutomaticDunningAttempt(account.AccountID.ToString(), account.StoragePartition);
            }
            else if (newSubscriptionStatus == "past_due" && previousSubscriptionStatus == "active")
            {
                // Turn on delinquncy: The 'ProcessFailedStripeInvoicedChargeEvent' will handle the dunning emails
                AccountManager.UpdateAccountDelinquentStatus(account.AccountID.ToString(), true);
            }
            else if (newSubscriptionStatus == "unpaid" && previousSubscriptionStatus == "past_due")
            {
                // 1. Deactivate the account, assure that delinquent is still true send final email
                AccountManager.UpdateAccountActiveState(account.AccountID.ToString(), false);
                AccountManager.UpdateAccountDelinquentStatus(account.AccountID.ToString(), true);

                // 2. get the account
                //var account = AccountManager.GetAccount(accountId);

                // 3. Get all owners for the account:
                var accountOwnerEmails = AccountManager.GetAccountOwnerEmails(account.AccountID.ToString());

                //Stripe has marked the Subscritption as 'unpaid'. Messaing is an alert about account closure
                // 4. Email all account owners

                //email all account owners a copy of account closure email
                EmailManager.Send(
                    accountOwnerEmails,
                    Settings.Endpoints.Emails.FromAlerts,
                    Settings.Copy.EmailMessages.InvoicedChargeFailed_AccountDeactivated.FromName,
                    String.Format(Settings.Copy.EmailMessages.InvoicedChargeFailed_AccountDeactivated.Subject),
                    String.Format(Settings.Copy.EmailMessages.InvoicedChargeFailed_AccountDeactivated.Body, account.AccountName),
                    true);


                // 5. Email Platform Admins
                EmailManager.Send(
                    Settings.Endpoints.Emails.PlatformEmailAddresses,
                    Settings.Endpoints.Emails.FromPlatform,
                    "ACCOUNT DEACTIVATED",
                    "An account has been deactivated due to an unpaid subscription",
                    "AccountName: <b>" + account.AccountName + "</b><br/><br/>AccountID: <b>" + account.AccountID + "</b><br/>",
                    true);
            }

            response.isSuccess = true;

            return(response);
        }