Simplify getLevels API
This commit is contained in:
parent
c89cfa4927
commit
1af53f2612
|
@ -299,7 +299,8 @@ public class SubscriptionController {
|
||||||
return stripeManager.updateSubscription(
|
return stripeManager.updateSubscription(
|
||||||
subscription, priceConfiguration.getId(), level, idempotencyKey)
|
subscription, priceConfiguration.getId(), level, idempotencyKey)
|
||||||
.thenCompose(updatedSubscription ->
|
.thenCompose(updatedSubscription ->
|
||||||
subscriptionManager.subscriptionLevelChanged(requestData.subscriberUser, requestData.now, level)
|
subscriptionManager.subscriptionLevelChanged(requestData.subscriberUser, requestData.now,
|
||||||
|
level)
|
||||||
.thenApply(unused -> updatedSubscription));
|
.thenApply(unused -> updatedSubscription));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -311,28 +312,13 @@ public class SubscriptionController {
|
||||||
|
|
||||||
public static class Level {
|
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 String badgeId;
|
||||||
private final Map<String, Price> currencies;
|
private final Map<String, BigDecimal> currencies;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public Level(
|
public Level(
|
||||||
@JsonProperty("badgeId") String badgeId,
|
@JsonProperty("badgeId") String badgeId,
|
||||||
@JsonProperty("currencies") Map<String, Price> currencies) {
|
@JsonProperty("currencies") Map<String, BigDecimal> currencies) {
|
||||||
this.badgeId = badgeId;
|
this.badgeId = badgeId;
|
||||||
this.currencies = currencies;
|
this.currencies = currencies;
|
||||||
}
|
}
|
||||||
|
@ -341,7 +327,7 @@ public class SubscriptionController {
|
||||||
return badgeId;
|
return badgeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Price> getCurrencies() {
|
public Map<String, BigDecimal> getCurrencies() {
|
||||||
return currencies;
|
return currencies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +357,7 @@ public class SubscriptionController {
|
||||||
entry -> new GetLevelsResponse.Level(entry.getValue().getBadge(),
|
entry -> new GetLevelsResponse.Level(entry.getValue().getBadge(),
|
||||||
entry.getValue().getPrices().entrySet().stream().collect(
|
entry.getValue().getPrices().entrySet().stream().collect(
|
||||||
Collectors.toMap(levelEntry -> levelEntry.getKey().toUpperCase(Locale.ROOT),
|
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();
|
return Response.ok(getLevelsResponse).build();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -478,6 +464,7 @@ public class SubscriptionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GetReceiptCredentialsRequest {
|
public static class GetReceiptCredentialsRequest {
|
||||||
|
|
||||||
private final byte[] receiptCredentialRequest;
|
private final byte[] receiptCredentialRequest;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
|
@ -493,6 +480,7 @@ public class SubscriptionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GetReceiptCredentialsResponse {
|
public static class GetReceiptCredentialsResponse {
|
||||||
|
|
||||||
private final byte[] receiptCredentialResponse;
|
private final byte[] receiptCredentialResponse;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
|
@ -556,6 +544,7 @@ public class SubscriptionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Receipt {
|
public static class Receipt {
|
||||||
|
|
||||||
private final Instant expiration;
|
private final Instant expiration;
|
||||||
private final long level;
|
private final long level;
|
||||||
private final String invoiceLineItemId;
|
private final String invoiceLineItemId;
|
||||||
|
|
|
@ -77,19 +77,19 @@ class SubscriptionControllerTest {
|
||||||
assertThat(longLevelMap).extractingByKey(1L).satisfies(level -> {
|
assertThat(longLevelMap).extractingByKey(1L).satisfies(level -> {
|
||||||
assertThat(level.getBadgeId()).isEqualTo("B1");
|
assertThat(level.getBadgeId()).isEqualTo("B1");
|
||||||
assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> {
|
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(longLevelMap).extractingByKey(2L).satisfies(level -> {
|
||||||
assertThat(level.getBadgeId()).isEqualTo("B2");
|
assertThat(level.getBadgeId()).isEqualTo("B2");
|
||||||
assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> {
|
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(longLevelMap).extractingByKey(3L).satisfies(level -> {
|
||||||
assertThat(level.getBadgeId()).isEqualTo("B3");
|
assertThat(level.getBadgeId()).isEqualTo("B3");
|
||||||
assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> {
|
assertThat(level.getCurrencies()).containsKeys("USD").extractingByKey("USD").satisfies(price -> {
|
||||||
assertThat(price.getAmount()).isEqualTo("300");
|
assertThat(price).isEqualTo("300");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue