mirror of
https://github.com/bitwarden/server.git
synced 2025-04-21 13:05:11 -05:00
prorate fix
This commit is contained in:
parent
ef945cc7c4
commit
35a31a4496
@ -1,10 +1,20 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Bit.Core.Models.Api
|
namespace Bit.Core.Models.Api
|
||||||
{
|
{
|
||||||
public class OrganizationSeatRequestModel
|
public class OrganizationSeatRequestModel : IValidatableObject
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public int? SeatAdjustment { get; set; }
|
public int? SeatAdjustment { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
if(SeatAdjustment == 0)
|
||||||
|
{
|
||||||
|
yield return new ValidationResult("Seat adjustment cannot be 0.", new string[] { nameof(SeatAdjustment) });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,6 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var invoiceService = new StripeInvoiceService();
|
|
||||||
var subscriptionItemService = new StripeSubscriptionItemService();
|
var subscriptionItemService = new StripeSubscriptionItemService();
|
||||||
var subscriptionService = new StripeSubscriptionService();
|
var subscriptionService = new StripeSubscriptionService();
|
||||||
var sub = await subscriptionService.GetAsync(organization.StripeSubscriptionId);
|
var sub = await subscriptionService.GetAsync(organization.StripeSubscriptionId);
|
||||||
@ -421,7 +420,7 @@ namespace Bit.Core.Services
|
|||||||
SubscriptionId = sub.Id
|
SubscriptionId = sub.Id
|
||||||
});
|
});
|
||||||
|
|
||||||
await PreviewUpcomingAndPayAsync(invoiceService, organization, plan);
|
await PreviewUpcomingAndPayAsync(organization, plan);
|
||||||
}
|
}
|
||||||
else if(additionalSeats > 0)
|
else if(additionalSeats > 0)
|
||||||
{
|
{
|
||||||
@ -432,7 +431,7 @@ namespace Bit.Core.Services
|
|||||||
Prorate = true
|
Prorate = true
|
||||||
});
|
});
|
||||||
|
|
||||||
await PreviewUpcomingAndPayAsync(invoiceService, organization, plan);
|
await PreviewUpcomingAndPayAsync(organization, plan);
|
||||||
}
|
}
|
||||||
else if(additionalSeats == 0)
|
else if(additionalSeats == 0)
|
||||||
{
|
{
|
||||||
@ -443,8 +442,9 @@ namespace Bit.Core.Services
|
|||||||
await _organizationRepository.ReplaceAsync(organization);
|
await _organizationRepository.ReplaceAsync(organization);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PreviewUpcomingAndPayAsync(StripeInvoiceService invoiceService, Organization org, Plan plan)
|
private async Task PreviewUpcomingAndPayAsync(Organization org, Plan plan)
|
||||||
{
|
{
|
||||||
|
var invoiceService = new StripeInvoiceService();
|
||||||
var upcomingPreview = await invoiceService.UpcomingAsync(org.StripeCustomerId,
|
var upcomingPreview = await invoiceService.UpcomingAsync(org.StripeCustomerId,
|
||||||
new StripeUpcomingInvoiceOptions
|
new StripeUpcomingInvoiceOptions
|
||||||
{
|
{
|
||||||
@ -452,8 +452,10 @@ namespace Bit.Core.Services
|
|||||||
});
|
});
|
||||||
|
|
||||||
var prorationAmount = upcomingPreview.StripeInvoiceLineItems?.Data?
|
var prorationAmount = upcomingPreview.StripeInvoiceLineItems?.Data?
|
||||||
.TakeWhile(i => i.Plan.Id == plan.StripeSeatPlanId).Sum(i => i.Amount);
|
.TakeWhile(i => i.Plan.Id == plan.StripeSeatPlanId && i.Proration).Sum(i => i.Amount);
|
||||||
if(prorationAmount.GetValueOrDefault() >= 500)
|
if(prorationAmount.GetValueOrDefault() >= 500)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// Owes more than $5.00 on next invoice. Invoice them and pay now instead of waiting until next month.
|
// Owes more than $5.00 on next invoice. Invoice them and pay now instead of waiting until next month.
|
||||||
var invoice = await invoiceService.CreateAsync(org.StripeCustomerId,
|
var invoice = await invoiceService.CreateAsync(org.StripeCustomerId,
|
||||||
@ -462,9 +464,14 @@ namespace Bit.Core.Services
|
|||||||
SubscriptionId = org.StripeSubscriptionId
|
SubscriptionId = org.StripeSubscriptionId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(invoice.AmountDue > 0)
|
||||||
|
{
|
||||||
await invoiceService.PayAsync(invoice.Id);
|
await invoiceService.PayAsync(invoice.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(StripeException) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup signup)
|
public async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup signup)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user