mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 17:56:08 +02:00
Extract premium pricing to a PricingEngine interface
This refactors the existing premium list functionality into the new class StaticPremiumListPricingEngine, which implements PricingEngine. A backfill @OnLoad is provided to default existing Registry entities into the static implementation. For now there is just this one implementation. Dagger map multibinding is used to generate the total set of allowed pricing engines, and allows other parties to plug in their own implementations. The pricing engine is a required field on the Registry object. If you don't want a particular Registry to actually have a premium list, then use the static pricing engine but don't actually set a premium list. A subsequent CL will refactor the Key<PremiumList> field on the Registry entity class to be handled solely by the StaticPremiumListPricingEngine implementation. Going forward, all configuration and implementation details that are specific to a given pricing engine should be handled by that pricing engine, and not as fields on the Registry object. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=121850176
This commit is contained in:
parent
87961fbb12
commit
047bbf186e
32 changed files with 659 additions and 200 deletions
|
@ -35,6 +35,7 @@ import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.registry.Registries.findTldForName;
|
||||
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
@ -176,8 +177,7 @@ public abstract class BaseDomainCreateFlow<R extends DomainBase, B extends Build
|
|||
tldState = registry.getTldState(now);
|
||||
checkRegistryStateForTld(tld);
|
||||
domainLabel = domainName.parts().get(0);
|
||||
createCost =
|
||||
registry.getDomainCreateCost(targetId, now, getClientId(), command.getPeriod().getValue());
|
||||
createCost = getDomainCreateCost(targetId, now, getClientId(), command.getPeriod().getValue());
|
||||
// The TLD should always be the parent of the requested domain name.
|
||||
isAnchorTenantViaReservation = matchesAnchorTenantReservation(
|
||||
domainLabel, tld, command.getAuthInfo().getPw().getValue());
|
||||
|
@ -202,7 +202,7 @@ public abstract class BaseDomainCreateFlow<R extends DomainBase, B extends Build
|
|||
} else if (isClaimsCreate) {
|
||||
throw new ClaimsPeriodEndedException(tld);
|
||||
}
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, getClientId(), tld);
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, getClientId());
|
||||
}
|
||||
verifyUnitIsYears(command.getPeriod());
|
||||
verifyNotInPendingDelete(
|
||||
|
|
|
@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static google.registry.flows.domain.DomainFlowUtils.getReservationType;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
|
||||
import static google.registry.util.CollectionUtils.isNullOrEmpty;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -103,15 +104,19 @@ public class DomainAllocateFlow extends DomainCreateOrAllocateFlow {
|
|||
.setFlags(billingFlagsBuilder.add(Flag.ALLOCATION).build())
|
||||
.setTargetId(targetId)
|
||||
.setClientId(getClientId())
|
||||
.setCost(registry
|
||||
.getDomainCreateCost(targetId, now, getClientId(), command.getPeriod().getValue()))
|
||||
// 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()))
|
||||
.setPeriodYears(command.getPeriod().getValue())
|
||||
.setEventTime(now)
|
||||
// If there are no nameservers on the domain, then they get the benefit of the sunrush add
|
||||
// grace period, which is longer than the standard add grace period.
|
||||
.setBillingTime(now.plus(sunrushAddGracePeriod
|
||||
? registry.getSunrushAddGracePeriodLength()
|
||||
: registry.getAddGracePeriodLength()))
|
||||
// If there are no nameservers on the domain, then they get the benefit of the sunrush
|
||||
// add grace period, which is longer than the standard add grace period.
|
||||
.setBillingTime(
|
||||
now.plus(
|
||||
sunrushAddGracePeriod
|
||||
? registry.getSunrushAddGracePeriodLength()
|
||||
: registry.getAddGracePeriodLength()))
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
ReservationType reservationType = getReservationType(domainName);
|
||||
|
|
|
@ -18,6 +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.util.CollectionUtils.nullToEmpty;
|
||||
import static google.registry.util.DomainNameUtils.getTldFromSld;
|
||||
|
||||
|
@ -77,7 +78,7 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
|
|||
ReservationType reservationType = getReservationType(domainName);
|
||||
Registry registry = Registry.get(domainName.parent().toString());
|
||||
if (reservationType == UNRESERVED
|
||||
&& registry.isPremiumName(domainName, now, getClientId())
|
||||
&& isPremiumName(domainName, now, getClientId())
|
||||
&& registry.getPremiumPriceAckRequired()
|
||||
&& !nullToEmpty(sessionMetadata.getServiceExtensionUris()).contains(
|
||||
ServiceExtension.FEE_0_6.getUri())) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import static google.registry.flows.domain.DomainFlowUtils.updateAutorenewRecurr
|
|||
import static google.registry.model.eppoutput.Result.Code.Success;
|
||||
import static google.registry.model.eppoutput.Result.Code.SuccessWithActionPending;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -139,8 +140,7 @@ public class DomainDeleteFlow extends ResourceSyncDeleteFlow<DomainResource, Bui
|
|||
TimeOfYear recurrenceTimeOfYear =
|
||||
checkNotNull(gracePeriod.getRecurringBillingEvent()).get().getRecurrenceTimeOfYear();
|
||||
DateTime autoRenewTime = recurrenceTimeOfYear.getLastInstanceBeforeOrAt(now);
|
||||
cost = Registry.get(existingResource.getTld())
|
||||
.getDomainRenewCost(targetId, autoRenewTime, getClientId(), 1);
|
||||
cost = getDomainRenewCost(targetId, autoRenewTime, getClientId(), 1);
|
||||
} else {
|
||||
cost = checkNotNull(gracePeriod.getOneTimeBillingEvent()).get().getCost();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@ 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.tldconfig.idn.IdnLabelValidator.findValidIdnTableForTld;
|
||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||
|
@ -385,11 +388,11 @@ public class DomainFlowUtils {
|
|||
* this registrar.
|
||||
*/
|
||||
static void verifyPremiumNameIsNotBlocked(
|
||||
String domainName, DateTime priceTime, String clientId, String tld) throws EppException {
|
||||
if (Registry.get(tld).isPremiumName(domainName, priceTime, clientId)) {
|
||||
String domainName, DateTime priceTime, String clientIdentifier) throws EppException {
|
||||
if (isPremiumName(domainName, priceTime, clientIdentifier)) {
|
||||
// NB: The load of the Registar object is transactionless, which means that it should hit
|
||||
// memcache most of the time.
|
||||
if (Registrar.loadByClientId(clientId).getBlockPremiumNames()) {
|
||||
if (Registrar.loadByClientId(clientIdentifier).getBlockPremiumNames()) {
|
||||
throw new PremiumNameBlockedException();
|
||||
}
|
||||
}
|
||||
|
@ -585,7 +588,7 @@ public class DomainFlowUtils {
|
|||
.setPeriod(feeRequest.getPeriod())
|
||||
// Choose from four classes: premium, premium-collision, collision, or null (standard case).
|
||||
.setClass(emptyToNull(Joiner.on('-').skipNulls().join(
|
||||
registry.isPremiumName(domainName, now, clientIdentifier) ? "premium" : null,
|
||||
isPremiumName(domainName, now, clientIdentifier) ? "premium" : null,
|
||||
isNameCollisionInSunrise ? "collision" : null)));
|
||||
|
||||
switch (feeCommand.getCommand()) {
|
||||
|
@ -597,9 +600,7 @@ public class DomainFlowUtils {
|
|||
} else {
|
||||
builder.setFee(
|
||||
Fee.create(
|
||||
registry
|
||||
.getDomainCreateCost(domainName, now, clientIdentifier, years)
|
||||
.getAmount(),
|
||||
getDomainCreateCost(domainName, now, clientIdentifier, years).getAmount(),
|
||||
"create"));
|
||||
}
|
||||
break;
|
||||
|
@ -610,7 +611,7 @@ public class DomainFlowUtils {
|
|||
// Restores have a "renew" and a "restore" fee.
|
||||
builder.setFee(
|
||||
Fee.create(
|
||||
registry.getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
|
||||
getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
|
||||
"renew"),
|
||||
Fee.create(registry.getStandardRestoreCost().getAmount(), "restore"));
|
||||
break;
|
||||
|
@ -618,7 +619,7 @@ public class DomainFlowUtils {
|
|||
// Anything else (transfer|renew) will have a "renew" fee.
|
||||
builder.setFee(
|
||||
Fee.create(
|
||||
registry.getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
|
||||
getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
|
||||
"renew"));
|
||||
}
|
||||
}
|
||||
|
@ -634,7 +635,7 @@ public class DomainFlowUtils {
|
|||
throws EppException {
|
||||
Registry registry = Registry.get(tld);
|
||||
if (registry.getPremiumPriceAckRequired()
|
||||
&& registry.isPremiumName(domainName, priceTime, clientIdentifier)
|
||||
&& isPremiumName(domainName, priceTime, clientIdentifier)
|
||||
&& feeCommand == null) {
|
||||
throw new FeesRequiredForPremiumNameException();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
|
|||
import static google.registry.model.domain.DomainResource.MAX_REGISTRATION_YEARS;
|
||||
import static google.registry.model.eppoutput.Result.Code.Success;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
||||
import static google.registry.util.DateTimeUtils.leapSafeAddYears;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -109,8 +110,7 @@ public class DomainRenewFlow extends OwnedResourceMutateFlow<DomainResource, Ren
|
|||
existingResource.getRegistrationExpirationTime().toLocalDate())) {
|
||||
throw new IncorrectCurrentExpirationDateException();
|
||||
}
|
||||
renewCost = Registry.get(existingResource.getTld())
|
||||
.getDomainRenewCost(targetId, now, getClientId(), command.getPeriod().getValue());
|
||||
renewCost = getDomainRenewCost(targetId, now, getClientId(), command.getPeriod().getValue());
|
||||
validateFeeChallenge(
|
||||
targetId, existingResource.getTld(), now, getClientId(), feeRenew, renewCost);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyNotReserved;
|
|||
import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNotBlocked;
|
||||
import static google.registry.model.eppoutput.Result.Code.Success;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -98,11 +99,11 @@ public class DomainRestoreRequestFlow extends OwnedResourceMutateFlow<DomainReso
|
|||
checkAllowedAccessToTld(getAllowedTlds(), tld);
|
||||
if (!superuser) {
|
||||
verifyNotReserved(InternetDomainName.from(targetId), false);
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, getClientId(), tld);
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, getClientId());
|
||||
}
|
||||
feeUpdate = eppInput.getSingleExtension(FeeUpdateExtension.class);
|
||||
restoreCost = Registry.get(tld).getStandardRestoreCost();
|
||||
renewCost = Registry.get(tld).getDomainRenewCost(targetId, now, getClientId(), 1);
|
||||
renewCost = getDomainRenewCost(targetId, now, getClientId(), 1);
|
||||
validateFeeChallenge(targetId, tld, now, getClientId(), feeUpdate, restoreCost, renewCost);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToT
|
|||
import static google.registry.flows.domain.DomainFlowUtils.updateAutorenewRecurrenceEndTime;
|
||||
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -76,10 +77,10 @@ public class DomainTransferApproveFlow extends
|
|||
.setTargetId(targetId)
|
||||
.setClientId(gainingClientId)
|
||||
.setPeriodYears(extraYears)
|
||||
.setCost(Registry.get(tld).getDomainRenewCost(
|
||||
.setCost(getDomainRenewCost(
|
||||
targetId,
|
||||
transferData.getTransferRequestTime(),
|
||||
getClientId(),
|
||||
transferData.getGainingClientId(),
|
||||
extraYears))
|
||||
.setEventTime(now)
|
||||
.setBillingTime(now.plus(Registry.get(tld).getTransferGracePeriodLength()))
|
||||
|
|
|
@ -22,6 +22,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNo
|
|||
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
|
||||
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -113,8 +114,8 @@ public class DomainTransferRequestFlow
|
|||
}
|
||||
Registry registry = Registry.get(existingResource.getTld());
|
||||
automaticTransferTime = now.plus(registry.getAutomaticTransferLength());
|
||||
renewCost = registry
|
||||
.getDomainRenewCost(targetId, now, getClientId(), command.getPeriod().getValue());
|
||||
// Note that the gaining registrar is used to calculate the cost of the renewal.
|
||||
renewCost = getDomainRenewCost(targetId, now, getClientId(), command.getPeriod().getValue());
|
||||
transferBillingEvent = new BillingEvent.OneTime.Builder()
|
||||
.setReason(Reason.TRANSFER)
|
||||
.setTargetId(targetId)
|
||||
|
@ -152,7 +153,7 @@ public class DomainTransferRequestFlow
|
|||
protected final void verifyTransferRequestIsAllowed() throws EppException {
|
||||
verifyUnitIsYears(command.getPeriod());
|
||||
if (!superuser) {
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, getClientId(), existingResource.getTld());
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, getClientId());
|
||||
}
|
||||
validateFeeChallenge(
|
||||
targetId, existingResource.getTld(), now, getClientId(), feeTransfer, renewCost);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue