1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-17 01:25:39 -05:00

Collect tax info, correct line1

This commit is contained in:
Chad Scharf 2020-06-12 19:35:17 -04:00
parent d88838f19e
commit 1552ff7b29
2 changed files with 25 additions and 8 deletions

View File

@ -136,5 +136,11 @@
return _taxIdType; return _taxIdType;
} }
} }
public bool HasTaxId
{
get => !string.IsNullOrWhiteSpace(TaxIdNumber) &&
!string.IsNullOrWhiteSpace(TaxIdType);
}
} }
} }

View File

@ -146,7 +146,7 @@ namespace Bit.Core.Services
} }
Customer customer = null; Customer customer = null;
Subscription subscription = null; Subscription subscription;
try try
{ {
customer = await customerService.CreateAsync(new CustomerCreateOptions customer = await customerService.CreateAsync(new CustomerCreateOptions
@ -160,18 +160,22 @@ namespace Bit.Core.Services
{ {
DefaultPaymentMethod = stipeCustomerPaymentMethodId DefaultPaymentMethod = stipeCustomerPaymentMethodId
}, },
// TODO: Address info for zip code and country, optional other address info and tax ID
Address = new AddressOptions Address = new AddressOptions
{ {
Country = null, Country = taxInfo.BillingAddressCountry,
PostalCode = null, PostalCode = taxInfo.BillingAddressPostalCode,
// Line1 is required in Stripe's API, suggestion in Docs is to use Business Name intead.
Line1 = taxInfo.BillingAddressLine1 ?? org.BusinessName,
Line2 = taxInfo.BillingAddressLine2,
City = taxInfo.BillingAddressCity,
State = taxInfo.BillingAddressState,
}, },
TaxIdData = new List<CustomerTaxIdDataOptions> TaxIdData = !taxInfo.HasTaxId ? null : new List<CustomerTaxIdDataOptions>
{ {
new CustomerTaxIdDataOptions new CustomerTaxIdDataOptions
{ {
Type = "", Type = taxInfo.TaxIdType,
Value = null, Value = taxInfo.TaxIdNumber,
}, },
}, },
}); });
@ -1530,6 +1534,13 @@ namespace Bit.Core.Services
var address = customer.Address; var address = customer.Address;
var taxId = customer.TaxIds?.FirstOrDefault(); var taxId = customer.TaxIds?.FirstOrDefault();
// Line1 is required, so if missing we're using the subscriber name
// see: https://stripe.com/docs/api/customers/create#create_customer-address-line1
if (address != null && address.Line1 == subscriber.BillingName())
{
address.Line1 = null;
}
return new TaxInfo return new TaxInfo
{ {
TaxIdNumber = taxId?.Value, TaxIdNumber = taxId?.Value,
@ -1554,7 +1565,7 @@ namespace Bit.Core.Services
{ {
Address = new AddressOptions Address = new AddressOptions
{ {
Line1 = taxInfo.BillingAddressLine1, Line1 = taxInfo.BillingAddressLine1 ?? subscriber.BillingName(),
Line2 = taxInfo.BillingAddressLine2, Line2 = taxInfo.BillingAddressLine2,
City = taxInfo.BillingAddressCity, City = taxInfo.BillingAddressCity,
State = taxInfo.BillingAddressState, State = taxInfo.BillingAddressState,