Exemple #1
0
        public async Task Notify(CustomerSubscriptionInvoiceUpdated busEvent)
        {
            var customer = await customerRepo.FindByBillingId(busEvent.CustomerBillingId) ?? throw new EntityNotFoundException();

            var user = await userRepo.FindById(customer.UserId) ?? throw new EntityNotFoundException();


            switch (busEvent.SubscriptionStatus)
            {
            case SubscriptionStatus.Active:
            case SubscriptionStatus.Trialing:
            case SubscriptionStatus.Incomplete:
            case SubscriptionStatus.Unpaid:
                var plan = await subscriptionPlanRepo.FindById(busEvent.PlanId) ?? throw new EntityNotFoundException();

                await roleAssigner.ReplaceRoles(user, (Guid)plan.RoleId !);    //TODO: Fix this

                break;

            case SubscriptionStatus.IncompleteExpired:
            case SubscriptionStatus.PastDue:
            case SubscriptionStatus.Canceled:
                await roleAssigner.ReplaceRoles(user, "Free");

                break;
            }
        }
Exemple #2
0
        public async override Task Execute(SubscriptionPlanUpdateCommand input, User?user)
        {
            var plan = await repo.FindById(input.Id);

            if (plan == null)
            {
                throw new EntityNotFoundException();
            }

            plan.Description = input.Description;
            plan.RoleId      = input.RoleId;

            await repo.Update(plan);
        }
Exemple #3
0
        // Don't delete. It's used twice in the app layer.
        public async Task <List <SubscriptionPlan> > RefreshPlans()
        {
            var plans = await gateway.GetAll();

            foreach (var plan in plans)
            {
                var existingPlan = await repo.FindById(plan.Id);

                if (existingPlan == null)
                {
                    await repo.Add(plan);
                }
                else
                {
                    // We don't want to wipe out some extra data we keep on our end. (Description, RoleId)
                    existingPlan.Name   = plan.Name;
                    existingPlan.Prices = plan.Prices;

                    await repo.Update(existingPlan);
                }
            }

            return(plans);
        }