diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/ChangePlan.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/ChangePlan.cs index 9d3424211..28351c602 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/ChangePlan.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/ChangePlan.cs @@ -12,7 +12,5 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands public bool FromCallback { get; set; } public string PlanId { get; set; } - - public string Referer { get; set; } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs index 7294e3786..f1dc9a1c4 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs @@ -258,7 +258,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject case DeleteApp delete: return UpdateAsync(delete, async (c, ct) => { - await Billing().SubscribeAsync(c.Actor.Identifier, Snapshot.NamedId(), null, null, ct); + await Billing().UnsubscribeAsync(c.Actor.Identifier, Snapshot.NamedId(), default); DeleteApp(c); }, ct); @@ -290,7 +290,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject if (!c.FromCallback) { - var redirectUri = await Billing().MustRedirectToPortalAsync(userId, Snapshot.NamedId(), c.PlanId, c.Referer, default); + var redirectUri = await Billing().MustRedirectToPortalAsync(userId, Snapshot.NamedId(), c.PlanId, default); if (redirectUri != null) { @@ -310,11 +310,11 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject if (result.Payload is PlanChangedResult { Unsubscribed: true, RedirectUri: null }) { - await Billing().UnsubscribeAsync(userId, Snapshot.NamedId(), changePlan.Referer, default); + await Billing().UnsubscribeAsync(userId, Snapshot.NamedId(), default); } else if (result.Payload is PlanChangedResult { RedirectUri: null }) { - await Billing().SubscribeAsync(userId, Snapshot.NamedId(), changePlan.PlanId, changePlan.Referer); + await Billing().SubscribeAsync(userId, Snapshot.NamedId(), changePlan.PlanId, default); } return result; diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/IAppPlanBillingManager.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/IAppPlanBillingManager.cs index 306ec6de8..963f935a5 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/IAppPlanBillingManager.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/IAppPlanBillingManager.cs @@ -13,13 +13,13 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans { bool HasPortal { get; } - Task MustRedirectToPortalAsync(string userId, NamedId appId, string? planId, string? referer, + Task MustRedirectToPortalAsync(string userId, NamedId appId, string? planId, CancellationToken ct = default); - Task SubscribeAsync(string userId, NamedId appId, string? planId, string? referer, + Task SubscribeAsync(string userId, NamedId appId, string planId, CancellationToken ct = default); - Task UnsubscribeAsync(string userId, NamedId appId, string? referer, + Task UnsubscribeAsync(string userId, NamedId appId, CancellationToken ct = default); Task GetPortalLinkAsync(string userId, diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/NoopAppPlanBillingManager.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/NoopAppPlanBillingManager.cs index 8063166fb..2a3d22307 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/NoopAppPlanBillingManager.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/NoopAppPlanBillingManager.cs @@ -22,19 +22,19 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans return Task.FromResult(string.Empty); } - public Task MustRedirectToPortalAsync(string userId, NamedId appId, string? planId, string? referer, + public Task MustRedirectToPortalAsync(string userId, NamedId appId, string? planId, CancellationToken ct = default) { return Task.FromResult(null); } - public Task SubscribeAsync(string userId, NamedId appId, string? planId, string? referer, + public Task SubscribeAsync(string userId, NamedId appId, string planId, CancellationToken ct = default) { return Task.CompletedTask; } - public Task UnsubscribeAsync(string userId, NamedId appId, string? referer, + public Task UnsubscribeAsync(string userId, NamedId appId, CancellationToken ct = default) { return Task.CompletedTask; diff --git a/backend/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs b/backend/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs index 4c53faab4..663c0380f 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs @@ -77,7 +77,7 @@ namespace Squidex.Areas.Api.Controllers.Plans [ApiCosts(0)] public async Task PutPlan(string app, [FromBody] ChangePlanDto request) { - var context = await CommandBus.PublishAsync(request.ToCommand(HttpContext), HttpContext.RequestAborted); + var context = await CommandBus.PublishAsync(request.ToCommand(), HttpContext.RequestAborted); string? redirectUri = null; diff --git a/backend/src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs b/backend/src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs index 66230b9a0..d0138b65e 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs @@ -19,12 +19,10 @@ namespace Squidex.Areas.Api.Controllers.Plans.Models [LocalizedRequired] public string PlanId { get; set; } - public ChangePlan ToCommand(HttpContext httpContext) + public ChangePlan ToCommand() { var result = SimpleMapper.Map(this, new ChangePlan()); - result.Referer = httpContext.Request.Headers["Referer"]; - return result; } } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DomainObject/AppDomainObjectTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DomainObject/AppDomainObjectTests.cs index 37bcbbcb0..dccd42af9 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DomainObject/AppDomainObjectTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DomainObject/AppDomainObjectTests.cs @@ -59,7 +59,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject A.CallTo(() => appPlansProvider.GetPlan(planIdPaid)) .Returns(new ConfigAppLimitsPlan { Id = planIdPaid, MaxContributors = 30 }); - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, A._, A._, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, A._, default)) .Returns(Task.FromResult(null)); // Create a non-empty setting, otherwise the event is not raised as it does not change the domain object. @@ -220,7 +220,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject { var command = new ChangePlan { PlanId = planIdPaid }; - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default)) .Returns(Task.FromResult(null)); await ExecuteCreateAsync(); @@ -236,10 +236,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject CreateEvent(new AppPlanChanged { PlanId = planIdPaid }) ); - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default)) .MustHaveHappened(); - A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default)) + A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, default)) .MustHaveHappened(); } @@ -261,10 +261,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject CreateEvent(new AppPlanChanged { PlanId = planIdPaid }) ); - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A._, A>._, A._, A._, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A._, A>._, A._, A._)) .MustNotHaveHappened(); - A.CallTo(() => appPlansBillingManager.SubscribeAsync(A._, A>._, A._, A._, A._)) + A.CallTo(() => appPlansBillingManager.SubscribeAsync(A._, A>._, A._, A._)) .MustNotHaveHappened(); } @@ -287,10 +287,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject CreateEvent(new AppPlanReset()) ); - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A._, A>._, A._, A._, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A._, A>._, A._, A._)) .MustHaveHappenedOnceExactly(); - A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A._, A>._, A._, A._)) + A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A._, A>._, A._)) .MustNotHaveHappened(); } @@ -313,10 +313,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject CreateEvent(new AppPlanReset()) ); - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default)) .MustHaveHappenedOnceExactly(); - A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A._, A>._, A._, A._)) + A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A._, A>._, A._)) .MustHaveHappened(); } @@ -325,7 +325,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject { var command = new ChangePlan { PlanId = planIdPaid }; - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default)) .Returns(new Uri("http://squidex.io")); await ExecuteCreateAsync(); @@ -350,10 +350,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject Assert.Equal(planIdPaid, sut.Snapshot.Plan?.PlanId); - A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default)) + A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, A._)) .MustNotHaveHappened(); - A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, A._, default)) + A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, A._)) .MustNotHaveHappened(); } @@ -668,7 +668,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject CreateEvent(new AppDeleted()) ); - A.CallTo(() => appPlansBillingManager.SubscribeAsync(command.Actor.Identifier, AppNamedId, null, A._, default)) + A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(command.Actor.Identifier, AppNamedId, default)) .MustHaveHappened(); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/NoopAppPlanBillingManagerTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/NoopAppPlanBillingManagerTests.cs index a8f9cacf9..6601b4218 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/NoopAppPlanBillingManagerTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/NoopAppPlanBillingManagerTests.cs @@ -22,13 +22,13 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans [Fact] public async Task Should_do_nothing_if_subscribing() { - await sut.SubscribeAsync(null!, null!, null, null); + await sut.SubscribeAsync(null!, null!, null!); } [Fact] public async Task Should_do_nothing_if_unsubscribing() { - await sut.SubscribeAsync(null!, null!, null, null); + await sut.UnsubscribeAsync(null!, null!); } [Fact] @@ -42,7 +42,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans [Fact] public async Task Should_do_nothing_if_checking_for_redirect() { - var result = await sut.MustRedirectToPortalAsync(null!, null!, null, null); + var result = await sut.MustRedirectToPortalAsync(null!, null!, null); Assert.Null(result); }