mirror of
https://github.com/bitwarden/server.git
synced 2024-11-28 13:15:12 +01:00
wip
This commit is contained in:
parent
ce85c38aa7
commit
27502da957
@ -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,51 +1708,53 @@ public class StripePaymentService : IPaymentService
|
|||||||
Expand = ["tax_ids"]
|
Expand = ["tax_ids"]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!subscriber.IsUser() && customer != null)
|
if (customer == null) return;
|
||||||
|
|
||||||
|
var taxId = customer.TaxIds?.FirstOrDefault();
|
||||||
|
|
||||||
|
if (taxId != null)
|
||||||
|
{
|
||||||
|
await _stripeAdapter.TaxIdDeleteAsync(customer.Id, taxId.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(taxInfo.TaxIdNumber)) return;
|
||||||
|
|
||||||
|
var taxIdType = taxInfo.TaxIdType;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(taxIdType))
|
||||||
|
{
|
||||||
|
taxIdType = _taxService.GetStripeTaxCode(taxInfo.BillingAddressCountry, taxInfo.TaxIdNumber);
|
||||||
|
|
||||||
|
if (taxIdType == null)
|
||||||
{
|
{
|
||||||
var taxId = customer.TaxIds?.FirstOrDefault();
|
_logger.LogWarning("Could not infer tax ID type in country '{Country}' with tax ID '{TaxID}'.",
|
||||||
|
taxInfo.BillingAddressCountry,
|
||||||
|
taxInfo.TaxIdNumber);
|
||||||
|
throw new BadRequestException("billingTaxIdTypeInferenceError");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (taxId != null)
|
try
|
||||||
{
|
{
|
||||||
await _stripeAdapter.TaxIdDeleteAsync(customer.Id, taxId.Id);
|
await _stripeAdapter.TaxIdCreateAsync(customer.Id,
|
||||||
}
|
new TaxIdCreateOptions { Type = taxInfo.TaxIdType, Value = taxInfo.TaxIdNumber, });
|
||||||
|
}
|
||||||
if (taxInfo.TaxIdType == null)
|
catch (StripeException e)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Could not infer tax ID type in country '{Country}' with tax ID '{TaxID}'.",
|
switch (e.StripeError.Code)
|
||||||
|
{
|
||||||
|
case StripeConstants.ErrorCodes.TaxIdInvalid:
|
||||||
|
_logger.LogWarning("Invalid tax ID '{TaxID}' for country '{Country}'.",
|
||||||
|
taxInfo.TaxIdNumber,
|
||||||
|
taxInfo.BillingAddressCountry);
|
||||||
|
throw new BadRequestException("billingInvalidTaxIdError");
|
||||||
|
default:
|
||||||
|
_logger.LogError(e,
|
||||||
|
"Error creating tax ID '{TaxId}' in country '{Country}' for customer '{CustomerID}'.",
|
||||||
|
taxInfo.TaxIdNumber,
|
||||||
taxInfo.BillingAddressCountry,
|
taxInfo.BillingAddressCountry,
|
||||||
taxInfo.TaxIdNumber);
|
customer.Id);
|
||||||
throw new BadRequestException("billingTaxIdTypeInferenceError");
|
throw new BadRequestException("billingTaxIdCreationError");
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(taxInfo.TaxIdNumber))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _stripeAdapter.TaxIdCreateAsync(customer.Id, new TaxIdCreateOptions
|
|
||||||
{
|
|
||||||
Type = taxInfo.TaxIdType,
|
|
||||||
Value = taxInfo.TaxIdNumber,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (StripeException e)
|
|
||||||
{
|
|
||||||
switch (e.StripeError.Code)
|
|
||||||
{
|
|
||||||
case StripeConstants.ErrorCodes.TaxIdInvalid:
|
|
||||||
_logger.LogWarning("Invalid tax ID '{TaxID}' for country '{Country}'.",
|
|
||||||
taxInfo.TaxIdNumber,
|
|
||||||
taxInfo.BillingAddressCountry);
|
|
||||||
throw new BadRequestException("billingInvalidTaxIdError");
|
|
||||||
default:
|
|
||||||
_logger.LogError(e, "Error creating tax ID '{TaxId}' in country '{Country}' for customer '{CustomerID}'.",
|
|
||||||
taxInfo.TaxIdNumber,
|
|
||||||
taxInfo.BillingAddressCountry,
|
|
||||||
customer.Id);
|
|
||||||
throw new BadRequestException("billingTaxIdCreationError");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user