mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 17:37:13 +02:00
Add additional return values to PricingEngine interface
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123658519
This commit is contained in:
parent
ca585dd0b5
commit
91f6c7006e
21 changed files with 191 additions and 191 deletions
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -72,16 +72,14 @@ public class DomainTransferApproveFlow extends
|
|||
String tld = existingResource.getTld();
|
||||
int extraYears = transferData.getExtendedRegistrationYears();
|
||||
// Bill for the transfer.
|
||||
BillingEvent.OneTime billingEvent = new BillingEvent.OneTime.Builder()
|
||||
BillingEvent.OneTime billingEvent =
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setReason(Reason.TRANSFER)
|
||||
.setTargetId(targetId)
|
||||
.setClientId(gainingClientId)
|
||||
.setPeriodYears(extraYears)
|
||||
.setCost(getDomainRenewCost(
|
||||
targetId,
|
||||
transferData.getTransferRequestTime(),
|
||||
transferData.getGainingClientId(),
|
||||
extraYears))
|
||||
.setCost(
|
||||
getDomainRenewCost(targetId, transferData.getTransferRequestTime(), extraYears))
|
||||
.setEventTime(now)
|
||||
.setBillingTime(now.plus(Registry.get(tld).getTransferGracePeriodLength()))
|
||||
.setParent(historyEntry)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,70 @@ import org.joda.time.DateTime;
|
|||
public interface PricingEngine {
|
||||
|
||||
/**
|
||||
* Returns the premium price for the given domain name at the given time for the given registrar,
|
||||
* or absent if the domain name isn't premium.
|
||||
* Returns the prices for the given fully qualified domain name at the given time.
|
||||
*
|
||||
* <p>Note that fullyQualifiedDomainName must not include any subdomains. It should be a single
|
||||
* level above the TLD (which may be multi-part).
|
||||
* <p>Note that the fullyQualifiedDomainName must only contain a single part left of the TLD, i.e.
|
||||
* subdomains are not allowed, but multi-part TLDs are.
|
||||
*/
|
||||
public Optional<Money> getPremiumPrice(
|
||||
String fullyQualifiedDomainName, DateTime priceTime, String clientIdentifier);
|
||||
public DomainPrices getDomainPrices(String fullyQualifiedDomainName, DateTime priceTime);
|
||||
|
||||
/**
|
||||
* A class containing information on prices for a specific domain name.
|
||||
*
|
||||
* <p>Any implementation of PricingEngine is responsible for determining all of these.
|
||||
*/
|
||||
public static class DomainPrices {
|
||||
|
||||
private boolean isPremium;
|
||||
// TODO(b/26901539): Refactor return values to support an arbitrary list of costs for each of
|
||||
// create, renew, restore, and transfer.
|
||||
private Money createCost;
|
||||
private Money renewCost;
|
||||
private Optional<Money> oneTimeFee;
|
||||
private Optional<String> feeClass;
|
||||
|
||||
static DomainPrices create(
|
||||
boolean isPremium,
|
||||
Money createCost,
|
||||
Money renewCost,
|
||||
Optional<Money> oneTimeFee,
|
||||
Optional<String> feeClass) {
|
||||
DomainPrices instance = new DomainPrices();
|
||||
instance.isPremium = isPremium;
|
||||
instance.createCost = createCost;
|
||||
instance.renewCost = renewCost;
|
||||
instance.oneTimeFee = oneTimeFee;
|
||||
instance.feeClass = feeClass;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** Returns whether the domain is premium. */
|
||||
public boolean isPremium() {
|
||||
return isPremium;
|
||||
}
|
||||
|
||||
/** Returns the cost to create the domain. */
|
||||
public Money getCreateCost() {
|
||||
return createCost;
|
||||
}
|
||||
|
||||
/** Returns the cost to renew the domain. */
|
||||
public Money getRenewCost() {
|
||||
return renewCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the one time fee to register a domain if there is one.
|
||||
*
|
||||
* <p>This is primarily used for EAP registration fees.
|
||||
*/
|
||||
public Optional<Money> getOneTimeFee() {
|
||||
return oneTimeFee;
|
||||
}
|
||||
|
||||
/** Returns the fee class of the cost (used for the Fee extension). */
|
||||
public Optional<String> getFeeClass() {
|
||||
return feeClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,13 @@ package google.registry.model.pricing;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static google.registry.model.registry.Registry.TldState.SUNRISE;
|
||||
import static google.registry.model.registry.label.ReservationType.NAME_COLLISION;
|
||||
import static google.registry.model.registry.label.ReservedList.getReservation;
|
||||
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
||||
|
@ -35,19 +40,28 @@ public final class StaticPremiumListPricingEngine implements PricingEngine {
|
|||
@Inject StaticPremiumListPricingEngine() {}
|
||||
|
||||
@Override
|
||||
public Optional<Money> getPremiumPrice(
|
||||
String fullyQualifiedDomainName, DateTime priceTime, String clientIdentifier) {
|
||||
// Note that clientIdentifier and priceTime are not used for determining premium pricing for
|
||||
// static premium lists.
|
||||
public DomainPrices getDomainPrices(String fullyQualifiedDomainName, DateTime priceTime) {
|
||||
String tld = getTldFromDomainName(fullyQualifiedDomainName);
|
||||
String label = InternetDomainName.from(fullyQualifiedDomainName).parts().get(0);
|
||||
Registry registry = Registry.get(checkNotNull(tld, "tld"));
|
||||
if (registry.getPremiumList() == null) {
|
||||
return Optional.<Money>absent();
|
||||
}
|
||||
Optional<Money> premiumPrice = Optional.<Money>absent();
|
||||
if (registry.getPremiumList() != null) {
|
||||
String listName = registry.getPremiumList().getName();
|
||||
Optional<PremiumList> premiumList = PremiumList.get(listName);
|
||||
checkState(premiumList.isPresent(), "Could not load premium list: %s", listName);
|
||||
String label = InternetDomainName.from(fullyQualifiedDomainName).parts().get(0);
|
||||
return premiumList.get().getPremiumPrice(label);
|
||||
premiumPrice = premiumList.get().getPremiumPrice(label);
|
||||
}
|
||||
boolean isNameCollisionInSunrise =
|
||||
registry.getTldState(priceTime).equals(SUNRISE)
|
||||
&& getReservation(label, tld) == NAME_COLLISION;
|
||||
String feeClass = emptyToNull(Joiner.on('-').skipNulls().join(
|
||||
premiumPrice.isPresent() ? "premium" : null,
|
||||
isNameCollisionInSunrise ? "collision" : null));
|
||||
return DomainPrices.create(
|
||||
premiumPrice.isPresent(),
|
||||
premiumPrice.or(registry.getStandardCreateCost()),
|
||||
premiumPrice.or(registry.getStandardRenewCost(priceTime)),
|
||||
Optional.<Money>absent(),
|
||||
Optional.<String>fromNullable(feeClass));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,16 +16,14 @@ package google.registry.pricing;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.model.registry.Registries.assertTldExists;
|
||||
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
||||
import google.registry.model.pricing.PricingEngine;
|
||||
import google.registry.model.pricing.PricingEngine.DomainPrices;
|
||||
import google.registry.model.registry.Registry;
|
||||
|
||||
import org.joda.money.Money;
|
||||
|
@ -54,53 +52,29 @@ public final class PricingEngineProxy {
|
|||
return pricingEngine.getClass().getCanonicalName();
|
||||
}});
|
||||
|
||||
/** Returns true if the given domain name is on the premium price list. */
|
||||
public static boolean isPremiumName(
|
||||
String domainName, DateTime priceTime, String clientIdentifier) {
|
||||
return isPremiumName(InternetDomainName.from(domainName), priceTime, clientIdentifier);
|
||||
}
|
||||
|
||||
/** Returns true if the given domain name is on the premium price list. */
|
||||
public static boolean isPremiumName(
|
||||
InternetDomainName domainName, DateTime priceTime, String clientIdentifier) {
|
||||
return getPremiumPriceForDomainName(domainName, priceTime, clientIdentifier).isPresent();
|
||||
}
|
||||
|
||||
/** Returns the billing cost for registering the specified domain name for this many years. */
|
||||
public static Money getDomainCreateCost(
|
||||
String domainName, DateTime priceTime, String clientIdentifier, int years) {
|
||||
public static Money getDomainCreateCost(String domainName, DateTime priceTime, int years) {
|
||||
checkArgument(years > 0, "Number of years must be positive");
|
||||
Optional<Money> annualCost =
|
||||
getPremiumPriceForDomainName(
|
||||
InternetDomainName.from(domainName), priceTime, clientIdentifier);
|
||||
return annualCost
|
||||
.or(Registry.get(getTldFromDomainName(domainName)).getStandardCreateCost())
|
||||
.multipliedBy(years);
|
||||
return getPricesForDomainName(domainName, priceTime).getCreateCost().multipliedBy(years);
|
||||
}
|
||||
|
||||
/** Returns the billing cost for renewing the specified domain name for this many years. */
|
||||
public static Money getDomainRenewCost(
|
||||
String domainName, DateTime priceTime, String clientIdentifier, int years) {
|
||||
public static Money getDomainRenewCost(String domainName, DateTime priceTime, int years) {
|
||||
checkArgument(years > 0, "Number of years must be positive");
|
||||
Optional<Money> annualCost =
|
||||
getPremiumPriceForDomainName(
|
||||
InternetDomainName.from(domainName), priceTime, clientIdentifier);
|
||||
return annualCost
|
||||
.or(Registry.get(getTldFromDomainName(domainName)).getStandardRenewCost(priceTime))
|
||||
.multipliedBy(years);
|
||||
return getPricesForDomainName(domainName, priceTime).getRenewCost().multipliedBy(years);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given domain name is premium by dispatching to the appropriate
|
||||
* {@link PricingEngine} based on what is configured for the TLD that the domain is under.
|
||||
* Returns the full {@link DomainPrices} details for the given domain name by dispatching to the
|
||||
* appropriate {@link PricingEngine} based on what is configured for the TLD that the domain is
|
||||
* under.
|
||||
*/
|
||||
private static Optional<Money> getPremiumPriceForDomainName(
|
||||
InternetDomainName domainName, DateTime priceTime, String clientIdentifier) {
|
||||
String tld = assertTldExists(getTldFromDomainName(domainName));
|
||||
public static DomainPrices getPricesForDomainName(String domainName, DateTime priceTime) {
|
||||
String tld = getTldFromDomainName(domainName);
|
||||
String clazz = Registry.get(tld).getPricingEngineClassName();
|
||||
PricingEngine engine = pricingEngines.get(clazz);
|
||||
checkState(engine != null, "Could not load pricing engine %s for TLD %s", clazz, tld);
|
||||
return engine.getPremiumPrice(domainName.toString(), priceTime, clientIdentifier);
|
||||
return engine.getDomainPrices(domainName, priceTime);
|
||||
}
|
||||
|
||||
private PricingEngineProxy() {}
|
||||
|
|
|
@ -88,9 +88,7 @@ final class CreateAnchorTenantCommand extends MutatingEppToolCommand implements
|
|||
|
||||
Money cost = null;
|
||||
if (fee) {
|
||||
cost =
|
||||
getDomainCreateCost(
|
||||
domainName, DateTime.now(UTC), clientIdentifier, DEFAULT_ANCHOR_TENANT_PERIOD_YEARS);
|
||||
cost = getDomainCreateCost(domainName, DateTime.now(UTC), DEFAULT_ANCHOR_TENANT_PERIOD_YEARS);
|
||||
}
|
||||
|
||||
setSoyTemplate(CreateAnchorTenantSoyInfo.getInstance(),
|
||||
|
|
|
@ -43,7 +43,10 @@ public final class DomainNameUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the canonicalized TLD part of a valid domain name by stripping off the leftmost part.
|
||||
* Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the
|
||||
* leftmost part.
|
||||
*
|
||||
* <p>This method should not be called for subdomains.
|
||||
*
|
||||
* <p>This function is compatible with multi-part tlds, e.g. {@code co.uk}. This function will
|
||||
* also work on domains for which the registry is not authoritative. If you are certain that the
|
||||
|
@ -51,28 +54,28 @@ public final class DomainNameUtils {
|
|||
* {@link google.registry.model.registry.Registries#findTldForName(InternetDomainName)
|
||||
* Registries#findTldForName}, which will work on hostnames in addition to domains.
|
||||
*
|
||||
* @param fullyQualifiedDomainName must be a puny-coded domain name (not a subdomain or Unicode)
|
||||
* @param fullyQualifiedDomainName must be a punycode SLD (not a host or unicode)
|
||||
* @throws IllegalArgumentException if there is no TLD
|
||||
*/
|
||||
public static String getTldFromDomainName(String fullyQualifiedDomainName) {
|
||||
checkArgument(
|
||||
!Strings.isNullOrEmpty(fullyQualifiedDomainName),
|
||||
"fullyQualifiedDomainName cannot be null or empty");
|
||||
"secondLevelDomainName cannot be null or empty");
|
||||
return getTldFromDomainName(InternetDomainName.from(fullyQualifiedDomainName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the canonicalized TLD part of a valid domain name by stripping off the leftmost part.
|
||||
* Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the
|
||||
* leftmost part.
|
||||
*
|
||||
* <p>This function is compatible with multi-part TLDs and must not be called with subdomains.
|
||||
* <p>This function is compatible with multi-part TLDs and should not be called with subdomains.
|
||||
*
|
||||
* @throws IllegalArgumentException if there is no TLD
|
||||
*/
|
||||
public static String getTldFromDomainName(InternetDomainName fullyQualifiedDomainName) {
|
||||
checkArgumentNotNull(fullyQualifiedDomainName);
|
||||
checkArgument(
|
||||
fullyQualifiedDomainName.hasParent(), "fullyQualifiedDomainName does not have a TLD");
|
||||
return fullyQualifiedDomainName.parent().toString();
|
||||
public static String getTldFromDomainName(InternetDomainName domainName) {
|
||||
checkArgumentNotNull(domainName);
|
||||
checkArgument(domainName.hasParent(), "secondLevelDomainName does not have a TLD");
|
||||
return domainName.parent().toString();
|
||||
}
|
||||
|
||||
private DomainNameUtils() {}
|
||||
|
|
|
@ -16,7 +16,7 @@ package google.registry.flows.domain;
|
|||
|
||||
import static com.google.common.io.BaseEncoding.base16;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.pricing.PricingEngineProxy.isPremiumName;
|
||||
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
|
||||
import static google.registry.testing.DatastoreHelper.assertBillingEvents;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.deleteTld;
|
||||
|
@ -180,7 +180,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
.setReason(Reason.CREATE)
|
||||
.setTargetId(getUniqueIdFromCommand())
|
||||
.setClientId("TheRegistrar")
|
||||
.setCost(isPremiumName(getUniqueIdFromCommand(), clock.nowUtc(), "TheRegistrar")
|
||||
.setCost(getPricesForDomainName(getUniqueIdFromCommand(), clock.nowUtc()).isPremium()
|
||||
? Money.of(USD, 200)
|
||||
: Money.of(USD, 26))
|
||||
.setPeriodYears(2)
|
||||
|
|
|
@ -180,7 +180,6 @@ public class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
|
|||
return createBillingEventForTransfer(
|
||||
domain,
|
||||
historyEntry,
|
||||
"NewRegistrar",
|
||||
TRANSFER_REQUEST_TIME,
|
||||
TRANSFER_EXPIRATION_TIME,
|
||||
EXTENDED_REGISTRATION_YEARS);
|
||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.pricing;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
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.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
|
@ -26,6 +26,7 @@ import static org.joda.money.CurrencyUnit.USD;
|
|||
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
|
||||
import google.registry.model.pricing.PricingEngine;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.label.PremiumList;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
|
@ -68,34 +69,34 @@ public class PricingEngineProxyTest {
|
|||
|
||||
@Test
|
||||
public void test_getDomainCreateCost_multipleYears() {
|
||||
assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.parse("USD 13"));
|
||||
assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 5))
|
||||
assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 5))
|
||||
.isEqualTo(Money.parse("USD 65"));
|
||||
assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.parse("USD 20.50"));
|
||||
assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 3))
|
||||
assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), 3))
|
||||
.isEqualTo(Money.parse("USD 61.50"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getDomainRenewCost_multipleYears() {
|
||||
assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.parse("USD 11"));
|
||||
assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 5))
|
||||
assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 5))
|
||||
.isEqualTo(Money.parse("USD 55"));
|
||||
assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.parse("USD 20.50"));
|
||||
assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 3))
|
||||
assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), 3))
|
||||
.isEqualTo(Money.parse("USD 61.50"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPremiumDomain() throws Exception {
|
||||
createTld("example");
|
||||
assertThat(isPremiumName("poor.example", clock.nowUtc(), "TheRegistrar")).isFalse();
|
||||
assertThat(isPremiumName("rich.example", clock.nowUtc(), "TheRegistrar")).isTrue();
|
||||
assertThat(isPremiumName("richer.example", clock.nowUtc(), "TheRegistrar")).isTrue();
|
||||
assertThat(getPricesForDomainName("poor.example", clock.nowUtc()).isPremium()).isFalse();
|
||||
assertThat(getPricesForDomainName("rich.example", clock.nowUtc()).isPremium()).isTrue();
|
||||
assertThat(getPricesForDomainName("richer.example", clock.nowUtc()).isPremium()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -103,13 +104,13 @@ public class PricingEngineProxyTest {
|
|||
// The example tld has a premium price for "rich".
|
||||
createTld("example");
|
||||
// The default value of 17 is set in createTld().
|
||||
assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.of(USD, 13));
|
||||
assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 2))
|
||||
assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 2))
|
||||
.isEqualTo(Money.of(USD, 26));
|
||||
assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.of(USD, 100));
|
||||
assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 2))
|
||||
assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 2))
|
||||
.isEqualTo(Money.of(USD, 200));
|
||||
}
|
||||
|
||||
|
@ -124,60 +125,36 @@ public class PricingEngineProxyTest {
|
|||
ImmutableSortedMap.of(
|
||||
START_OF_TIME, Money.of(USD, 8), clock.nowUtc(), Money.of(USD, 10)))
|
||||
.build());
|
||||
assertThat(getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 1))
|
||||
assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 1))
|
||||
.isEqualTo(Money.of(USD, 8));
|
||||
assertThat(getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 2))
|
||||
assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 2))
|
||||
.isEqualTo(Money.of(USD, 16));
|
||||
assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.of(USD, 10));
|
||||
assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 2))
|
||||
assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 2))
|
||||
.isEqualTo(Money.of(USD, 20));
|
||||
assertThat(getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 1))
|
||||
assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 1))
|
||||
.isEqualTo(Money.of(USD, 100));
|
||||
assertThat(getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 2))
|
||||
assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 2))
|
||||
.isEqualTo(Money.of(USD, 200));
|
||||
assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 1))
|
||||
assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 1))
|
||||
.isEqualTo(Money.of(USD, 100));
|
||||
assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 2))
|
||||
assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 2))
|
||||
.isEqualTo(Money.of(USD, 200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_isPremiumNameForSldNotUnderTld() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
isPremiumName("test.example", clock.nowUtc(), "TheRegistrar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_isPremiumNameForSldSubdomain() throws Exception {
|
||||
public void testFailure_cantLoadPricingEngine() throws Exception {
|
||||
createTld("example");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
isPremiumName("rich.sld.example", clock.nowUtc(), "TheRegistrar");
|
||||
persistResource(
|
||||
Registry.get("example").asBuilder().setPricingEngineClass(FakePricingEngine.class).build());
|
||||
thrown.expect(
|
||||
IllegalStateException.class,
|
||||
String.format(
|
||||
"Could not load pricing engine %s for TLD example",
|
||||
FakePricingEngine.class.getCanonicalName()));
|
||||
getDomainCreateCost("bad.example", clock.nowUtc(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_getCreateCostForSldNotUnderTld() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
getDomainCreateCost("test.example", clock.nowUtc(), "TheRegistrar", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_getCreateCostForSldSubdomain() throws Exception {
|
||||
createTld("example");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
getDomainCreateCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_getRenewCostForSldNotUnderTld() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
getDomainRenewCost("test.example", clock.nowUtc(), "TheRegistrar", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_getRenewCostForSldSubdomain() throws Exception {
|
||||
createTld("example");
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
getDomainRenewCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1);
|
||||
}
|
||||
private abstract static class FakePricingEngine implements PricingEngine {}
|
||||
}
|
||||
|
|
|
@ -428,7 +428,6 @@ public class DatastoreHelper {
|
|||
public static BillingEvent.OneTime createBillingEventForTransfer(
|
||||
DomainResource domain,
|
||||
HistoryEntry historyEntry,
|
||||
String gainingClientId,
|
||||
DateTime costLookupTime,
|
||||
DateTime eventTime,
|
||||
Integer extendedRegistrationYears) {
|
||||
|
@ -440,11 +439,9 @@ public class DatastoreHelper {
|
|||
eventTime.plus(Registry.get(domain.getTld()).getTransferGracePeriodLength()))
|
||||
.setClientId("NewRegistrar")
|
||||
.setPeriodYears(extendedRegistrationYears)
|
||||
.setCost(getDomainRenewCost(
|
||||
domain.getFullyQualifiedDomainName(),
|
||||
costLookupTime,
|
||||
gainingClientId,
|
||||
extendedRegistrationYears))
|
||||
.setCost(
|
||||
getDomainRenewCost(
|
||||
domain.getFullyQualifiedDomainName(), costLookupTime, extendedRegistrationYears))
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
}
|
||||
|
@ -505,7 +502,6 @@ public class DatastoreHelper {
|
|||
BillingEvent.OneTime transferBillingEvent = persistResource(createBillingEventForTransfer(
|
||||
domain,
|
||||
historyEntryDomainTransfer,
|
||||
"NewRegistrar",
|
||||
requestTime,
|
||||
expirationTime,
|
||||
extendedRegistrationYears));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue