1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-28 13:15:12 +01:00
This commit is contained in:
Jonas Hendrickx 2024-11-25 09:55:28 +01:00
parent ce85c38aa7
commit 27502da957

View File

@ -1691,9 +1691,10 @@ public class StripePaymentService : IPaymentService
public async Task SaveTaxInfoAsync(ISubscriber subscriber, TaxInfo taxInfo) public async Task SaveTaxInfoAsync(ISubscriber subscriber, TaxInfo taxInfo)
{ {
if (subscriber != null && !string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId)) if (string.IsNullOrWhiteSpace(subscriber?.GatewayCustomerId) || subscriber.IsUser()) return;
{
var customer = await _stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId, new CustomerUpdateOptions var customer = await _stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId,
new CustomerUpdateOptions
{ {
Address = new AddressOptions Address = new AddressOptions
{ {
@ -1707,8 +1708,8 @@ public class StripePaymentService : IPaymentService
Expand = ["tax_ids"] Expand = ["tax_ids"]
}); });
if (!subscriber.IsUser() && customer != null) if (customer == null) return;
{
var taxId = customer.TaxIds?.FirstOrDefault(); var taxId = customer.TaxIds?.FirstOrDefault();
if (taxId != null) if (taxId != null)
@ -1716,23 +1717,27 @@ public class StripePaymentService : IPaymentService
await _stripeAdapter.TaxIdDeleteAsync(customer.Id, taxId.Id); await _stripeAdapter.TaxIdDeleteAsync(customer.Id, taxId.Id);
} }
if (taxInfo.TaxIdType == null) if (string.IsNullOrWhiteSpace(taxInfo.TaxIdNumber)) return;
var taxIdType = taxInfo.TaxIdType;
if (string.IsNullOrWhiteSpace(taxIdType))
{
taxIdType = _taxService.GetStripeTaxCode(taxInfo.BillingAddressCountry, taxInfo.TaxIdNumber);
if (taxIdType == null)
{ {
_logger.LogWarning("Could not infer tax ID type in country '{Country}' with tax ID '{TaxID}'.", _logger.LogWarning("Could not infer tax ID type in country '{Country}' with tax ID '{TaxID}'.",
taxInfo.BillingAddressCountry, taxInfo.BillingAddressCountry,
taxInfo.TaxIdNumber); taxInfo.TaxIdNumber);
throw new BadRequestException("billingTaxIdTypeInferenceError"); throw new BadRequestException("billingTaxIdTypeInferenceError");
} }
}
if (!string.IsNullOrWhiteSpace(taxInfo.TaxIdNumber))
{
try try
{ {
await _stripeAdapter.TaxIdCreateAsync(customer.Id, new TaxIdCreateOptions await _stripeAdapter.TaxIdCreateAsync(customer.Id,
{ new TaxIdCreateOptions { Type = taxInfo.TaxIdType, Value = taxInfo.TaxIdNumber, });
Type = taxInfo.TaxIdType,
Value = taxInfo.TaxIdNumber,
});
} }
catch (StripeException e) catch (StripeException e)
{ {
@ -1744,7 +1749,8 @@ public class StripePaymentService : IPaymentService
taxInfo.BillingAddressCountry); taxInfo.BillingAddressCountry);
throw new BadRequestException("billingInvalidTaxIdError"); throw new BadRequestException("billingInvalidTaxIdError");
default: default:
_logger.LogError(e, "Error creating tax ID '{TaxId}' in country '{Country}' for customer '{CustomerID}'.", _logger.LogError(e,
"Error creating tax ID '{TaxId}' in country '{Country}' for customer '{CustomerID}'.",
taxInfo.TaxIdNumber, taxInfo.TaxIdNumber,
taxInfo.BillingAddressCountry, taxInfo.BillingAddressCountry,
customer.Id); customer.Id);
@ -1752,9 +1758,6 @@ public class StripePaymentService : IPaymentService
} }
} }
} }
}
}
}
public async Task<TaxRate> CreateTaxRateAsync(TaxRate taxRate) public async Task<TaxRate> CreateTaxRateAsync(TaxRate taxRate)
{ {