Browse Source

Billing manager simplified.

pull/95/head
Sebastian Stehle 9 years ago
parent
commit
81825272cf
  1. 2
      src/Squidex.Domain.Apps.Read/Apps/Services/IAppPlanBillingManager.cs
  2. 6
      src/Squidex.Domain.Apps.Read/Apps/Services/Implementations/NoopAppPlanBillingManager.cs
  3. 15
      src/Squidex/Controllers/Api/Plans/AppPlansController.cs
  4. 5
      src/Squidex/Controllers/Api/Plans/Models/AppPlansDto.cs
  5. 2
      src/Squidex/app-config/webpack.run.dev.js
  6. 11
      src/Squidex/app/features/settings/pages/plans/plans-page.component.html
  7. 1
      src/Squidex/app/features/settings/pages/plans/plans-page.component.ts
  8. 2
      src/Squidex/app/shared/services/plans.service.spec.ts
  9. 2
      src/Squidex/app/shared/services/plans.service.ts
  10. 6
      tests/Squidex.Domain.Apps.Read.Tests/Apps/NoopAppPlanBillingManagerTests.cs

2
src/Squidex.Domain.Apps.Read/Apps/Services/IAppPlanBillingManager.cs

@ -17,8 +17,6 @@ namespace Squidex.Domain.Apps.Read.Apps.Services
Task<IChangePlanResult> ChangePlanAsync(string userId, Guid appId, string appName, string planId);
Task<bool> HasPaymentOptionsAsync(string userId);
Task<string> GetPortalLinkAsync(string userId);
}
}

6
src/Squidex.Domain.Apps.Read/Apps/Services/Implementations/NoopAppPlanBillingManager.cs

@ -8,7 +8,6 @@
using System;
using System.Threading.Tasks;
using Squidex.Infrastructure.Tasks;
namespace Squidex.Domain.Apps.Read.Apps.Services.Implementations
{
@ -24,11 +23,6 @@ namespace Squidex.Domain.Apps.Read.Apps.Services.Implementations
return Task.FromResult<IChangePlanResult>(PlanChangedResult.Instance);
}
public Task<bool> HasPaymentOptionsAsync(string userId)
{
return TaskHelper.True;
}
public Task<string> GetPortalLinkAsync(string userId)
{
return Task.FromResult(string.Empty);

15
src/Squidex/Controllers/Api/Plans/AppPlansController.cs

@ -16,7 +16,6 @@ using Squidex.Domain.Apps.Read.Apps.Services;
using Squidex.Domain.Apps.Write.Apps.Commands;
using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.Security;
using Squidex.Pipeline;
// ReSharper disable RedundantIfElseBlock
@ -54,22 +53,16 @@ namespace Squidex.Controllers.Api.Plans
[Route("apps/{app}/plans/")]
[ProducesResponseType(typeof(AppPlansDto), 200)]
[ApiCosts(0.5)]
public async Task<IActionResult> GetPlans(string app)
public IActionResult GetPlans(string app)
{
var userId = User.FindFirst(OpenIdClaims.Subject).Value;
var planId = appPlansProvider.GetPlanForApp(App).Id;
var hasPortal = appPlansBillingManager.HasPortal;
var hasConfigured = await appPlansBillingManager.HasPaymentOptionsAsync(userId);
var response = new AppPlansDto
{
CurrentPlanId = planId,
Plans = appPlansProvider.GetAvailablePlans().Select(x => SimpleMapper.Map(x, new PlanDto())).ToList(),
PlanOwner = App.PlanOwner,
HasPortal = hasPortal,
HasConfigured = hasConfigured,
CurrentPlanId = planId
HasPortal = appPlansBillingManager.HasPortal
};
Response.Headers["ETag"] = new StringValues(App.Version.ToString());

5
src/Squidex/Controllers/Api/Plans/Models/AppPlansDto.cs

@ -31,10 +31,5 @@ namespace Squidex.Controllers.Api.Plans.Models
/// Indicates if there is a billing portal.
/// </summary>
public bool HasPortal { get; set; }
/// <summary>
/// Indicates if the user has payment options entered so that the plan can be changed.
/// </summary>
public bool HasConfigured { get; set; }
}
}

