Add additional return values to PricingEngine interface

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123658519
This commit is contained in:
mcilwain 2016-05-31 10:47:02 -07:00 committed by Ben McIlwain
parent ca585dd0b5
commit 91f6c7006e
21 changed files with 191 additions and 191 deletions

View file

@ -181,7 +181,7 @@ public abstract class BaseDomainCreateFlow<R extends DomainBase, B extends Build
tldState = registry.getTldState(now);
checkRegistryStateForTld(tld);
domainLabel = domainName.parts().get(0);
createCost = getDomainCreateCost(targetId, now, getClientId(), command.getPeriod().getValue());
createCost = getDomainCreateCost(targetId, now, command.getPeriod().getValue());
// The TLD should always be the parent of the requested domain name.
isAnchorTenantViaReservation = matchesAnchorTenantReservation(
domainLabel, tld, command.getAuthInfo().getPw().getValue());

View file

@ -106,8 +106,7 @@ public class DomainAllocateFlow extends DomainCreateOrAllocateFlow {
.setClientId(getClientId())
// Note that the cost is calculated as of now, i.e. the event time, not the billing time,
// which may be some additional days into the future.
.setCost(
getDomainCreateCost(targetId, now, getClientId(), command.getPeriod().getValue()))
.setCost(getDomainCreateCost(targetId, now, command.getPeriod().getValue()))
.setPeriodYears(command.getPeriod().getValue())
.setEventTime(now)
// If there are no nameservers on the domain, then they get the benefit of the sunrush

View file

@ -139,7 +139,7 @@ public class DomainApplicationCreateFlow extends BaseDomainCreateFlow<DomainAppl
@Override
protected void verifyDomainCreateIsAllowed() throws EppException {
validateFeeChallenge(targetId, getTld(), now, getClientId(), feeCreate, createCost);
validateFeeChallenge(targetId, getTld(), now, feeCreate, createCost);
if (tldState == TldState.LANDRUSH && !superuser) {
// Prohibit creating a landrush application in LANDRUSH (but not in SUNRUSH) if there is
// exactly one sunrise application for the same name.

View file

@ -18,7 +18,7 @@ import static google.registry.flows.domain.DomainFlowUtils.getReservationType;
import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.registry.label.ReservationType.UNRESERVED;
import static google.registry.pricing.PricingEngineProxy.isPremiumName;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
@ -83,7 +83,7 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
ReservationType reservationType = getReservationType(domainName);
Registry registry = Registry.get(domainName.parent().toString());
if (reservationType == UNRESERVED
&& isPremiumName(domainName, now, getClientId())
&& getPricesForDomainName(domainName.toString(), now).isPremium()
&& registry.getPremiumPriceAckRequired()
&& !nullToEmpty(sessionMetadata.getServiceExtensionUris()).contains(
ServiceExtension.FEE_0_6.getUri())) {
@ -121,7 +121,7 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
}
FeeCheck.Builder builder = new FeeCheck.Builder();
handleFeeRequest(
domainCheck, builder, domainName, getTldFromDomainName(domainName), getClientId(), now);
domainCheck, builder, domainName, getTldFromDomainName(domainName), now);
feeChecksBuilder.add(builder.setName(domainName).build());
}
return ImmutableList.of(FeeCheckResponseExtension.create(feeChecksBuilder.build()));

View file

@ -108,7 +108,7 @@ public class DomainCreateFlow extends DomainCreateOrAllocateFlow {
@Override
protected final void verifyDomainCreateIsAllowed() throws EppException {
String tld = getTld();
validateFeeChallenge(targetId, tld, now, getClientId(), feeCreate, createCost);
validateFeeChallenge(targetId, tld, now, feeCreate, createCost);
if (!superuser) {
// Prohibit creating a domain if there is an open application for the same name.
for (DomainApplication application : loadActiveApplicationsByDomainName(targetId, now)) {

View file

@ -139,7 +139,7 @@ public class DomainDeleteFlow extends ResourceSyncDeleteFlow<DomainResource, Bui
TimeOfYear recurrenceTimeOfYear =
checkNotNull(gracePeriod.getRecurringBillingEvent()).get().getRecurrenceTimeOfYear();
DateTime autoRenewTime = recurrenceTimeOfYear.getLastInstanceBeforeOrAt(now);
cost = getDomainRenewCost(targetId, autoRenewTime, getClientId(), 1);
cost = getDomainRenewCost(targetId, autoRenewTime, 1);
} else {
cost = checkNotNull(gracePeriod.getOneTimeBillingEvent()).get().getCost();
}

View file

@ -17,7 +17,6 @@ package google.registry.flows.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Sets.difference;
@ -25,9 +24,7 @@ import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.findTldForName;
import static google.registry.model.registry.label.ReservedList.getReservation;
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
import static google.registry.pricing.PricingEngineProxy.isPremiumName;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
import static google.registry.tldconfig.idn.IdnLabelValidator.findValidIdnTableForTld;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DateTimeUtils.isAtOrAfter;
@ -82,6 +79,7 @@ import google.registry.model.mark.Mark;
import google.registry.model.mark.ProtectedMark;
import google.registry.model.mark.Trademark;
import google.registry.model.poll.PollMessage;
import google.registry.model.pricing.PricingEngine.DomainPrices;
import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
@ -286,7 +284,6 @@ public class DomainFlowUtils {
throw new TooManyNameserversException(String.format(
"Only %d nameservers are allowed per domain", MAX_NAMESERVERS_PER_DOMAIN));
}
}
static void validateNoDuplicateContacts(Set<DesignatedContact> contacts)
@ -388,7 +385,7 @@ public class DomainFlowUtils {
*/
static void verifyPremiumNameIsNotBlocked(
String domainName, DateTime priceTime, String clientIdentifier) throws EppException {
if (isPremiumName(domainName, priceTime, clientIdentifier)) {
if (getPricesForDomainName(domainName, priceTime).isPremium()) {
// NB: The load of the Registar object is transactionless, which means that it should hit
// memcache most of the time.
if (Registrar.loadByClientId(clientIdentifier).getBlockPremiumNames()) {
@ -563,15 +560,12 @@ public class DomainFlowUtils {
BaseFeeResponse.Builder<?, ?> builder,
String domainName,
String tld,
String clientIdentifier,
DateTime now) throws EppException {
InternetDomainName domain = InternetDomainName.from(domainName);
FeeCommandDescriptor feeCommand = feeRequest.getCommand();
Registry registry = Registry.get(tld);
int years = verifyUnitIsYears(feeRequest.getPeriod()).getValue();
boolean isSunrise = registry.getTldState(now).equals(TldState.SUNRISE);
boolean isNameCollisionInSunrise =
isSunrise && getReservationType(domain) == ReservationType.NAME_COLLISION;
if (feeCommand.getPhase() != null || feeCommand.getSubphase() != null) {
throw new FeeChecksDontSupportPhasesException();
@ -581,14 +575,13 @@ public class DomainFlowUtils {
throw new CurrencyUnitMismatchException();
}
DomainPrices prices = getPricesForDomainName(domainName, now);
builder
.setCommand(feeCommand)
.setCurrency(registry.getCurrency())
.setPeriod(feeRequest.getPeriod())
// Choose from four classes: premium, premium-collision, collision, or null (standard case).
.setClass(emptyToNull(Joiner.on('-').skipNulls().join(
isPremiumName(domainName, now, clientIdentifier) ? "premium" : null,
isNameCollisionInSunrise ? "collision" : null)));
.setClass(prices.getFeeClass().orNull());
switch (feeCommand.getCommand()) {
case UNKNOWN:
@ -598,9 +591,7 @@ public class DomainFlowUtils {
builder.setClass("reserved"); // Override whatever class we've set above.
} else {
builder.setFee(
Fee.create(
getDomainCreateCost(domainName, now, clientIdentifier, years).getAmount(),
"create"));
Fee.create(prices.getCreateCost().multipliedBy(years).getAmount(), "create"));
}
break;
case RESTORE:
@ -609,17 +600,12 @@ public class DomainFlowUtils {
}
// Restores have a "renew" and a "restore" fee.
builder.setFee(
Fee.create(
getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
"renew"),
Fee.create(prices.getRenewCost().multipliedBy(years).getAmount(), "renew"),
Fee.create(registry.getStandardRestoreCost().getAmount(), "restore"));
break;
default:
// Anything else (transfer|renew) will have a "renew" fee.
builder.setFee(
Fee.create(
getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
"renew"));
builder.setFee(Fee.create(prices.getRenewCost().multipliedBy(years).getAmount(), "renew"));
}
}
@ -627,14 +613,13 @@ public class DomainFlowUtils {
String domainName,
String tld,
DateTime priceTime,
String clientIdentifier,
final BaseFeeCommand feeCommand,
Money cost,
Money... otherCosts)
throws EppException {
Registry registry = Registry.get(tld);
if (registry.getPremiumPriceAckRequired()
&& isPremiumName(domainName, priceTime, clientIdentifier)
&& getPricesForDomainName(domainName, priceTime).isPremium()
&& feeCommand == null) {
throw new FeesRequiredForPremiumNameException();
}
@ -1021,4 +1006,3 @@ public class DomainFlowUtils {
}
}
}

View file

@ -95,7 +95,7 @@ public class DomainInfoFlow extends BaseDomainInfoFlow<DomainResource, Builder>
if (feeInfo != null) { // Fee check was requested.
FeeInfoResponseExtension.Builder builder = new FeeInfoResponseExtension.Builder();
handleFeeRequest(
feeInfo, builder, getTargetId(), existingResource.getTld(), getClientId(), now);
feeInfo, builder, getTargetId(), existingResource.getTld(), now);
extensions.add(builder.build());
}
if (!registrationTypes.isEmpty()) {

View file

@ -110,9 +110,9 @@ public class DomainRenewFlow extends OwnedResourceMutateFlow<DomainResource, Ren
existingResource.getRegistrationExpirationTime().toLocalDate())) {
throw new IncorrectCurrentExpirationDateException();
}
renewCost = getDomainRenewCost(targetId, now, getClientId(), command.getPeriod().getValue());
renewCost = getDomainRenewCost(targetId, now, command.getPeriod().getValue());
validateFeeChallenge(
targetId, existingResource.getTld(), now, getClientId(), feeRenew, renewCost);
targetId, existingResource.getTld(), now, feeRenew, renewCost);
}
@Override

View file

@ -103,8 +103,8 @@ public class DomainRestoreRequestFlow extends OwnedResourceMutateFlow<DomainReso
}
feeUpdate = eppInput.getSingleExtension(FeeUpdateExtension.class);
restoreCost = Registry.get(tld).getStandardRestoreCost();
renewCost = getDomainRenewCost(targetId, now, getClientId(), 1);
validateFeeChallenge(targetId, tld, now, getClientId(), feeUpdate, restoreCost, renewCost);
renewCost = getDomainRenewCost(targetId, now, 1);
validateFeeChallenge(targetId, tld, now, feeUpdate, restoreCost, renewCost);
}
@Override

View file

@ -72,20 +72,18 @@ public class DomainTransferApproveFlow extends
String tld = existingResource.getTld();
int extraYears = transferData.getExtendedRegistrationYears();
// Bill for the transfer.
BillingEvent.OneTime billingEvent = new BillingEvent.OneTime.Builder()
.setReason(Reason.TRANSFER)
.setTargetId(targetId)
.setClientId(gainingClientId)
.setPeriodYears(extraYears)
.setCost(getDomainRenewCost(
targetId,
transferData.getTransferRequestTime(),
transferData.getGainingClientId(),
extraYears))
.setEventTime(now)
.setBillingTime(now.plus(Registry.get(tld).getTransferGracePeriodLength()))
.setParent(historyEntry)
.build();
BillingEvent.OneTime billingEvent =
new BillingEvent.OneTime.Builder()
.setReason(Reason.TRANSFER)
.setTargetId(targetId)
.setClientId(gainingClientId)
.setPeriodYears(extraYears)
.setCost(
getDomainRenewCost(targetId, transferData.getTransferRequestTime(), extraYears))
.setEventTime(now)
.setBillingTime(now.plus(Registry.get(tld).getTransferGracePeriodLength()))
.setParent(historyEntry)
.build();
ofy().save().entity(billingEvent);
// If we are within an autorenew grace period, cancel the autorenew billing event and reduce
// the number of years to extend the registration by one.

View file

@ -115,7 +115,7 @@ public class DomainTransferRequestFlow
Registry registry = Registry.get(existingResource.getTld());
automaticTransferTime = now.plus(registry.getAutomaticTransferLength());
// Note that the gaining registrar is used to calculate the cost of the renewal.
renewCost = getDomainRenewCost(targetId, now, getClientId(), command.getPeriod().getValue());
renewCost = getDomainRenewCost(targetId, now, command.getPeriod().getValue());
transferBillingEvent = new BillingEvent.OneTime.Builder()
.setReason(Reason.TRANSFER)
.setTargetId(targetId)
@ -156,7 +156,7 @@ public class DomainTransferRequestFlow
verifyPremiumNameIsNotBlocked(targetId, now, getClientId());
}
validateFeeChallenge(
targetId, existingResource.getTld(), now, getClientId(), feeTransfer, renewCost);
targetId, existingResource.getTld(), now, feeTransfer, renewCost);
checkAllowedAccessToTld(getAllowedTlds(), existingResource.getTld());
}