diff --git a/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java b/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java index 12ed6f10b..c1e852710 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java +++ b/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java @@ -159,7 +159,11 @@ public final class DomainPricingLogic { case NONPREMIUM -> { renewCost = getDomainCostWithDiscount( - false, years, allocationToken, tld.getStandardRenewCost(dateTime)); + false, + years, + allocationToken, + tld.getStandardRenewCost(dateTime), + Optional.empty()); isRenewCostPremiumPrice = false; } default -> @@ -252,7 +256,11 @@ public final class DomainPricingLogic { DomainPrices domainPrices, int years, Optional allocationToken) throws EppException { return getDomainCostWithDiscount( - domainPrices.isPremium(), years, allocationToken, domainPrices.getCreateCost()); + domainPrices.isPremium(), + years, + allocationToken, + domainPrices.getCreateCost(), + Optional.of(domainPrices.getRenewCost())); } /** Returns the domain renew cost with allocation-token-related discounts applied. */ @@ -272,24 +280,45 @@ public final class DomainPricingLogic { } } return getDomainCostWithDiscount( - domainPrices.isPremium(), years, allocationToken, domainPrices.getRenewCost()); + domainPrices.isPremium(), + years, + allocationToken, + domainPrices.getRenewCost(), + Optional.empty()); } + /** + * Returns the domain creation or renewal cost for the given number of {@code years}. + * + *

For domain creation, {@code firstYearCost} is the creation cost while {@code + * subsequentYearCost} is the single-year renewal cost (which is guaranteed to be present). + * + *

For domain renewal, {@code firstYearCost} is the single-year renewal cost and {@code + * subsequentYearCost} should be empty. + */ private Money getDomainCostWithDiscount( - boolean isPremium, int years, Optional allocationToken, Money oneYearCost) + boolean isPremium, + int years, + Optional allocationToken, + Money firstYearCost, + Optional subsequentYearCost) throws AllocationTokenInvalidForPremiumNameException { + checkArgument(years > 0, "Registration years to get cost for must be positive."); validateTokenForPossiblePremiumName(allocationToken, isPremium); - Money totalDomainFlowCost = oneYearCost.multipliedBy(years); + Money totalDomainFlowCost = + firstYearCost.plus(subsequentYearCost.orElse(firstYearCost).multipliedBy(years - 1)); // Apply the allocation token discount, if applicable. if (allocationToken.isPresent() && allocationToken.get().getTokenBehavior().equals(TokenBehavior.DEFAULT)) { int discountedYears = Math.min(years, allocationToken.get().getDiscountYears()); - Money discount = - oneYearCost.multipliedBy( - discountedYears * allocationToken.get().getDiscountFraction(), - RoundingMode.HALF_EVEN); - totalDomainFlowCost = totalDomainFlowCost.minus(discount); + if (discountedYears > 0) { + var discount = + firstYearCost + .plus(subsequentYearCost.orElse(firstYearCost).multipliedBy(discountedYears - 1)) + .multipliedBy(allocationToken.get().getDiscountFraction(), RoundingMode.HALF_EVEN); + totalDomainFlowCost = totalDomainFlowCost.minus(discount); + } } return totalDomainFlowCost; } diff --git a/core/src/test/java/google/registry/flows/EppTestCase.java b/core/src/test/java/google/registry/flows/EppTestCase.java index 3af8b2e99..3088f3118 100644 --- a/core/src/test/java/google/registry/flows/EppTestCase.java +++ b/core/src/test/java/google/registry/flows/EppTestCase.java @@ -297,7 +297,7 @@ public class EppTestCase { .setReason(Reason.CREATE) .setTargetId(domain.getDomainName()) .setRegistrarId(domain.getCurrentSponsorRegistrarId()) - .setCost(Money.parse("USD 26.00")) + .setCost(Money.parse("USD 24.00")) .setPeriodYears(2) .setEventTime(createTime) .setBillingTime(createTime.plus(Tld.get(domain.getTld()).getAddGracePeriodLength())) diff --git a/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java index 332054ea0..7703d981f 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java @@ -514,14 +514,17 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase() .put("DOMAIN", "single.tld") .put("COST_1YR", "7.23") - .put("COST_2YR", "14.46") - .put("COST_5YR", "53.46") + .put("COST_2YR", "13.34") + .put("COST_5YR", "46.34") .put("FEE_CLASS", "") .build())); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java index a6073539b..a9737666f 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -295,7 +295,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase() .put("FEE_VERSION", "0.6") .put("DESCRIPTION_1", "create") - .put("FEE_1", "26") + .put("FEE_1", "24") .put("DESCRIPTION_2", "Early Access Period") .put("FEE_2", "100") .put("DESCRIPTION_3", "renew") @@ -3111,7 +3111,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase() .put("FEE_VERSION", "0.6") .put("DESCRIPTION_1", "create") - .put("FEE_1", "26") + .put("FEE_1", "24") .put("DESCRIPTION_2", "Early Access Period") .put("FEE_2", "55") .put("DESCRIPTION_3", "Early Access Period") @@ -3142,7 +3142,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase() .put("FEE_VERSION", "0.6") .put("DESCRIPTION_1", "create") - .put("FEE_1", "26") + .put("FEE_1", "24") .put("DESCRIPTION_2", "Early Access Period") .put("FEE_2", "55") .put("DESCRIPTION_3", "Early Access Period") diff --git a/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java index 6f342aeaa..c53a8a17b 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java @@ -711,7 +711,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { "COMMAND", "create", "DESCRIPTION", "create", "PERIOD", "2", - "FEE", "26.00"), + "FEE", "24.00"), true); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java b/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java index f3eff276a..f4c3f11fd 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java @@ -145,8 +145,8 @@ public class DomainPricingLogicTest { .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) - // 13 * 2 * 0.85 == 22.1 - .addFeeOrCredit(Fee.create(Money.of(USD, 22.1).getAmount(), CREATE, false)) + // (13 + 11) * 0.85 == 20.40 + .addFeeOrCredit(Fee.create(Money.of(USD, 20.4).getAmount(), CREATE, false)) .build()); } diff --git a/core/src/test/resources/google/registry/flows/domain/domain_check_eap_fee_response_v06.xml b/core/src/test/resources/google/registry/flows/domain/domain_check_eap_fee_response_v06.xml index 1c72c9819..adac418c5 100644 --- a/core/src/test/resources/google/registry/flows/domain/domain_check_eap_fee_response_v06.xml +++ b/core/src/test/resources/google/registry/flows/domain/domain_check_eap_fee_response_v06.xml @@ -32,7 +32,7 @@ USD create 2 - 26.00 + 24.00 100.00 diff --git a/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_default_token_v06.xml b/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_default_token_v06.xml index 37b1b8cc1..8ccee8d91 100644 --- a/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_default_token_v06.xml +++ b/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_default_token_v06.xml @@ -31,7 +31,7 @@ USD create 2 - 19.50 + 17.50 diff --git a/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_v06.xml b/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_v06.xml index 97d8f6a6e..5323efe53 100644 --- a/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_v06.xml +++ b/core/src/test/resources/google/registry/flows/domain/domain_check_fee_response_v06.xml @@ -31,7 +31,7 @@ USD create 2 - 26.00 + 24.00 diff --git a/core/src/test/resources/google/registry/flows/domain/domain_create_eap_fee.xml b/core/src/test/resources/google/registry/flows/domain/domain_create_eap_fee.xml index 00f1b4a7a..35c649c1d 100644 --- a/core/src/test/resources/google/registry/flows/domain/domain_create_eap_fee.xml +++ b/core/src/test/resources/google/registry/flows/domain/domain_create_eap_fee.xml @@ -20,7 +20,7 @@ USD - 26.00 + 24.00 100.00 diff --git a/core/src/test/resources/google/registry/flows/domain/domain_create_fee.xml b/core/src/test/resources/google/registry/flows/domain/domain_create_fee.xml index 3401c1091..e8fc1ae53 100644 --- a/core/src/test/resources/google/registry/flows/domain/domain_create_fee.xml +++ b/core/src/test/resources/google/registry/flows/domain/domain_create_fee.xml @@ -20,7 +20,7 @@ %CURRENCY% - 26.00 + 24.00 ABC-12345 diff --git a/core/src/test/resources/google/registry/flows/domain/domain_create_fee_defaults.xml b/core/src/test/resources/google/registry/flows/domain/domain_create_fee_defaults.xml index 2fa821cd2..035b59254 100644 --- a/core/src/test/resources/google/registry/flows/domain/domain_create_fee_defaults.xml +++ b/core/src/test/resources/google/registry/flows/domain/domain_create_fee_defaults.xml @@ -20,7 +20,7 @@ USD - 26.00 + 24.00 ABC-12345 diff --git a/core/src/test/resources/google/registry/flows/domain/domain_create_response_eap_fee.xml b/core/src/test/resources/google/registry/flows/domain/domain_create_response_eap_fee.xml index 469be5356..5b9397f67 100644 --- a/core/src/test/resources/google/registry/flows/domain/domain_create_response_eap_fee.xml +++ b/core/src/test/resources/google/registry/flows/domain/domain_create_response_eap_fee.xml @@ -14,7 +14,7 @@ USD - 26.00 + 24.00 100.00 diff --git a/core/src/test/resources/google/registry/flows/domain_create_eap_fee.xml b/core/src/test/resources/google/registry/flows/domain_create_eap_fee.xml index 64b304d72..38aa38854 100644 --- a/core/src/test/resources/google/registry/flows/domain_create_eap_fee.xml +++ b/core/src/test/resources/google/registry/flows/domain_create_eap_fee.xml @@ -15,7 +15,7 @@ USD - 26.00 + 24.00 100.00 diff --git a/core/src/test/resources/google/registry/flows/domain_create_response_eap_fee.xml b/core/src/test/resources/google/registry/flows/domain_create_response_eap_fee.xml index a80bc2292..a2ff9ca6b 100644 --- a/core/src/test/resources/google/registry/flows/domain_create_response_eap_fee.xml +++ b/core/src/test/resources/google/registry/flows/domain_create_response_eap_fee.xml @@ -13,7 +13,7 @@ USD - 26.00 + 24.00 100.00 diff --git a/core/src/test/resources/google/registry/flows/domain_delete_response_fee.xml b/core/src/test/resources/google/registry/flows/domain_delete_response_fee.xml index d1498878d..d9f6998d4 100644 --- a/core/src/test/resources/google/registry/flows/domain_delete_response_fee.xml +++ b/core/src/test/resources/google/registry/flows/domain_delete_response_fee.xml @@ -7,7 +7,7 @@ USD - -26.00 + -24.00