aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@vespa.ai>2023-10-26 13:46:01 +0200
committerBjørn Christian Seime <bjorncs@vespa.ai>2023-10-26 15:05:45 +0200
commit0f2ce7b6011610ba2af87a19e2a2eeb90bc0f94f (patch)
tree63304cc6f47227ea123765ef0d77fa5e095f7b5c /controller-server
parenta3ff4d30e01b2e5294883f36a62f0355eddcb116 (diff)
Introduce method to `/billing/v2` that returns accepted countries with tax types
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java27
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java7
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/accepted-countries.json34
3 files changed, 68 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java
index 85a77dcfa61..b4237a46c5a 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java
@@ -74,6 +74,12 @@ public class BillingApiHandlerV2 extends RestApiRequestHandler<BillingApiHandler
private static RestApi createRestApi(BillingApiHandlerV2 self) {
return RestApi.builder()
/*
+ * This is the API that is tenant agnostic
+ */
+ .addRoute(RestApi.route("/billing/v2/countries")
+ .get(self::acceptedCountries))
+
+ /*
* This is the API that is available to tenants to view their status
*/
.addRoute(RestApi.route("/billing/v2/tenant/{tenant}")
@@ -116,6 +122,27 @@ public class BillingApiHandlerV2 extends RestApiRequestHandler<BillingApiHandler
.build();
}
+ // ---------- AUX API -------------
+
+ private SlimeJsonResponse acceptedCountries(RestApi.RequestContext ctx) {
+ var response = new Slime();
+ var countries = response.setObject().setArray("countries");
+ billing.getAcceptedCountries().countries().forEach(country -> {
+ var countryCursor = countries.addObject();
+ countryCursor.setString("code", country.code());
+ countryCursor.setString("name", country.displayName());
+ var taxTypesCursors = countryCursor.setArray("taxTypes");
+ country.taxTypes().forEach(taxType -> {
+ var taxTypeCursor = taxTypesCursors.addObject();
+ taxTypeCursor.setString("id", taxType.id());
+ taxTypeCursor.setString("description", taxType.description());
+ taxTypeCursor.setString("pattern", taxType.pattern());
+ taxTypeCursor.setString("example", taxType.example());
+ });
+ });
+ return new SlimeJsonResponse(response, /*compact*/false);
+ }
+
// ---------- TENANT API ----------
private Slime tenant(RestApi.RequestContext requestContext) {
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java
index 46c1aa107f0..356076a8d00 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2Test.java
@@ -17,6 +17,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
+import java.io.File;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
@@ -251,6 +252,12 @@ public class BillingApiHandlerV2Test extends ControllerContainerCloudTest {
{"tenant":"tenant1","plan":{"id":"trial","name":"Free Trial - for testing purposes","billed":false,"supported":false},"billing":{},"collection":"AUTO"}""");
}
+ @Test
+ void lists_accepted_countries() {
+ var req = request("/billing/v2/countries").roles(tenantReader);
+ tester.assertJsonResponse(req, new File("accepted-countries.json"));
+ }
+
private static Bill createBill() {
var start = LocalDate.of(2020, 5, 23).atStartOfDay(ZoneOffset.UTC);
var end = start.toLocalDate().plusDays(6).atStartOfDay(ZoneOffset.UTC);
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/accepted-countries.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/accepted-countries.json
new file mode 100644
index 00000000000..2714de1e64d
--- /dev/null
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/accepted-countries.json
@@ -0,0 +1,34 @@
+{
+ "countries": [
+ {
+ "code": "NO",
+ "name": "Norway",
+ "taxTypes": [
+ {
+ "id": "no_vat",
+ "description": "Norwegian VAT number",
+ "pattern": "[0-9]{9}MVA",
+ "example": "123456789MVA"
+ }
+ ]
+ },
+ {
+ "code": "CA",
+ "name": "Canada",
+ "taxTypes": [
+ {
+ "id": "ca_gst_hst",
+ "description": "Canadian GST/HST number",
+ "pattern": "([0-9]{9}) ?RT ?([0-9]{4})",
+ "example": "123456789RT0002"
+ },
+ {
+ "id": "ca_pst_bc",
+ "description": "Canadian PST number (British Columbia)",
+ "pattern": "PST-?([0-9]{4})-?([0-9]{4})",
+ "example": "PST-1234-5678"
+ }
+ ]
+ }
+ ]
+}