1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-07 02:52:50 -05:00

API updates for tax info collection

This commit is contained in:
Chad Scharf
2020-06-08 17:40:18 -04:00
parent cad7cf0200
commit d88838f19e
11 changed files with 411 additions and 5 deletions

View File

@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
{
public class TaxInfoUpdateRequestModel : IValidatableObject
{
[Required]
public string Country { get; set; }
public string PostalCode { get; set; }
public virtual IEnumerable<ValidationResult> Validate (ValidationContext validationContext)
{
if (Country == "US" && string.IsNullOrWhiteSpace(PostalCode))
{
yield return new ValidationResult("Zip / postal code is required.",
new string[] { nameof(PostalCode) });
}
}
}
}

View File

@ -31,6 +31,15 @@ namespace Bit.Core.Models.Api
[EncryptedString]
[EncryptedStringLength(1000)]
public string CollectionName { get; set; }
public string TaxIdNumber { get; set; }
public string BillingAddressLine1 { get; set; }
public string BillingAddressLine2 { get; set; }
public string BillingAddressCity { get; set; }
public string BillingAddressState { get; set; }
public string BillingAddressPostalCode { get; set; }
[Required]
[StringLength(2)]
public string BillingAddressCountry { get; set; }
public virtual OrganizationSignup ToOrganizationSignup(User user)
{
@ -47,7 +56,17 @@ namespace Bit.Core.Models.Api
PremiumAccessAddon = PremiumAccessAddon,
BillingEmail = BillingEmail,
BusinessName = BusinessName,
CollectionName = CollectionName
CollectionName = CollectionName,
TaxInfo = new TaxInfo
{
TaxIdNumber = TaxIdNumber,
BillingAddressLine1 = BillingAddressLine1,
BillingAddressLine2 = BillingAddressLine2,
BillingAddressCity = BillingAddressCity,
BillingAddressState = BillingAddressState,
BillingAddressPostalCode = BillingAddressPostalCode,
BillingAddressCountry = BillingAddressCountry,
},
};
}
@ -62,6 +81,17 @@ namespace Bit.Core.Models.Api
yield return new ValidationResult("Payment method type required.",
new string[] { nameof(PaymentMethodType) });
}
if (PlanType != PlanType.Free && string.IsNullOrWhiteSpace(BillingAddressCountry))
{
yield return new ValidationResult("Country required.",
new string[] { nameof(BillingAddressCountry) });
}
if (PlanType != PlanType.Free && BillingAddressCountry == "US" &&
string.IsNullOrWhiteSpace(BillingAddressPostalCode))
{
yield return new ValidationResult("Zip / postal code is required.",
new string[] { nameof(BillingAddressPostalCode) });
}
}
}
}

View File

@ -0,0 +1,11 @@
namespace Bit.Core.Models.Api
{
public class OrganizationTaxInfoUpdateRequestModel : TaxInfoUpdateRequestModel
{
public string TaxId { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
public string State { get; set; }
}
}

View File

@ -0,0 +1,34 @@
using Bit.Core.Models.Business;
namespace Bit.Core.Models.Api
{
public class TaxInfoResponseModel
{
public TaxInfoResponseModel () { }
public TaxInfoResponseModel(TaxInfo taxInfo)
{
if (taxInfo == null)
{
return;
}
TaxIdNumber = taxInfo.TaxIdNumber;
TaxIdType = taxInfo.TaxIdType;
Line1 = taxInfo.BillingAddressLine1;
Line2 = taxInfo.BillingAddressLine2;
City = taxInfo.BillingAddressCity;
State = taxInfo.BillingAddressState;
PostalCode = taxInfo.BillingAddressPostalCode;
Country = taxInfo.BillingAddressCountry;
}
public string TaxIdNumber { get; set; }
public string TaxIdType { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
}
}