From 1af53f261222b98111b12fac667f316fbc0b2c06 Mon Sep 17 00:00:00 2001 From: Ehren Kret Date: Wed, 13 Oct 2021 13:28:31 -0500 Subject: [PATCH] Simplify getLevels API --- .../controllers/SubscriptionController.java | 29 ++++++------------- .../SubscriptionControllerTest.java | 6 ++-- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java index 6a218d7b5..784741205 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java @@ -299,7 +299,8 @@ public class SubscriptionController { return stripeManager.updateSubscription( subscription, priceConfiguration.getId(), level, idempotencyKey) .thenCompose(updatedSubscription -> - subscriptionManager.subscriptionLevelChanged(requestData.subscriberUser, requestData.now, level) + subscriptionManager.subscriptionLevelChanged(requestData.subscriberUser, requestData.now, + level) .thenApply(unused -> updatedSubscription)); })); } @@ -311,28 +312,13 @@ public class SubscriptionController { public static class Level { - public static class Price { - - private final BigDecimal amount; - - @JsonCreator - public Price( - @JsonProperty("amount") BigDecimal amount) { - this.amount = amount; - } - - public BigDecimal getAmount() { - return amount; - } - } - private final String badgeId; - private final Map currencies; + private final Map currencies; @JsonCreator public Level( @JsonProperty("badgeId") String badgeId, - @JsonProperty("currencies") Map currencies) { + @JsonProperty("currencies") Map currencies) { this.badgeId = badgeId; this.currencies = currencies; } @@ -341,7 +327,7 @@ public class SubscriptionController { return badgeId; } - public Map getCurrencies() { + public Map getCurrencies() { return currencies; } } @@ -371,7 +357,7 @@ public class SubscriptionController { entry -> new GetLevelsResponse.Level(entry.getValue().getBadge(), entry.getValue().getPrices().entrySet().stream().collect( Collectors.toMap(levelEntry -> levelEntry.getKey().toUpperCase(Locale.ROOT), - levelEntry -> new GetLevelsResponse.Level.Price(levelEntry.getValue().getAmount()))))))); + levelEntry -> levelEntry.getValue().getAmount())))))); return Response.ok(getLevelsResponse).build(); }); } @@ -478,6 +464,7 @@ public class SubscriptionController { } public static class GetReceiptCredentialsRequest { + private final byte[] receiptCredentialRequest; @JsonCreator @@ -493,6 +480,7 @@ public class SubscriptionController { } public static class GetReceiptCredentialsResponse { + private final byte[] receiptCredentialResponse; @JsonCreator @@ -556,6 +544,7 @@ public class SubscriptionController { } public static class Receipt { + private final Instant expiration; private final long level; private final String invoiceLineItemId; diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java index 0ec90e3f7..ff3aad58b 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java @@ -77,19 +77,19 @@ class SubscriptionControllerTest { assertThat(longLevelMap).extractingByKey(1L).satisfies(level -> { assertThat(level.getBadgeId()).isEqualTo("B1"); assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { - assertThat(price.getAmount()).isEqualTo("100"); + assertThat(price).isEqualTo("100"); }); }); assertThat(longLevelMap).extractingByKey(2L).satisfies(level -> { assertThat(level.getBadgeId()).isEqualTo("B2"); assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { - assertThat(price.getAmount()).isEqualTo("200"); + assertThat(price).isEqualTo("200"); }); }); assertThat(longLevelMap).extractingByKey(3L).satisfies(level -> { assertThat(level.getBadgeId()).isEqualTo("B3"); assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> { - assertThat(price.getAmount()).isEqualTo("300"); + assertThat(price).isEqualTo("300"); }); }); });