2
src/Squidex/app-config/webpack.run.dev.js

@ -15,8 +15,6 @@ module.exports = webpackMerge(runConfig, {
*/
devtool: 'cheap-module-source-map',
//debug: true,
output: {
filename: '[name].js',
// Set the public path, because we are running the website from another port (5000)

11
src/Squidex/app/features/settings/pages/plans/plans-page.component.html

@ -22,13 +22,8 @@
<div class="panel-main">
<div class="panel-content">
<div *ngIf="plans">
<div class="panel-alert panel-alert-danger" *ngIf="!plans.hasConfigured || !planOwned">
<div *ngIf="!plans.hasConfigured">
You have not configured your account yet. Go to <a target="_blank" href="{{portalUrl}}">Billing Portal</a> to add payment options.
</div>
<div *ngIf="!planOwned">
You have not created the subscription. Therefore you cannot change the plan.
</div>
<div class="panel-alert panel-alert-danger" *ngIf="!planOwned">
You have not created the subscription. Therefore you cannot change the plan.
</div>
<div class="text-muted text-center empty" *ngIf="plans.plans.length === 0">
@ -59,7 +54,7 @@
&#10003; Selected
</button>
<button *ngIf="plan.id !== plans.currentPlanId" class="btn btn-block btn-success" [disabled]="isDisabled || !plans.hasConfigured || !planOwned" (click)="changePlan(plan.id)">
<button *ngIf="plan.id !== plans.currentPlanId" class="btn btn-block btn-success" [disabled]="isDisabled || !planOwned" (click)="changePlan(plan.id)">
Change
</button>
</div>

1
src/Squidex/app/features/settings/pages/plans/plans-page.component.ts

@ -74,7 +74,6 @@ export class PlansPageComponent extends AppComponentBase implements OnInit {
new AppPlansDto(planId,
this.plans.planOwner,
this.plans.hasPortal,
this.plans.hasConfigured,
this.plans.plans);
this.isDisabled = false;
}

2
src/Squidex/app/shared/services/plans.service.spec.ts

@ -53,7 +53,6 @@ describe('PlansService', () => {
req.flush({
currentPlanId: '123',
hasConfigured: true,
hasPortal: true,
planOwner: '456',
plans: [
@ -81,7 +80,6 @@ describe('PlansService', () => {
'123',
'456',
true,
true,
[
new PlanDto('free', 'Free', '14 €', 1000, 1500, 2500),
new PlanDto('prof', 'Prof', '18 €', 4000, 5500, 6500)

2
src/Squidex/app/shared/services/plans.service.ts

@ -22,7 +22,6 @@ export class AppPlansDto {
public readonly currentPlanId: string,
public readonly planOwner: string,
public readonly hasPortal: boolean,
public readonly hasConfigured: boolean,
public readonly plans: PlanDto[]
) {
}
@ -73,7 +72,6 @@ export class PlansService {
response.currentPlanId,
response.planOwner,
response.hasPortal,
response.hasConfigured,
items.map(item => {
return new PlanDto(
item.id,

6
tests/Squidex.Domain.Apps.Read.Tests/Apps/NoopAppPlanBillingManagerTests.cs

@ -29,12 +29,6 @@ namespace Squidex.Domain.Apps.Read.Apps
await sut.ChangePlanAsync(null, Guid.Empty, null, null);
}
[Fact]
public async Task Should_return_true_for_payment_option_check()
{
Assert.True(await sut.HasPaymentOptionsAsync(null));
}
[Fact]
public async Task Should_not_return_portal_link()
{

Loading…
Cancel
Save