Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEEEP][PM-16921] Improve validation tax information when subscribing to pre… #5247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Api/Auth/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,11 @@
new TaxInfo
{
BillingAddressCountry = model.Country,
BillingAddressPostalCode = model.PostalCode
BillingAddressPostalCode = model.PostalCode,
BillingAddressCity = model.City,
BillingAddressLine1 = model.Line1,
BillingAddressLine2 = model.Line2,
BillingAddressState = model.State,

Check warning on line 673 in src/Api/Auth/Controllers/AccountsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Auth/Controllers/AccountsController.cs#L669-L673

Added lines #L669 - L673 were not covered by tests
});

var userTwoFactorEnabled = await _userService.TwoFactorIsEnabledAsync(user);
Expand Down Expand Up @@ -726,8 +730,7 @@
BillingAddressCity = model.City,
BillingAddressState = model.State,
BillingAddressCountry = model.Country,
BillingAddressPostalCode = model.PostalCode,
TaxIdNumber = model.TaxId
BillingAddressPostalCode = model.PostalCode

Check warning on line 733 in src/Api/Auth/Controllers/AccountsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Auth/Controllers/AccountsController.cs#L733

Added line #L733 was not covered by tests
});
}

Expand Down
17 changes: 11 additions & 6 deletions src/Api/Models/Request/Accounts/PremiumRequestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@
[Range(0, 99)]
public short? AdditionalStorageGb { get; set; }
public IFormFile License { get; set; }
public string Country { get; set; }

public string Line1 { get; set; }
public string Line2 { get; set; }

Check warning on line 17 in src/Api/Models/Request/Accounts/PremiumRequestModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Models/Request/Accounts/PremiumRequestModel.cs#L16-L17

Added lines #L16 - L17 were not covered by tests

[Required]
public string PostalCode { get; set; }

public string City { get; set; }
public string State { get; set; }

Check warning on line 23 in src/Api/Models/Request/Accounts/PremiumRequestModel.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Models/Request/Accounts/PremiumRequestModel.cs#L22-L23

Added lines #L22 - L23 were not covered by tests

[Required]
public string Country { get; set; }

public bool Validate(GlobalSettings globalSettings)
{
if (!(License == null && !globalSettings.SelfHosted) ||
Expand All @@ -32,10 +42,5 @@
{
yield return new ValidationResult("Payment token or license is required.");
}
if (Country == "US" && string.IsNullOrWhiteSpace(PostalCode))
{
yield return new ValidationResult("Zip / postal code is required.",
new string[] { nameof(PostalCode) });
}
}
}
50 changes: 25 additions & 25 deletions src/Core/Services/Implementations/StripePaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,15 +1394,9 @@

try
{
if (!string.IsNullOrWhiteSpace(taxInfo.TaxIdNumber))
{
taxInfo.TaxIdType = taxInfo.TaxIdType ??
_taxService.GetStripeTaxCode(taxInfo.BillingAddressCountry, taxInfo.TaxIdNumber);
}

if (customer == null)
{
customer = await _stripeAdapter.CustomerCreateAsync(new CustomerCreateOptions
var customerCreateOptions = new CustomerCreateOptions

Check warning on line 1399 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1399

Added line #L1399 was not covered by tests
{
Description = subscriber.BillingName(),
Email = subscriber.BillingEmailAddress(),
Expand All @@ -1422,26 +1416,32 @@

]
},
Address = taxInfo == null ? null : new AddressOptions
{
Country = taxInfo.BillingAddressCountry,
PostalCode = taxInfo.BillingAddressPostalCode,
Line1 = taxInfo.BillingAddressLine1 ?? string.Empty,
Line2 = taxInfo.BillingAddressLine2,
City = taxInfo.BillingAddressCity,
State = taxInfo.BillingAddressState
},
TaxIdData = string.IsNullOrWhiteSpace(taxInfo.TaxIdNumber)
? []
: [
new CustomerTaxIdDataOptions
Address = taxInfo == null
? null
: new AddressOptions

Check warning on line 1421 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1419-L1421

Added lines #L1419 - L1421 were not covered by tests
{
Type = taxInfo.TaxIdType,
Value = taxInfo.TaxIdNumber
}
],
Country = taxInfo.BillingAddressCountry,
PostalCode = taxInfo.BillingAddressPostalCode,

Check warning on line 1424 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1424

Added line #L1424 was not covered by tests
Line1 = taxInfo.BillingAddressLine1 ?? string.Empty,
Line2 = taxInfo.BillingAddressLine2,
City = taxInfo.BillingAddressCity,
State = taxInfo.BillingAddressState
},

Check warning on line 1429 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1426-L1429

Added lines #L1426 - L1429 were not covered by tests
Expand = ["sources", "tax", "subscriptions"],
});
};

if (!string.IsNullOrWhiteSpace(taxInfo.TaxIdNumber))
{

Check warning on line 1434 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1432-L1434

Added lines #L1432 - L1434 were not covered by tests
taxInfo.TaxIdType = taxInfo.TaxIdType ??
_taxService.GetStripeTaxCode(taxInfo.BillingAddressCountry, taxInfo.TaxIdNumber);

Check warning on line 1436 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1436

Added line #L1436 was not covered by tests

customerCreateOptions.TaxIdData =
[
new CustomerTaxIdDataOptions { Type = taxInfo.TaxIdType, Value = taxInfo.TaxIdNumber }
];
}

customer = await _stripeAdapter.CustomerCreateAsync(customerCreateOptions);

Check warning on line 1444 in src/Core/Services/Implementations/StripePaymentService.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Services/Implementations/StripePaymentService.cs#L1438-L1444

Added lines #L1438 - L1444 were not covered by tests

subscriber.Gateway = GatewayType.Stripe;
subscriber.GatewayCustomerId = customer.Id;
Expand Down
Loading