aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2023-10-30 16:55:23 +0100
committerGitHub <noreply@github.com>2023-10-30 16:55:23 +0100
commit6143829e6383f66a09b3292716ddfaff37d66ab2 (patch)
treee9cb7be64d956ac074abef31da93c571367060e5 /controller-api/src/main/java/com
parentcaa21cf51b78a5426e8a137d7376eea76f59f07d (diff)
parent6a3584d8b799bc815ec339aa2038dccc8a415f1a (diff)
Merge pull request #29158 from vespa-engine/bjorncs/taxid-country
Bjorncs/taxid country
Diffstat (limited to 'controller-api/src/main/java/com')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/AcceptedCountries.java2
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java6
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java20
3 files changed, 19 insertions, 9 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/AcceptedCountries.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/AcceptedCountries.java
index c665b4fb7c2..082eaac7315 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/AcceptedCountries.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/AcceptedCountries.java
@@ -13,7 +13,7 @@ public record AcceptedCountries(List<Country> countries) {
countries = List.copyOf(countries);
}
- public record Country(String code, String displayName, List<TaxType> taxTypes) {
+ public record Country(String code, String displayName, boolean taxIdMandatory, List<TaxType> taxTypes) {
public Country {
taxTypes = List.copyOf(taxTypes);
}
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java
index 18dd339b4a1..9012b45748c 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java
@@ -210,10 +210,10 @@ public class MockBillingController implements BillingController {
public AcceptedCountries getAcceptedCountries() {
return new AcceptedCountries(List.of(
new AcceptedCountries.Country(
- "NO", "Norway",
+ "NO", "Norway", true,
List.of(new AcceptedCountries.TaxType("no_vat", "Norwegian VAT number", "[0-9]{9}MVA", "123456789MVA"))),
new AcceptedCountries.Country(
- "CA", "Canada",
+ "CA", "Canada", true,
List.of(new AcceptedCountries.TaxType("ca_gst_hst", "Canadian GST/HST number", "([0-9]{9}) ?RT ?([0-9]{4})", "123456789RT0002"),
new AcceptedCountries.TaxType("ca_pst_bc", "Canadian PST number (British Columbia)", "PST-?([0-9]{4})-?([0-9]{4})", "PST-1234-5678")))
));
@@ -221,7 +221,7 @@ public class MockBillingController implements BillingController {
@Override
public void validateTaxId(TaxId id) throws IllegalArgumentException {
- if (id.isEmpty() || id.isLegacy()) return;
+ if (id.isEmpty() || id.isLegacy() || id.country().isEmpty()) return;
if (!List.of("eu_vat", "no_vat").contains(id.type().value()))
throw new IllegalArgumentException("Unknown tax id type '%s'".formatted(id.type().value()));
if (!id.code().value().matches("\\w+"))
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java
index 99c2400c58c..172ad257f6a 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/tenant/TaxId.java
@@ -8,17 +8,27 @@ import static ai.vespa.validation.Validation.requireLength;
/**
* @author olaa
*/
-public record TaxId(Type type, Code code) {
+public record TaxId(Country country, Type type, Code code) {
- public TaxId(String type, String code) { this(new Type(type), new Code(code)); }
+ public TaxId(String country, String type, String code) { this(new Country(country), new Type(type), new Code(code)); }
- public static TaxId empty() { return new TaxId(Type.empty(), Code.empty()); }
- public boolean isEmpty() { return type.isEmpty() && code.isEmpty(); }
+ public static TaxId empty() { return new TaxId(Country.empty(), Type.empty(), Code.empty()); }
+ public boolean isEmpty() { return country.isEmpty() && type.isEmpty() && code.isEmpty(); }
// TODO(bjorncs) Remove legacy once no longer present in ZK
- public static TaxId legacy(String code) { return new TaxId(Type.empty(), new Code(code)); }
+ public static TaxId legacy(String code) { return new TaxId(Country.empty(), Type.empty(), new Code(code)); }
public boolean isLegacy() { return type.isEmpty() && !code.isEmpty(); }
+ public static class Country extends StringWrapper<Country> {
+ public Country(String value) {
+ super(value);
+ requireLength(value, "tax code country length", 0, 2);
+ }
+
+ public static Country empty() { return new Country(""); }
+ public boolean isEmpty() { return value().isEmpty(); }
+ }
+
public static class Type extends StringWrapper<Type> {
public Type(String value) {
super(value);