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. 13
      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. 9
      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<IChangePlanResult> ChangePlanAsync(string userId, Guid appId, string appName, string planId);
Task<bool> HasPaymentOptionsAsync(string userId);
Task<string> GetPortalLinkAsync(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;
using System.Threading.Tasks; using System.Threading.Tasks;
using Squidex.Infrastructure.Tasks;
namespace Squidex.Domain.Apps.Read.Apps.Services.Implementations 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); return Task.FromResult<IChangePlanResult>(PlanChangedResult.Instance);
} }
public Task<bool> HasPaymentOptionsAsync(string userId)
{
return TaskHelper.True;
}
public Task<string> GetPortalLinkAsync(string userId) public Task<string> GetPortalLinkAsync(string userId)
{ {
return Task.FromResult(string.Empty); return Task.FromResult(string.Empty);

13
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.Domain.Apps.Write.Apps.Commands;
using Squidex.Infrastructure.CQRS.Commands; using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.Security;
using Squidex.Pipeline; using Squidex.Pipeline;
// ReSharper disable RedundantIfElseBlock // ReSharper disable RedundantIfElseBlock
@ -54,22 +53,16 @@ namespace Squidex.Controllers.Api.Plans
[Route("apps/{app}/plans/")] [Route("apps/{app}/plans/")]
[ProducesResponseType(typeof(AppPlansDto), 200)] [ProducesResponseType(typeof(AppPlansDto), 200)]
[ApiCosts(0.5)] [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 planId = appPlansProvider.GetPlanForApp(App).Id;
var hasPortal = appPlansBillingManager.HasPortal;
var hasConfigured = await appPlansBillingManager.HasPaymentOptionsAsync(userId);
var response = new AppPlansDto var response = new AppPlansDto
{ {
CurrentPlanId = planId,
Plans = appPlansProvider.GetAvailablePlans().Select(x => SimpleMapper.Map(x, new PlanDto())).ToList(), Plans = appPlansProvider.GetAvailablePlans().Select(x => SimpleMapper.Map(x, new PlanDto())).ToList(),
PlanOwner = App.PlanOwner, PlanOwner = App.PlanOwner,
HasPortal = hasPortal, HasPortal = appPlansBillingManager.HasPortal
HasConfigured = hasConfigured,
CurrentPlanId = planId
}; };
Response.Headers["ETag"] = new StringValues(App.Version.ToString()); 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. /// Indicates if there is a billing portal.
/// </summary> /// </summary>
public bool HasPortal { get; set; } 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', devtool: 'cheap-module-source-map',
//debug: true,
output: { output: {
filename: '[name].js', filename: '[name].js',
// Set the public path, because we are running the website from another port (5000) // Set the public path, because we are running the website from another port (5000)

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

@ -22,14 +22,9 @@
<div class="panel-main"> <div class="panel-main">
<div class="panel-content"> <div class="panel-content">
<div *ngIf="plans"> <div *ngIf="plans">
<div class="panel-alert panel-alert-danger" *ngIf="!plans.hasConfigured || !planOwned"> <div class="panel-alert panel-alert-danger" *ngIf="!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. You have not created the subscription. Therefore you cannot change the plan.
</div> </div>
</div>
<div class="text-muted text-center empty" *ngIf="plans.plans.length === 0"> <div class="text-muted text-center empty" *ngIf="plans.plans.length === 0">
No plan configured, this app has unlimited usage. No plan configured, this app has unlimited usage.
@ -59,7 +54,7 @@
&#10003; Selected &#10003; Selected
</button> </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 Change
</button> </button>
</div> </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, new AppPlansDto(planId,
this.plans.planOwner, this.plans.planOwner,
this.plans.hasPortal, this.plans.hasPortal,
this.plans.hasConfigured,
this.plans.plans); this.plans.plans);
this.isDisabled = false; this.isDisabled = false;
} }

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

@ -53,7 +53,6 @@ describe('PlansService', () => {
req.flush({ req.flush({
currentPlanId: '123', currentPlanId: '123',
hasConfigured: true,
hasPortal: true, hasPortal: true,
planOwner: '456', planOwner: '456',
plans: [ plans: [
@ -81,7 +80,6 @@ describe('PlansService', () => {
'123', '123',
'456', '456',
true, true,
true,
[ [
new PlanDto('free', 'Free', '14 €', 1000, 1500, 2500), new PlanDto('free', 'Free', '14 €', 1000, 1500, 2500),
new PlanDto('prof', 'Prof', '18 €', 4000, 5500, 6500) 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 currentPlanId: string,
public readonly planOwner: string, public readonly planOwner: string,
public readonly hasPortal: boolean, public readonly hasPortal: boolean,
public readonly hasConfigured: boolean,
public readonly plans: PlanDto[] public readonly plans: PlanDto[]
) { ) {
} }
@ -73,7 +72,6 @@ export class PlansService {
response.currentPlanId, response.currentPlanId,
response.planOwner, response.planOwner,
response.hasPortal, response.hasPortal,
response.hasConfigured,
items.map(item => { items.map(item => {
return new PlanDto( return new PlanDto(
item.id, 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); 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] [Fact]
public async Task Should_not_return_portal_link() public async Task Should_not_return_portal_link()
{ {

Loading…
Cancel
Save