diff --git a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateSubscriptionForTenant.cs b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateSubscriptionForTenant.cs deleted file mode 100644 index e6397505..00000000 --- a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateSubscriptionForTenant.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Shared.Features.CQRS.Command; - -namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate.Application.Commands -{ - public class CreateSubscriptionForTenant : ICommand - { - public Guid TenantId { get; set; } - public Stripe.Subscription Subscription { get; set; } - } -} diff --git a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscriptionForTenant.cs similarity index 76% rename from Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs rename to Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscriptionForTenant.cs index 7f6396df..46c6adb4 100644 --- a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscription.cs +++ b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/CreateTrialingSubscriptionForTenant.cs @@ -9,14 +9,15 @@ namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate.Application.Commands { - public class CreateTrialingSubscription : ICommand + public class CreateTrialingSubscriptionForTenant : ICommand { public Guid UserId { get; set; } + public Guid TenantId { get; set; } public string StripeCustomerId { get; set; } - public Stripe.Subscription Subscription { get; set; } + public Stripe.Subscription CreatedStripeSubscription { get; set; } } - public class CreateTrialingSubscriptionCommandHandler : ICommandHandler + public class CreateTrialingSubscriptionCommandHandler : ICommandHandler { private readonly SubscriptionsDbContext subscriptionDbContext; private readonly SubscriptionsConfiguration subscriptionConfiguration; @@ -32,14 +33,16 @@ public CreateTrialingSubscriptionCommandHandler( this.integrationEventDispatcher = integrationEventDispatcher; } - public async Task HandleAsync(CreateTrialingSubscription command, CancellationToken cancellationToken) + public async Task HandleAsync(CreateTrialingSubscriptionForTenant command, CancellationToken cancellationToken) { - var subscriptionType = subscriptionConfiguration.Subscriptions.First(s => s.StripePriceId == command.Subscription.Items.First().Price.Id).Type; + var subscriptionType = subscriptionConfiguration.Subscriptions.First(s => s.StripePriceId == command.CreatedStripeSubscription.Items.First().Price.Id).Type; - var customer = await new CustomerService().GetAsync(command.Subscription.CustomerId); + var customer = await new CustomerService().GetAsync(command.CreatedStripeSubscription.CustomerId); var stripeCustomer = await subscriptionDbContext.StripeCustomers.FirstAsync(sc => sc.StripePortalCustomerId == customer.Id); - var stripeSubscription = StripeSubscription.Create(command.Subscription.TrialEnd, subscriptionType, StripeSubscriptionStatus.Trialing, stripeCustomer); + var tenantId = new Guid(command.CreatedStripeSubscription.Metadata["TenantId"]); + + var stripeSubscription = StripeSubscription.Create(command.CreatedStripeSubscription.TrialEnd, subscriptionType, StripeSubscriptionStatus.Trialing, tenantId, stripeCustomer); subscriptionDbContext.StripeSubscriptions.Add(stripeSubscription); @@ -47,7 +50,7 @@ public async Task HandleAsync(CreateTrialingSubscription command, CancellationTo var userSubscriptionUpdatedEvent = new TenantSubscriptionPlanUpdatedIntegrationEvent { - TenantId = new Guid(command.Subscription.Metadata["TenantId"]), + TenantId = tenantId, SubscriptionPlanType = subscriptionType }; diff --git a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionEndDate.cs b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionEndDate.cs deleted file mode 100644 index 4d16f267..00000000 --- a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionEndDate.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Shared.Features.CQRS.Command; - -namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate.Application.Commands -{ - public class UpdateSubscriptionEndDate : ICommand - { - public Stripe.Subscription Subscription { get; set; } - } -} diff --git a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriodEnd.cs b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriodEnd.cs new file mode 100644 index 00000000..f4d5422a --- /dev/null +++ b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/Application/Commands/UpdateSubscriptionPeriodEnd.cs @@ -0,0 +1,17 @@ +using Shared.Features.CQRS.Command; + +namespace Modules.Subscriptions.Features.Aggregates.StripeSubscriptionAggregate.Application.Commands +{ + public class UpdateSubscriptionPeriodEnd : ICommand + { + public Stripe.Subscription Subscription { get; set; } + } + + public class UpdateSubscriptionPerioEndCommandHandler : ICommandHandler + { + public Task HandleAsync(UpdateSubscriptionPeriodEnd command, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + } +} diff --git a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs index 3427ea94..07c6d6b3 100644 --- a/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs +++ b/Source/Modules/Subscriptions/Features/Aggregates/StripeSubscriptionAggregate/StripeSubscription.cs @@ -11,6 +11,7 @@ public static StripeSubscription Create( DateTime? expirationDate, SubscriptionPlanType subscriptionPlanType, StripeSubscriptionStatus stripeSubscriptionStatus, + Guid tenantId, StripeCustomer stripeCustomer) { return new StripeSubscription() @@ -18,6 +19,7 @@ public static StripeSubscription Create( ExpirationDate = expirationDate, PlanType = subscriptionPlanType, Status = stripeSubscriptionStatus, + TenantId = tenantId, StripeCustomer = stripeCustomer }; } diff --git a/Source/Modules/Subscriptions/Features/Infrastructure/EFCore/Migrations/20240218050150_initial.cs b/Source/Modules/Subscriptions/Features/Infrastructure/EFCore/Migrations/20240218050150_initial.cs index 77d45d5b..6b85dbea 100644 --- a/Source/Modules/Subscriptions/Features/Infrastructure/EFCore/Migrations/20240218050150_initial.cs +++ b/Source/Modules/Subscriptions/Features/Infrastructure/EFCore/Migrations/20240218050150_initial.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs b/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs index 52544169..daf95a6e 100644 --- a/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs +++ b/Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs @@ -39,11 +39,11 @@ public async Task Index() var subscription = await new SubscriptionService().GetAsync(session.SubscriptionId); var userId = subscription.Metadata["UserId"]; - var createTrialingSubscription = new CreateTrialingSubscription + var createTrialingSubscription = new CreateTrialingSubscriptionForTenant { UserId = Guid.Parse(userId), StripeCustomerId = subscription.CustomerId, - Subscription = subscription + CreatedStripeSubscription = subscription }; await commandDispatcher.DispatchAsync(createTrialingSubscription); @@ -55,7 +55,7 @@ public async Task Index() var subscription = await new SubscriptionService().GetAsync(invoice.SubscriptionId); - + } // Sent each billing interval if there is an issue with your customer’s payment method. (Stripe) else if (stripeEvent.Type == Events.InvoicePaymentFailed) diff --git a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs index 8b86ef6d..6cde7ddc 100644 --- a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs +++ b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Application/Commands/UpdateUserRoleInTenant.cs @@ -22,7 +22,7 @@ public async Task HandleAsync(UpdateTenantMembership command, CancellationToken { var tenant = await tenantIdentityDbContext.GetTenantExtendedByIdAsync(command.TenantId); - tenant.ChangeRoleOfUser(command.UserId, command.Role); + tenant.ChangeRoleOfTenantMember(command.UserId, command.Role); await tenantIdentityDbContext.SaveChangesAsync(); } diff --git a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/Tenant.cs b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/Tenant.cs index df64141f..be1e522d 100644 --- a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/Tenant.cs +++ b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/Tenant.cs @@ -3,7 +3,6 @@ using Shared.Features.Domain; using Shared.Features.Domain.Exceptions; using Shared.Kernel.BuildingBlocks.Auth; -using StackExchange.Redis; namespace Modules.TenantIdentity.Features.Aggregates.TenantAggregate.Domain { @@ -50,7 +49,7 @@ public void AddUser(Guid userId, TenantRole role) } } - public void ChangeRoleOfMember(Guid userId, TenantRole newRole) + public void ChangeRoleOfTenantMember(Guid userId, TenantRole newRole) { ThrowIfCallerIsNotInRole(TenantRole.Admin); diff --git a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantInvitation.cs b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantInvitation.cs index 056bfa50..97fafc63 100644 --- a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantInvitation.cs +++ b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantInvitation.cs @@ -1,5 +1,4 @@ -using Modules.TenantIdentity.Features.Aggregates.UserAggregate; -using Shared.Features.Domain; +using Shared.Features.Domain; using Shared.Kernel.BuildingBlocks.Auth; namespace Modules.TenantIdentity.Features.Aggregates.TenantAggregate.Domain diff --git a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantMembership.cs b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantMembership.cs index 9019a073..8ee86896 100644 --- a/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantMembership.cs +++ b/Source/Modules/TenantIdentity/Features/Aggregates/TenantAggregate/Domain/TenantMembership.cs @@ -12,13 +12,20 @@ public TenantMembership(Guid userId, TenantRole role) UserId = userId; Role = role; } + public Guid UserId { get; set; } + public Guid TenantId { get; set; } public Tenant Tenant { get; set; } public TenantRole Role { get; set; } public TenantMembershipDTO ToDTO() { - return new TenantMembershipDTO(); + return new TenantMembershipDTO() + { + UserId = UserId, + TenantId = Tenant.Id, + Role = Role + }; } } } diff --git a/Source/Modules/TenantIdentity/Features/Aggregates/UserAggregate/Infrastructure/ApplicationUserEFConfiguration.cs b/Source/Modules/TenantIdentity/Features/Aggregates/UserAggregate/Infrastructure/ApplicationUserEFConfiguration.cs index 8670b72d..18e360bc 100644 --- a/Source/Modules/TenantIdentity/Features/Aggregates/UserAggregate/Infrastructure/ApplicationUserEFConfiguration.cs +++ b/Source/Modules/TenantIdentity/Features/Aggregates/UserAggregate/Infrastructure/ApplicationUserEFConfiguration.cs @@ -1,6 +1,5 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Modules.TenantIdentity.Features.Aggregates.UserAggregate; namespace Modules.TenantIdentity.Features.Aggregates.UserAggregate.Infrastructure { diff --git a/Source/Shared/Kernel/BuildingBlocks/Auth/Attributes/AuthorizationAttribute.cs b/Source/Shared/Kernel/BuildingBlocks/Auth/Attributes/AuthorizationAttribute.cs index c77a4402..8391de4c 100644 --- a/Source/Shared/Kernel/BuildingBlocks/Auth/Attributes/AuthorizationAttribute.cs +++ b/Source/Shared/Kernel/BuildingBlocks/Auth/Attributes/AuthorizationAttribute.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Shared.Kernel.BuildingBlocks.Auth.Attributes +namespace Shared.Kernel.BuildingBlocks.Auth.Attributes { public class AuthorizationAttribute : Attribute { diff --git a/Source/Web/Server/Startup.cs b/Source/Web/Server/Startup.cs index 7ca49d22..ba9f74a4 100644 --- a/Source/Web/Server/Startup.cs +++ b/Source/Web/Server/Startup.cs @@ -6,8 +6,6 @@ using Modules.LandingPages.Web.Server; using Web.Server.BuildingBlocks; using Shared.Kernel.BuildingBlocks.Auth; -using Microsoft.AspNetCore.Mvc; -using System; using Modules.TenantIdentity.Server; using Shared.Features.Modules; using Shared.Features;