diff options
author | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-10-30 15:30:10 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-10-30 15:30:10 +0100 |
commit | 8b6c5e37aff416b59f4182f901328479d543a71e (patch) | |
tree | 0931b682e8635f075bd05725d26b1d7dbe5e8f6a /controller-server | |
parent | 621520610face5ad70122a4ddecb61e2222798d8 (diff) |
Add country to tax id definition
Diffstat (limited to 'controller-server')
4 files changed, 16 insertions, 5 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java index 85b7acd603a..7801efe504b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializer.java @@ -96,6 +96,7 @@ public class TenantSerializer { private static final String accountField = "account"; private static final String templateVersionField = "templateVersion"; private static final String taxIdField = "taxId"; + private static final String taxIdCountryField = "country"; private static final String taxIdTypeField = "type"; private static final String taxIdCodeField = "code"; private static final String purchaseOrderField = "purchaseOrder"; @@ -293,9 +294,10 @@ public class TenantSerializer { var taxId = switch (taxIdInspector.type()) { case STRING -> TaxId.legacy(taxIdInspector.asString()); case OBJECT -> { + var taxIdCountry = taxIdInspector.field(taxIdCountryField).asString(); var taxIdType = taxIdInspector.field(taxIdTypeField).asString(); var taxIdCode = taxIdInspector.field(taxIdCodeField).asString(); - yield new TaxId(new TaxId.Type(taxIdType), new TaxId.Code(taxIdCode)); + yield new TaxId(new TaxId.Country(taxIdCountry), new TaxId.Type(taxIdType), new TaxId.Code(taxIdCode)); } case NIX -> TaxId.empty(); default -> throw new IllegalStateException(taxIdInspector.type().name()); @@ -374,6 +376,7 @@ public class TenantSerializer { billingCursor.setBool("emailVerified", billingContact.contact().email().isVerified()); billingCursor.setString("phone", billingContact.contact().phone()); var taxIdCursor = billingCursor.setObject(taxIdField); + taxIdCursor.setString(taxIdCountryField, billingContact.getTaxId().country().value()); taxIdCursor.setString(taxIdTypeField, billingContact.getTaxId().type().value()); taxIdCursor.setString(taxIdCodeField, billingContact.getTaxId().code().value()); billingCursor.setString(purchaseOrderField, billingContact.getPurchaseOrder().value()); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 078c27f5d00..fa32d61675c 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -697,6 +697,7 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { contact.setBool("emailVerified", billingContact.contact().email().isVerified()); contact.setString("phone", billingContact.contact().phone()); var taxIdCursor = root.setObject("taxId"); + taxIdCursor.setString("country", billingContact.getTaxId().country().value()); taxIdCursor.setString("type", billingContact.getTaxId().type().value()); taxIdCursor.setString("code", billingContact.getTaxId().code().value()); root.setString("purchaseOrder", billingContact.getPurchaseOrder().value()); @@ -809,6 +810,7 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { billingCursor.setBool("emailVerified", billingContact.contact().email().isVerified()); billingCursor.setString("phone", billingContact.contact().phone()); var taxIdCursor = billingCursor.setObject("taxId"); + taxIdCursor.setString("country", billingContact.getTaxId().country().value()); taxIdCursor.setString("type", billingContact.getTaxId().type().value()); taxIdCursor.setString("code", billingContact.getTaxId().code().value()); billingCursor.setString("purchaseOrder", billingContact.getPurchaseOrder().value()); @@ -924,8 +926,10 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler { private TaxId updateAndValidateTaxId(Inspector insp, TaxId old) { if (!insp.valid()) return old; - var taxId = new TaxId(getString(insp.field("type"), old.type().value()), - getString(insp.field("code"), old.code().value())); + var taxId = new TaxId( + getString(insp.field("country"), old.country().value()), + getString(insp.field("type"), old.type().value()), + getString(insp.field("code"), old.code().value())); controller.serviceRegistry().billingController().validateTaxId(taxId); return taxId; } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java index cfc3320b083..f2fc43933df 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/TenantSerializerTest.java @@ -238,7 +238,7 @@ public class TenantSerializerTest { .withAddress("Central Station") .withRegion("Irish Sea")) .withPurchaseOrder(new PurchaseOrder("PO42")) - .withTaxId(new TaxId("no_vat", "123456789MVA")) + .withTaxId(new TaxId("NO", "no_vat", "123456789MVA")) .withInvoiceEmail(new Email("billing@mycomp.any", false)) ); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiCloudTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiCloudTest.java index 1ad88675169..f8ae7c8ea50 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiCloudTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiCloudTest.java @@ -107,6 +107,7 @@ public class ApplicationApiCloudTest extends ControllerContainerCloudTest { "phone":"" }, "taxId": { + "country": "", "type": "", "code": "" }, @@ -125,7 +126,7 @@ public class ApplicationApiCloudTest extends ControllerContainerCloudTest { "email":"foo@example", "phone":"phone" }, - "taxId":{"type": "no_vat", "code": "123456789MVA"}, + "taxId":{"country": "NO", "type": "no_vat", "code": "123456789MVA"}, "purchaseOrder":"PO9001", "invoiceEmail":"billing@mycomp.any", "address": { @@ -151,6 +152,7 @@ public class ApplicationApiCloudTest extends ControllerContainerCloudTest { "phone":"phone" }, "taxId": { + "country": "NO", "type": "no_vat", "code": "123456789MVA" }, @@ -238,6 +240,7 @@ public class ApplicationApiCloudTest extends ControllerContainerCloudTest { "email":"","emailVerified":false, "phone":"", "taxId": { + "country": "", "type": "", "code": "" }, @@ -272,6 +275,7 @@ public class ApplicationApiCloudTest extends ControllerContainerCloudTest { "emailVerified":false, "phone":"phone", "taxId": { + "country": "", "type": "", "code": "" }, |