Reconcile FeesAndCredits handling in price customization

Also adds a mechanism to ensure that fee extensions are included when custom
pricing logic adds a custom fee, and fixes up the domain restore flow to
properly use the restore price.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=142715136
This commit is contained in:
mcilwain 2016-12-21 16:44:08 -08:00 committed by Ben McIlwain
parent 720f03cc17
commit 9d9c527917
19 changed files with 312 additions and 182 deletions

View file

@ -54,8 +54,7 @@ import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.Superuser;
import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.TransactionalFlow;
import google.registry.flows.domain.DomainFlowUtils.FeesRequiredForNonFreeUpdateException;
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
import google.registry.flows.domain.DomainFlowUtils.FeesRequiredForNonFreeOperationException;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainCommand.Update;
@ -75,7 +74,6 @@ import google.registry.model.eppoutput.EppResponse;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import javax.inject.Inject;
import org.joda.money.Money;
import org.joda.time.DateTime;
/**
@ -188,12 +186,11 @@ public class DomainApplicationUpdateFlow implements TransactionalFlow {
// If the fee extension is present, validate it (even if the cost is zero, to check for price
// mismatches). Don't rely on the the validateFeeChallenge check for feeUpdate nullness, because
// it throws an error if the name is premium, and we don't want to do that here.
Money totalCost = feesAndCredits.getTotalCost();
if (feeUpdate != null) {
validateFeeChallenge(targetId, tld, now, feeUpdate, totalCost);
} else if (!totalCost.isZero()) {
validateFeeChallenge(targetId, tld, now, feeUpdate, feesAndCredits);
} else if (!feesAndCredits.getTotalCost().isZero()) {
// If it's not present but the cost is not zero, throw an exception.
throw new FeesRequiredForNonFreeUpdateException();
throw new FeesRequiredForNonFreeOperationException(feesAndCredits.getTotalCost());
}
verifyNotInPendingDelete(
add.getContacts(),