1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

started charging sales tax on seat/storage upgrades and auto renewals (#1034)

* started charging sales tax on seat/storage upgrades and auto renewals

* Code review fixes for auto-renewing subscriptions charging sales tax
This commit is contained in:
Addison Beck
2020-12-09 14:04:46 -05:00
committed by GitHub
parent 7d3fb55b2d
commit fee5c932db
5 changed files with 83 additions and 8 deletions

View File

@ -38,6 +38,7 @@ namespace Bit.Core.Services
private readonly ISsoUserRepository _ssoUserRepository;
private readonly IReferenceEventService _referenceEventService;
private readonly GlobalSettings _globalSettings;
private readonly ITaxRateRepository _taxRateRepository;
public OrganizationService(
IOrganizationRepository organizationRepository,
@ -59,7 +60,8 @@ namespace Bit.Core.Services
ISsoConfigRepository ssoConfigRepository,
ISsoUserRepository ssoUserRepository,
IReferenceEventService referenceEventService,
GlobalSettings globalSettings)
GlobalSettings globalSettings,
ITaxRateRepository taxRateRepository)
{
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
@ -81,6 +83,7 @@ namespace Bit.Core.Services
_ssoUserRepository = ssoUserRepository;
_referenceEventService = referenceEventService;
_globalSettings = globalSettings;
_taxRateRepository = taxRateRepository;
}
public async Task ReplacePaymentMethodAsync(Guid organizationId, string paymentToken,
@ -392,7 +395,7 @@ namespace Bit.Core.Services
// Retain original collection method
var collectionMethod = sub.CollectionMethod;
var subResponse = await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions
var subUpdateOptions = new SubscriptionUpdateOptions
{
Items = new List<SubscriptionItemOptions>
{
@ -408,7 +411,26 @@ namespace Bit.Core.Services
DaysUntilDue = 1,
CollectionMethod = "send_invoice",
ProrationDate = prorationDate,
});
};
var customer = await new CustomerService().GetAsync(sub.CustomerId);
var taxRates = await _taxRateRepository.GetByLocationAsync(
new Bit.Core.Models.Table.TaxRate()
{
Country = customer.Address.Country,
PostalCode = customer.Address.PostalCode
}
);
var taxRate = taxRates.FirstOrDefault();
if (taxRate != null && !sub.DefaultTaxRates.Any(x => x.Equals(taxRate.Id)))
{
subUpdateOptions.DefaultTaxRates = new List<string>(1)
{
taxRate.Id
};
}
var subResponse = await subscriptionService.UpdateAsync(sub.Id, subUpdateOptions);
string paymentIntentClientSecret = null;
if (additionalSeats > 0)

View File

@ -684,7 +684,7 @@ namespace Bit.Core.Services
// Retain original collection method
var collectionMethod = sub.CollectionMethod;
var subResponse = await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions
var subUpdateOptions = new SubscriptionUpdateOptions
{
Items = new List<SubscriptionItemOptions>
{
@ -700,7 +700,26 @@ namespace Bit.Core.Services
DaysUntilDue = 1,
CollectionMethod = "send_invoice",
ProrationDate = prorationDate,
});
};
var customer = await new CustomerService().GetAsync(sub.CustomerId);
var taxRates = await _taxRateRepository.GetByLocationAsync(
new Bit.Core.Models.Table.TaxRate()
{
Country = customer.Address.Country,
PostalCode = customer.Address.PostalCode
}
);
var taxRate = taxRates.FirstOrDefault();
if (taxRate != null && !sub.DefaultTaxRates.Any(x => x.Equals(taxRate.Id)))
{
subUpdateOptions.DefaultTaxRates = new List<string>(1)
{
taxRate.Id
};
}
var subResponse = await subscriptionService.UpdateAsync(sub.Id, subUpdateOptions);
string paymentIntentClientSecret = null;
if (additionalStorage > 0)