From bdf5931d68c329a3abc45b05e2f8a85eaea75bde Mon Sep 17 00:00:00 2001 From: DavidEggenberger Date: Sun, 17 Mar 2024 20:48:10 +0100 Subject: [PATCH] deleting leftover subscription module files --- .../UserCreatedIntegrationEventHandler.cs | 42 ------------- .../StripeCustomerAggregate/StripeCustomer.cs | 24 ------- .../Commands/CreateTrialingSubscription.cs | 63 ------------------- .../Commands/UpdateActiveSubscription.cs | 28 --------- .../StripeSubscription.cs | 32 ---------- .../StripeSubscriptionStatus.cs | 11 ---- 6 files changed, 200 deletions(-) delete mode 100644 Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/Application/IntegrationEventHandlers/UserCreatedIntegrationEventHandler.cs delete mode 100644 Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/StripeCustomer.cs delete mode 100644 Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs delete mode 100644 Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateActiveSubscription.cs delete mode 100644 Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs delete mode 100644 Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscriptionStatus.cs diff --git a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/Application/IntegrationEventHandlers/UserCreatedIntegrationEventHandler.cs b/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/Application/IntegrationEventHandlers/UserCreatedIntegrationEventHandler.cs deleted file mode 100644 index 7cab67bc..00000000 --- a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/Application/IntegrationEventHandlers/UserCreatedIntegrationEventHandler.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Modules.Identity.IntegrationEvents; -using Modules.Subscription.Features.Infrastructure.EFCore; -using Shared.Features.CQRS.IntegrationEvent; -using Stripe; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Modules.Subscriptions.Features.Aggregates.StripeCustomerAggregate.Application.IntegrationEventHandlers -{ - public class UserCreatedIntegrationEventHandler : IIntegrationEventHandler - { - private readonly SubscriptionsDbContext subscriptionsDbContext; - public UserCreatedIntegrationEventHandler(SubscriptionsDbContext subscriptionsDbContext) - { - this.subscriptionsDbContext = subscriptionsDbContext; - } - - public async Task HandleAsync(UserCreatedIntegrationEvent userCreatedIntegrationEvent, CancellationToken cancellation) - { - var stripeCustomerService = new CustomerService(); - - var options = new CustomerCreateOptions - { - Email = userCreatedIntegrationEvent.Email, - Metadata = new Dictionary - { - ["UserId"] = userCreatedIntegrationEvent.UserId.ToString() - } - }; - - var customer = await stripeCustomerService.CreateAsync(options); - - var stripeCustomer = StripeCustomer.Create(userCreatedIntegrationEvent.UserId, customer.Id); - - subscriptionsDbContext.StripeCustomers.Add(stripeCustomer); - - await subscriptionsDbContext.SaveChangesAsync(); - } - } -} diff --git a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/StripeCustomer.cs b/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/StripeCustomer.cs deleted file mode 100644 index f6793ec6..00000000 --- a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeCustomerAggregate/StripeCustomer.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Shared.Features.DomainKernel; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Modules.Subscriptions.Features.Aggregates.StripeCustomerAggregate -{ - public class StripeCustomer : AggregateRoot - { - public string StripePortalCustomerId { get; set; } - - public static StripeCustomer Create(Guid userId, string stripePortalCustomerId) - { - return new StripeCustomer - { - CreatedAt = DateTime.UtcNow, - StripePortalCustomerId = stripePortalCustomerId, - UserId = userId, - }; - } - } -} diff --git a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs b/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs deleted file mode 100644 index e87233d3..00000000 --- a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Modules.Subscription.Features.Infrastructure.Configuration; -using Modules.Subscription.Features.Infrastructure.EFCore; -using Modules.Subscription.IntegrationEvents; -using Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate; -using Shared.DomainFeatures.CQRS.Command; -using Shared.Features.CQRS.Command; -using Shared.Features.CQRS.IntegrationEvent; -using Shared.Kernel.BuildingBlocks.Auth; -using Stripe; -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate.Application.Commands -{ - public class CreateTrialingSubscription : ICommand - { - public Guid UserId { get; set; } - public string StripeCustomerId { get; set; } - public Stripe.Subscription Subscription { get; set; } - } - - public class CreateTrialingSubscriptionCommandHandler : ICommandHandler - { - private readonly SubscriptionsDbContext subscriptionDbContext; - private readonly SubscriptionsConfiguration subscriptionConfiguration; - private readonly IIntegrationEventDispatcher integrationEventDispatcher; - - public CreateTrialingSubscriptionCommandHandler( - SubscriptionsDbContext subscriptionDbContext, - SubscriptionsConfiguration subscriptionConfiguration, - IIntegrationEventDispatcher integrationEventDispatcher) - { - this.subscriptionDbContext = subscriptionDbContext; - this.subscriptionConfiguration = subscriptionConfiguration; - this.integrationEventDispatcher = integrationEventDispatcher; - } - - public async Task HandleAsync(CreateTrialingSubscription command, CancellationToken cancellationToken) - { - var subscriptionType = subscriptionConfiguration.Subscriptions.First(s => s.StripePriceId == command.Subscription.Items.First().Price.Id).Type; - - var customer = await new CustomerService().GetAsync(command.Subscription.CustomerId); - var stripeCustomer = await subscriptionDbContext.StripeCustomers.FirstAsync(sc => sc.StripePortalCustomerId == customer.Id); - - var stripeSubscription = StripeSubscription.Create(command.Subscription.TrialEnd, subscriptionType, StripeSubscriptionStatus.Trialing, stripeCustomer); - - subscriptionDbContext.StripeSubscriptions.Add(stripeSubscription); - - await subscriptionDbContext.SaveChangesAsync(); - - var userSubscriptionUpdatedEvent = new UserSubscriptionPlanUpdatedIntegrationEvent - { - SubscriptionPlanType = subscriptionType, - UserId = command.UserId - }; - - await integrationEventDispatcher.RaiseAndWaitForCompletionAsync(userSubscriptionUpdatedEvent, cancellationToken); - } - } -} diff --git a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateActiveSubscription.cs b/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateActiveSubscription.cs deleted file mode 100644 index deb3f14c..00000000 --- a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateActiveSubscription.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Modules.Subscription.Features.Infrastructure.EFCore; -using Shared.Features.CQRS.Command; -using System.Threading; -using System.Threading.Tasks; - -namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate.Application.Commands -{ - public class UpdateActiveSubscription : ICommand - { - public string StripeCustomerId { get; set; } - public Stripe.Subscription Subscription { get; set; } - } - - public class UpdateSubscriptionCommandHandler : ICommandHandler - { - private readonly SubscriptionsDbContext subscriptionDbContext; - - public UpdateSubscriptionCommandHandler(SubscriptionsDbContext subscriptionDbContext) - { - this.subscriptionDbContext = subscriptionDbContext; - } - - public async Task HandleAsync(UpdateActiveSubscription command, CancellationToken cancellationToken) - { - - } - } -} diff --git a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs b/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs deleted file mode 100644 index 1ce1a62d..00000000 --- a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Modules.Subscriptions.Features.Aggregates.StripeCustomerAggregate; -using Shared.Features.DomainKernel; -using Shared.Kernel.BuildingBlocks.Auth; -using System; - -namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate -{ - public class StripeSubscription : Entity - { - private StripeSubscription() { } - public static StripeSubscription Create( - DateTime? expirationDate, - SubscriptionPlanType subscriptionPlanType, - StripeSubscriptionStatus stripeSubscriptionStatus, - StripeCustomer stripeCustomer) - { - return new StripeSubscription() - { - ExpirationDate = expirationDate, - PlanType = subscriptionPlanType, - Status = stripeSubscriptionStatus, - StripeCustomer = stripeCustomer - }; - } - - public Guid StripeCustomerId { get; set; } - public StripeCustomer StripeCustomer { get; set; } - public DateTime? ExpirationDate { get; set; } - public SubscriptionPlanType PlanType { get; set; } - public StripeSubscriptionStatus Status { get; set; } - } -} diff --git a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscriptionStatus.cs b/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscriptionStatus.cs deleted file mode 100644 index f264a913..00000000 --- a/Source/Modules/Subscription/DomainFeatures/Aggregates/StripeSubscriptionAggregate/StripeSubscriptionStatus.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate -{ - public enum StripeSubscriptionStatus - { - Active, - Canceled, - Trialing, - TrialEnded, - Unpaid - } -}