Support creation of EPP fee objects using custom descriptions

This is a reasonable thing that custom code might want to do (Donuts already has
a use case).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144216929
This commit is contained in:
mcilwain 2017-01-11 09:49:07 -08:00 committed by Ben McIlwain
parent 3ee98988c5
commit a5d5c9e2fd
3 changed files with 32 additions and 16 deletions

View file

@ -16,17 +16,27 @@ package google.registry.model.domain.fee;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import java.math.BigDecimal;
/** A credit, in currency units specified elsewhere in the xml, and with an optional description. */
public class Credit extends BaseFee {
/** Creates a Credit for the given amount and type with the default description. */
public static Credit create(BigDecimal cost, FeeType type, Object... descriptionArgs) {
checkArgumentNotNull(type, "Must specify the type of the credit");
return createWithCustomDescription(cost, type, type.renderDescription(descriptionArgs));
}
/** Creates a Credit for the given amount and type with a custom description. */
public static Credit createWithCustomDescription(
BigDecimal cost, FeeType type, String description) {
Credit instance = new Credit();
instance.cost = checkNotNull(cost);
checkArgument(instance.cost.signum() < 0);
instance.type = checkNotNull(type);
instance.generateDescription(descriptionArgs);
instance.description = description;
return instance;
}
}