diff --git a/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java b/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java index 680480660..c14a615c7 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java @@ -187,6 +187,7 @@ import org.joda.time.Duration; * @error {@link DomainFlowUtils.UnexpectedClaimsNoticeException} * @error {@link DomainFlowUtils.UnsupportedFeeAttributeException} * @error {@link DomainFlowUtils.UnsupportedMarkTypeException} + * @error {@link DomainPricingLogic.AllocationTokenInvalidForPremiumNameException} */ @ReportingSpec(ActivityReportField.DOMAIN_CREATE) public class DomainCreateFlow implements TransactionalFlow { 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 d20f2608f..22219c1a6 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java +++ b/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java @@ -14,12 +14,12 @@ package google.registry.flows.domain; -import static com.google.common.base.Preconditions.checkArgument; import static google.registry.pricing.PricingEngineProxy.getDomainFeeClass; import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost; import com.google.common.net.InternetDomainName; import google.registry.flows.EppException; +import google.registry.flows.EppException.CommandUseErrorException; import google.registry.flows.FlowScope; import google.registry.flows.custom.DomainPricingCustomLogic; import google.registry.flows.custom.DomainPricingCustomLogic.CreatePriceParameters; @@ -182,13 +182,14 @@ public final class DomainPricingLogic { } private Money getDomainCreateCostWithDiscount( - String domainName, DateTime date, int years, Optional allocationToken) { + String domainName, DateTime date, int years, Optional allocationToken) + throws EppException { DomainPrices domainPrices = PricingEngineProxy.getPricesForDomainName(domainName, date); - checkArgument( - !allocationToken.isPresent() - || allocationToken.get().getDiscountFraction() == 0.0 - || !domainPrices.isPremium(), - "A nonzero discount code cannot be applied to premium domains"); + if (allocationToken.isPresent() + && allocationToken.get().getDiscountFraction() != 0.0 + && domainPrices.isPremium()) { + throw new AllocationTokenInvalidForPremiumNameException(); + } Money oneYearCreateCost = domainPrices.getCreateCost(); Money totalDomainCreateCost = oneYearCreateCost.multipliedBy(years); // If a discount is applicable, apply it only to the first year @@ -200,4 +201,12 @@ public final class DomainPricingLogic { } return totalDomainCreateCost; } + + /** An allocation token was provided that is invalid for premium domains. */ + public static class AllocationTokenInvalidForPremiumNameException + extends CommandUseErrorException { + public AllocationTokenInvalidForPremiumNameException() { + super("A nonzero discount code cannot be applied to premium domains"); + } + } } 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 b313512d5..8f5b8e9d3 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -129,6 +129,7 @@ import google.registry.flows.domain.DomainFlowUtils.TrailingDashException; import google.registry.flows.domain.DomainFlowUtils.UnexpectedClaimsNoticeException; import google.registry.flows.domain.DomainFlowUtils.UnsupportedFeeAttributeException; import google.registry.flows.domain.DomainFlowUtils.UnsupportedMarkTypeException; +import google.registry.flows.domain.DomainPricingLogic.AllocationTokenInvalidForPremiumNameException; import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotInPromotionException; import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForRegistrarException; import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForTldException; @@ -1227,9 +1228,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase