Cancel() public method

public Cancel ( string customerId, string subscriptionId, bool cancelAtPeriodEnd = false, Stripe.StripeRequestOptions requestOptions = null ) : Stripe.StripeSubscription
customerId string
subscriptionId string
cancelAtPeriodEnd bool
requestOptions Stripe.StripeRequestOptions
return Stripe.StripeSubscription
示例#1
0
        public void Cancel(PawzeUser pawzeUser, Subscription pawzeSubscription)
        {
            var subscriptionService         = new Stripe.StripeSubscriptionService(APIKey);
            StripeSubscription subscription = subscriptionService.Cancel(pawzeUser.StripeCustomerId, pawzeSubscription.StripeSubscriptionId);

            pawzeSubscription.StripeSubscriptionId = null;

            _subscriptionRepository.Update(pawzeSubscription);

            _unitOfWork.Commit();
        }
示例#2
0
    public static string CancelSubscription(int userId)
    {
        Users user = Users.LoadById(userId);
        try
        {
            var subscriptionService = new StripeSubscriptionService();
            foreach (StripeSubscription subscription in subscriptionService.List(user.StripeCustomerId))
            {
                user.Ended = subscription.PeriodEnd;
                user.Cancelled = true;
                user.Save();

                subscriptionService.Cancel(user.StripeCustomerId, subscription.Id);
            }
        }
        catch(Exception ex)
        {
            return "Error: " + ex.Message;
        }
        return "";
    }
        public override async Task HandleItemAsync(WorkItemContext context) {
            var workItem = context.GetData<RemoveOrganizationWorkItem>();
            Logger.Info().Message($"Received remove organization work item for: {workItem.OrganizationId}").Write();

            await context.ReportProgressAsync(0, "Starting deletion...").AnyContext();
            var organization = await _organizationRepository.GetByIdAsync(workItem.OrganizationId).AnyContext();
            if (organization == null) {
                await context.ReportProgressAsync(100, "Organization deleted").AnyContext();
                return;
            }

            await context.ReportProgressAsync(10, "Removing subscriptions").AnyContext();
            if (!String.IsNullOrEmpty(organization.StripeCustomerId)) {
                Logger.Info().Message($"Canceling stripe subscription for the organization '{organization.Name}' with Id: '{organization.Id}'.").Write();

                var subscriptionService = new StripeSubscriptionService(Settings.Current.StripeApiKey);
                var subscriptions = subscriptionService.List(organization.StripeCustomerId).Where(s => !s.CanceledAt.HasValue);
                foreach (var subscription in subscriptions)
                    subscriptionService.Cancel(organization.StripeCustomerId, subscription.Id);
            }

            await context.ReportProgressAsync(20, "Removing users").AnyContext();
            var users = await _userRepository.GetByOrganizationIdAsync(organization.Id).AnyContext();
            foreach (User user in users.Documents) {
                // delete the user if they are not associated to any other organizations and they are not the current user
                if (user.OrganizationIds.All(oid => String.Equals(oid, organization.Id)) && !String.Equals(user.Id, workItem.CurrentUserId)) {
                    Logger.Info().Message("Removing user '{0}' as they do not belong to any other organizations.", user.Id, organization.Name, organization.Id).Write();
                    await _userRepository.RemoveAsync(user.Id).AnyContext();
                } else {
                    Logger.Info().Message("Removing user '{0}' from organization '{1}' with Id: '{2}'", user.Id, organization.Name, organization.Id).Write();
                    user.OrganizationIds.Remove(organization.Id);
                    await _userRepository.SaveAsync(user, true).AnyContext();
                }
            }

            await context.ReportProgressAsync(30, "Removing tokens").AnyContext();
            await _tokenRepository.RemoveAllByOrganizationIdsAsync(new[] { organization.Id }).AnyContext();

            await context.ReportProgressAsync(40, "Removing web hooks").AnyContext();
            await _webHookRepository.RemoveAllByOrganizationIdsAsync(new[] { organization.Id }).AnyContext();

            await context.ReportProgressAsync(50, "Removing projects").AnyContext();
            var projects = await _projectRepository.GetByOrganizationIdAsync(organization.Id).AnyContext();
            if (workItem.IsGlobalAdmin && projects.Total > 0) {
                var completed = 1;
                foreach (Project project in projects.Documents) {
                    Logger.Info().Message("Resetting all project data for project '{0}' with Id: '{1}'.", project.Name, project.Id).Write();
                    await _eventRepository.RemoveAllByProjectIdsAsync(new[] { project.Id }).AnyContext();
                    await _stackRepository.RemoveAllByProjectIdsAsync(new[] { project.Id }).AnyContext();
                    await context.ReportProgressAsync(CalculateProgress(projects.Total, completed++, 51, 89), "Removing projects...").AnyContext();
                }

                Logger.Info().Message("Deleting all projects for organization '{0}' with Id: '{1}'.", organization.Name, organization.Id).Write();
                await _projectRepository.RemoveAsync(projects.Documents).AnyContext();
            }

            Logger.Info().Message("Deleting organization '{0}' with Id: '{1}'.", organization.Name, organization.Id).Write();
            await context.ReportProgressAsync(90, "Removing organization").AnyContext();
            await _organizationRepository.RemoveAsync(organization.Id).AnyContext();

            await context.ReportProgressAsync(100, "Organization deleted").AnyContext();
        }
        public async Task<ActionResult> CancelSubscription()
        {          
            await Task.Run(() =>
            {
                var hasSubscription = getCustomer().HasSubscription;
                if(hasSubscription == true)
                {
                    var uStripeCustomer = getCustomer();
                    var stripeCustomerID = uStripeCustomer.StripeCustomerID;
                    var subscriptionID = uStripeCustomer.StripeSubscriptionID;                    
                  
                    if (uStripeCustomer.SubscriptionType == "ultimate")
                    {
                        // cancel subscription in stripe.com
                        var subscriptionService = new StripeSubscriptionService();
                        subscriptionService.Cancel(stripeCustomerID, subscriptionID);

                        // delete stripe customer as well
                        var customerService = new StripeCustomerService();
                        StripeCustomer customerToDelete = customerService.Get(stripeCustomerID);
                        customerService.Delete(customerToDelete.Id);

                        db.StripeCustomers.Remove(uStripeCustomer); //db
                    }
                    else if (uStripeCustomer.SubscriptionType == "standard")
                    {
                        // cancel subscription in stripe.com
                        var subscriptionService = new StripeSubscriptionService();
                        subscriptionService.Cancel(stripeCustomerID, subscriptionID);

                        // delete stripe customer as well
                        var customerService = new StripeCustomerService();
                        StripeCustomer customerToDelete = customerService.Get(stripeCustomerID);
                        customerService.Delete(customerToDelete.Id);

                        uStripeCustomer.HasSubscription = false; //db
                    }
                    db.SaveChanges();                  
                }
            });
         
            return RedirectToAction("Index", "Home");
        }
示例#5
0
        /// <summary>
        /// Unsubscribes the given subscription
        /// NOTE: Save changes on the underlying context for the model after calling this method
        /// </summary>
        /// <param name="subscription"></param>
        public static void Unsubscribe(IStripeUser user, IStripeSubscription subscription)
        {
            if (string.IsNullOrEmpty(subscription.PaymentSystemId) || string.IsNullOrEmpty(user.PaymentSystemId))
                return;

            var subscriptionService = new StripeSubscriptionService();
            subscriptionService.Cancel(subscription.PaymentSystemId, user.PaymentSystemId);
            subscription.PaymentSystemId = null;

            System.Diagnostics.Trace.TraceInformation("Unsuscribed customer in stripe: '{0}' with new subscription id '{1}", user.Email, subscription.PaymentSystemId);
        }