Add clientId and time parameters to pricing methods

This is a broken-out refactoring from []
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=121603352
This commit is contained in:
mcilwain 2016-05-05 12:19:50 -07:00 committed by Justine Tunney
parent 4a9be60e0b
commit 6f69e96465
18 changed files with 105 additions and 62 deletions

View file

@ -176,7 +176,8 @@ 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, command.getPeriod().getValue());
createCost =
registry.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());
@ -201,7 +202,7 @@ public abstract class BaseDomainCreateFlow<R extends DomainBase, B extends Build
} else if (isClaimsCreate) {
throw new ClaimsPeriodEndedException(tld);
}
verifyPremiumNameIsNotBlocked(targetId, tld, getClientId());
verifyPremiumNameIsNotBlocked(targetId, now, getClientId(), tld);
}
verifyUnitIsYears(command.getPeriod());
verifyNotInPendingDelete(

View file

@ -103,7 +103,8 @@ public class DomainAllocateFlow extends DomainCreateOrAllocateFlow {
.setFlags(billingFlagsBuilder.add(Flag.ALLOCATION).build())
.setTargetId(targetId)
.setClientId(getClientId())
.setCost(registry.getDomainCreateCost(targetId, command.getPeriod().getValue()))
.setCost(registry
.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

View file

@ -139,7 +139,7 @@ public class DomainApplicationCreateFlow extends BaseDomainCreateFlow<DomainAppl
@Override
protected void verifyDomainCreateIsAllowed() throws EppException {
validateFeeChallenge(targetId, getTld(), feeCreate, createCost);
validateFeeChallenge(targetId, getTld(), now, getClientId(), 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

@ -77,7 +77,7 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
ReservationType reservationType = getReservationType(domainName);
Registry registry = Registry.get(domainName.parent().toString());
if (reservationType == UNRESERVED
&& registry.isPremiumName(domainName)
&& registry.isPremiumName(domainName, now, getClientId())
&& registry.getPremiumPriceAckRequired()
&& !nullToEmpty(sessionMetadata.getServiceExtensionUris()).contains(
ServiceExtension.FEE_0_6.getUri())) {
@ -114,7 +114,8 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
throw new OnlyCheckedNamesCanBeFeeCheckedException();
}
FeeCheck.Builder builder = new FeeCheck.Builder();
handleFeeRequest(domainCheck, builder, domainName, getTldFromSld(domainName), now);
handleFeeRequest(
domainCheck, builder, domainName, getTldFromSld(domainName), getClientId(), now);
feeChecksBuilder.add(builder.setName(domainName).build());
}
return ImmutableList.of(FeeCheckResponseExtension.create(feeChecksBuilder.build()));

View file

@ -105,7 +105,7 @@ public class DomainCreateFlow extends DomainCreateOrAllocateFlow {
@Override
protected final void verifyDomainCreateIsAllowed() throws EppException {
String tld = getTld();
validateFeeChallenge(targetId, tld, feeCreate, createCost);
validateFeeChallenge(targetId, tld, now, getClientId(), 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

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

View file

@ -384,9 +384,9 @@ public class DomainFlowUtils {
* where it would not be allowed is if domain name is premium, and premium names are blocked by
* this registrar.
*/
static void verifyPremiumNameIsNotBlocked(String domainName, String tld, String clientId)
throws EppException {
if (Registry.get(tld).isPremiumName(domainName)) {
static void verifyPremiumNameIsNotBlocked(
String domainName, DateTime priceTime, String clientId, String tld) throws EppException {
if (Registry.get(tld).isPremiumName(domainName, priceTime, clientId)) {
// 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()) {
@ -561,6 +561,7 @@ 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();
@ -584,7 +585,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) ? "premium" : null,
registry.isPremiumName(domainName, now, clientIdentifier) ? "premium" : null,
isNameCollisionInSunrise ? "collision" : null)));
switch (feeCommand.getCommand()) {
@ -595,7 +596,11 @@ public class DomainFlowUtils {
builder.setClass("reserved"); // Override whatever class we've set above.
} else {
builder.setFee(
Fee.create(registry.getDomainCreateCost(domainName, years).getAmount(), "create"));
Fee.create(
registry
.getDomainCreateCost(domainName, now, clientIdentifier, years)
.getAmount(),
"create"));
}
break;
case RESTORE:
@ -604,23 +609,32 @@ public class DomainFlowUtils {
}
// Restores have a "renew" and a "restore" fee.
builder.setFee(
Fee.create(registry.getDomainRenewCost(domainName, years, now).getAmount(), "renew"),
Fee.create(
registry.getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
"renew"),
Fee.create(registry.getStandardRestoreCost().getAmount(), "restore"));
break;
default:
// Anything else (transfer|renew) will have a "renew" fee.
builder.setFee(
Fee.create(registry.getDomainRenewCost(domainName, years, now).getAmount(), "renew"));
Fee.create(
registry.getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(),
"renew"));
}
}
static void validateFeeChallenge(
String domainName, String tld,
String domainName,
String tld,
DateTime priceTime,
String clientIdentifier,
final BaseFeeCommand feeCommand,
Money cost, Money... otherCosts) throws EppException {
Money cost,
Money... otherCosts)
throws EppException {
Registry registry = Registry.get(tld);
if (registry.getPremiumPriceAckRequired()
&& registry.isPremiumName(domainName)
&& registry.isPremiumName(domainName, priceTime, clientIdentifier)
&& feeCommand == null) {
throw new FeesRequiredForPremiumNameException();
}

View file

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

View file

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

View file

@ -98,12 +98,12 @@ public class DomainRestoreRequestFlow extends OwnedResourceMutateFlow<DomainReso
checkAllowedAccessToTld(getAllowedTlds(), tld);
if (!superuser) {
verifyNotReserved(InternetDomainName.from(targetId), false);
verifyPremiumNameIsNotBlocked(targetId, tld, getClientId());
verifyPremiumNameIsNotBlocked(targetId, now, getClientId(), tld);
}
feeUpdate = eppInput.getSingleExtension(FeeUpdateExtension.class);
restoreCost = Registry.get(tld).getStandardRestoreCost();
renewCost = Registry.get(tld).getDomainRenewCost(targetId, 1, now);
validateFeeChallenge(targetId, tld, feeUpdate, restoreCost, renewCost);
renewCost = Registry.get(tld).getDomainRenewCost(targetId, now, getClientId(), 1);
validateFeeChallenge(targetId, tld, now, getClientId(), feeUpdate, restoreCost, renewCost);
}
@Override

View file

@ -78,8 +78,9 @@ public class DomainTransferApproveFlow extends
.setPeriodYears(extraYears)
.setCost(Registry.get(tld).getDomainRenewCost(
targetId,
extraYears,
transferData.getTransferRequestTime()))
transferData.getTransferRequestTime(),
getClientId(),
extraYears))
.setEventTime(now)
.setBillingTime(now.plus(Registry.get(tld).getTransferGracePeriodLength()))
.setParent(historyEntry)

View file

@ -113,7 +113,8 @@ public class DomainTransferRequestFlow
}
Registry registry = Registry.get(existingResource.getTld());
automaticTransferTime = now.plus(registry.getAutomaticTransferLength());
renewCost = registry.getDomainRenewCost(targetId, command.getPeriod().getValue(), now);
renewCost = registry
.getDomainRenewCost(targetId, now, getClientId(), command.getPeriod().getValue());
transferBillingEvent = new BillingEvent.OneTime.Builder()
.setReason(Reason.TRANSFER)
.setTargetId(targetId)
@ -151,9 +152,10 @@ public class DomainTransferRequestFlow
protected final void verifyTransferRequestIsAllowed() throws EppException {
verifyUnitIsYears(command.getPeriod());
if (!superuser) {
verifyPremiumNameIsNotBlocked(targetId, existingResource.getTld(), getClientId());
verifyPremiumNameIsNotBlocked(targetId, now, getClientId(), existingResource.getTld());
}
validateFeeChallenge(targetId, existingResource.getTld(), feeTransfer, renewCost);
validateFeeChallenge(
targetId, existingResource.getTld(), now, getClientId(), feeTransfer, renewCost);
checkAllowedAccessToTld(getAllowedTlds(), existingResource.getTld());
}

View file

@ -492,26 +492,32 @@ public class Registry extends ImmutableObject implements Buildable {
}
/** Returns true if the given domain name is on the premium price list. */
public boolean isPremiumName(String domainName) {
return isPremiumName(InternetDomainName.from(domainName));
public 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 boolean isPremiumName(InternetDomainName domainName) {
@SuppressWarnings("unused")
public boolean isPremiumName(
InternetDomainName domainName, DateTime priceTime, String clientIdentifier) {
return getPremiumPriceForSld(domainName).isPresent();
}
/** Returns the billing cost for registering the specified domain name for this many years. */
public Money getDomainCreateCost(String domainName, int years) {
@SuppressWarnings("unused")
public Money getDomainCreateCost(
String domainName, DateTime priceTime, String clientIdentifier, int years) {
checkArgument(years > 0, "Number of years must be positive");
Money annualCost = getPremiumPriceForSld(domainName).or(getStandardCreateCost());
return annualCost.multipliedBy(years);
}
/** Returns the billing cost for renewing the specified domain name for this many years. */
public Money getDomainRenewCost(String domainName, int years, DateTime now) {
@SuppressWarnings("unused")
public Money getDomainRenewCost(
String domainName, DateTime priceTime, String clientIdentifier, int years) {
checkArgument(years > 0, "Number of years must be positive");
Money annualCost = getPremiumPriceForSld(domainName).or(getStandardRenewCost(now));
Money annualCost = getPremiumPriceForSld(domainName).or(getStandardRenewCost(priceTime));
return annualCost.multipliedBy(years);
}

View file

@ -17,6 +17,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static google.registry.model.registry.Registries.findTldForNameOrThrow;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.net.InternetDomainName;
import com.google.template.soy.data.SoyMapData;
@ -29,6 +30,7 @@ import google.registry.tools.Command.GtechCommand;
import google.registry.tools.soy.CreateAnchorTenantSoyInfo;
import org.joda.money.Money;
import org.joda.time.DateTime;
import javax.inject.Inject;
@ -86,7 +88,9 @@ final class CreateAnchorTenantCommand extends MutatingEppToolCommand implements
Money cost = null;
if (fee) {
cost = Registry.get(tld).getDomainCreateCost(domainName, DEFAULT_ANCHOR_TENANT_PERIOD_YEARS);
cost = Registry.get(tld)
.getDomainCreateCost(
domainName, DateTime.now(UTC), clientIdentifier, DEFAULT_ANCHOR_TENANT_PERIOD_YEARS);
}
setSoyTemplate(CreateAnchorTenantSoyInfo.getInstance(),