From 56a4cdb06b4cd5d1f15a40875d89a3f782d65369 Mon Sep 17 00:00:00 2001 From: DavidEggenberger Date: Tue, 26 Mar 2024 21:31:27 +0100 Subject: [PATCH] pauseactivesubscription command --- ...enant.cs => CreateTrialingSubscription.cs} | 7 ++--- .../Commands/DeleteSubscription.cs | 9 ------ ...eriodEnd.cs => PauseActiveSubscription.cs} | 6 ++-- .../Commands/UpdateSubscriptionPeriod.cs | 17 +++++++++++ .../GetSubscriptionForTenant.cs | 2 +- .../StripePayments/StripeOptions.cs | 28 ------------------- .../Web/Server/WebHooks/StripeWebhook.cs | 9 ++++-- 7 files changed, 31 insertions(+), 47 deletions(-) rename Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/{CreateTrialingSubscriptionForTenant.cs => CreateTrialingSubscription.cs} (90%) delete mode 100644 Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/DeleteSubscription.cs rename Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/{UpdateSubscriptionPeriodEnd.cs => PauseActiveSubscription.cs} (64%) create mode 100644 Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs rename Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/{Commands => Queries}/GetSubscriptionForTenant.cs (89%) delete mode 100644 Source/Modules/Subscriptions/Features/Infrastructure/StripePayments/StripeOptions.cs diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscriptionForTenant.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs similarity index 90% rename from Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscriptionForTenant.cs rename to Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs index 4ad548a4..f230e5f4 100644 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscriptionForTenant.cs +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs @@ -9,7 +9,7 @@ namespace Modules.Subscriptions.Features.DomainFeatures.StripeSubscriptionAggregate.Application.Commands { - public class CreateTrialingSubscriptionForTenant : ICommand + public class CreateTrialingSubscription : ICommand { public Guid UserId { get; set; } public Guid TenantId { get; set; } @@ -17,11 +17,10 @@ public class CreateTrialingSubscriptionForTenant : ICommand public Stripe.Subscription CreatedStripeSubscription { get; set; } } - public class CreateTrialingSubscriptionCommandHandler : ServerExecutionBase, ICommandHandler + public class CreateTrialingSubscriptionCommandHandler : ServerExecutionBase, ICommandHandler { private readonly SubscriptionsDbContext subscriptionDbContext; private readonly SubscriptionsConfiguration subscriptionConfiguration; - private readonly IIntegrationEventDispatcher integrationEventDispatcher; public CreateTrialingSubscriptionCommandHandler( SubscriptionsDbContext subscriptionDbContext, @@ -32,7 +31,7 @@ public CreateTrialingSubscriptionCommandHandler( this.subscriptionConfiguration = subscriptionConfiguration; } - public async Task HandleAsync(CreateTrialingSubscriptionForTenant command, CancellationToken cancellationToken) + public async Task HandleAsync(CreateTrialingSubscription command, CancellationToken cancellationToken) { var subscriptionType = subscriptionConfiguration.Subscriptions.First(s => s.StripePriceId == command.CreatedStripeSubscription.Items.First().Price.Id).Type; diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/DeleteSubscription.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/DeleteSubscription.cs deleted file mode 100644 index 22359440..00000000 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/DeleteSubscription.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Shared.Features.CQRS.Command; - -namespace Modules.Subscriptions.Features.DomainFeatures.StripeSubscriptionAggregate.Application.Commands -{ - public class DeleteSubscription : ICommand - { - public Stripe.Subscription Subscription { get; set; } - } -} diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriodEnd.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/PauseActiveSubscription.cs similarity index 64% rename from Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriodEnd.cs rename to Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/PauseActiveSubscription.cs index e9ea2050..5fc7fa69 100644 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriodEnd.cs +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/PauseActiveSubscription.cs @@ -2,14 +2,14 @@ namespace Modules.Subscriptions.Features.DomainFeatures.StripeSubscriptionAggregate.Application.Commands { - public class UpdateSubscriptionPeriodEnd : ICommand + public class UpdateSubscriptionPeriod : ICommand { public Stripe.Subscription Subscription { get; set; } } - public class UpdateSubscriptionPerioEndCommandHandler : ICommandHandler + public class UpdateSubscriptionPerioEndCommandHandler : ICommandHandler { - public Task HandleAsync(UpdateSubscriptionPeriodEnd command, CancellationToken cancellationToken) + public Task HandleAsync(UpdateSubscriptionPeriod command, CancellationToken cancellationToken) { throw new NotImplementedException(); } diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs new file mode 100644 index 00000000..5fc7fa69 --- /dev/null +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriod.cs @@ -0,0 +1,17 @@ +using Shared.Features.CQRS.Command; + +namespace Modules.Subscriptions.Features.DomainFeatures.StripeSubscriptionAggregate.Application.Commands +{ + public class UpdateSubscriptionPeriod : ICommand + { + public Stripe.Subscription Subscription { get; set; } + } + + public class UpdateSubscriptionPerioEndCommandHandler : ICommandHandler + { + public Task HandleAsync(UpdateSubscriptionPeriod command, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + } +} diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/GetSubscriptionForTenant.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Queries/GetSubscriptionForTenant.cs similarity index 89% rename from Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/GetSubscriptionForTenant.cs rename to Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Queries/GetSubscriptionForTenant.cs index 970b4f7e..60f71675 100644 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Commands/GetSubscriptionForTenant.cs +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeSubscriptionAggregate/Application/Queries/GetSubscriptionForTenant.cs @@ -1,7 +1,7 @@ using Shared.Features.CQRS.Query; using Shared.Kernel.BuildingBlocks.Auth.Attributes; -namespace Modules.Subscriptions.Features.DomainFeatures.StripeSubscriptionAggregate.Application.Commands +namespace Modules.Subscriptions.Features.DomainFeatures.StripeSubscriptionAggregate.Application.Queries { [AuthorizeTenantAdmin] public class GetSubscriptionForTenant : IQuery diff --git a/Source/Modules/Subscriptions/Features/Infrastructure/StripePayments/StripeOptions.cs b/Source/Modules/Subscriptions/Features/Infrastructure/StripePayments/StripeOptions.cs deleted file mode 100644 index 4db31841..00000000 --- a/Source/Modules/Subscriptions/Features/Infrastructure/StripePayments/StripeOptions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Shared.Kernel.BuildingBlocks.Auth; - -namespace Modules.Subscriptions.Features.Infrastructure.StripePayments -{ - public class StripeOptions - { - public string EndpointSecret { get; set; } - public string ProfessionalPlanPriceId { get; set; } - public string EnterprisePlanPriceId { get; set; } - - public List GetStripeSubscriptionPlans() - { - return new List() - { - new StripeSubscriptionPlan - { - Type = SubscriptionPlanType.Professional, - StripePriceId = ProfessionalPlanPriceId - }, - new StripeSubscriptionPlan - { - Type = SubscriptionPlanType.Enterprise, - StripePriceId = EnterprisePlanPriceId - } - }; - } - } -} diff --git a/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs b/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs index 6a569ef7..e6897e7d 100644 --- a/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs +++ b/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs @@ -39,7 +39,7 @@ public async Task Index() var subscription = await new SubscriptionService().GetAsync(session.SubscriptionId); var userId = subscription.Metadata["UserId"]; - var createTrialingSubscription = new CreateTrialingSubscriptionForTenant + var createTrialingSubscription = new CreateTrialingSubscription { UserId = Guid.Parse(userId), StripeCustomerId = subscription.CustomerId, @@ -55,7 +55,12 @@ public async Task Index() var subscription = await new SubscriptionService().GetAsync(invoice.SubscriptionId); - + var updateSubscriptionPeriod = new UpdateSubscriptionPeriod + { + + }; + + } // Sent each billing interval if there is an issue with your customer’s payment method. (Stripe) else if (stripeEvent.Type == Events.InvoicePaymentFailed)