diff --git a/java/google/registry/model/domain/fee/BaseFee.java b/java/google/registry/model/domain/fee/BaseFee.java index 17a0e411b..4e74c3948 100644 --- a/java/google/registry/model/domain/fee/BaseFee.java +++ b/java/google/registry/model/domain/fee/BaseFee.java @@ -28,7 +28,7 @@ import org.joda.time.Period; /** Base class for the fee and credit types. */ @XmlTransient -public class BaseFee extends ImmutableObject { +public abstract class BaseFee extends ImmutableObject { /** Enum for when a fee is applied. */ public enum AppliedType { @@ -71,6 +71,13 @@ public class BaseFee extends ImmutableObject { return firstNonNull(refundable, true); } + /** + * According to the fee extension specification, a fee must always be non-negative, while a credit + * must always be negative. Essentially, they are the same thing, just with different sign. + * However, we need them to be separate classes for proper JAXB handling. + * + * @see "https://tools.ietf.org/html/draft-brown-epp-fees-03#section-2.4" + */ public BigDecimal getCost() { return cost; } diff --git a/java/google/registry/model/domain/fee/Credit.java b/java/google/registry/model/domain/fee/Credit.java index 1e34d3c36..ce64e0aac 100644 --- a/java/google/registry/model/domain/fee/Credit.java +++ b/java/google/registry/model/domain/fee/Credit.java @@ -14,6 +14,7 @@ package google.registry.model.domain.fee; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.math.BigDecimal; @@ -23,6 +24,7 @@ public class Credit extends BaseFee { public static Credit create(BigDecimal cost, String description) { Credit instance = new Credit(); instance.cost = checkNotNull(cost); + checkArgument(instance.cost.signum() < 0); instance.description = description; return instance; } diff --git a/java/google/registry/model/domain/fee/Fee.java b/java/google/registry/model/domain/fee/Fee.java index d90cf2748..a64fcad3f 100644 --- a/java/google/registry/model/domain/fee/Fee.java +++ b/java/google/registry/model/domain/fee/Fee.java @@ -14,6 +14,7 @@ package google.registry.model.domain.fee; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableList; @@ -41,6 +42,7 @@ public class Fee extends BaseFee { public static Fee create(BigDecimal cost, String description) { Fee instance = new Fee(); instance.cost = checkNotNull(cost); + checkArgument(instance.cost.signum() >= 0); instance.description = description; return instance; }