diff --git a/java/google/registry/flows/domain/BaseDomainCreateFlow.java b/java/google/registry/flows/domain/BaseDomainCreateFlow.java index 5df93bee7..57a87f2d4 100644 --- a/java/google/registry/flows/domain/BaseDomainCreateFlow.java +++ b/java/google/registry/flows/domain/BaseDomainCreateFlow.java @@ -176,7 +176,8 @@ public abstract class BaseDomainCreateFlow 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(); } diff --git a/java/google/registry/flows/domain/DomainInfoFlow.java b/java/google/registry/flows/domain/DomainInfoFlow.java index bc3b52ca1..189946bb1 100644 --- a/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/java/google/registry/flows/domain/DomainInfoFlow.java @@ -87,7 +87,8 @@ public class DomainInfoFlow extends BaseDomainInfoFlow 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(); diff --git a/java/google/registry/flows/domain/DomainRenewFlow.java b/java/google/registry/flows/domain/DomainRenewFlow.java index 8b397ad32..467611095 100644 --- a/java/google/registry/flows/domain/DomainRenewFlow.java +++ b/java/google/registry/flows/domain/DomainRenewFlow.java @@ -110,8 +110,9 @@ public class DomainRenewFlow extends OwnedResourceMutateFlow 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); } diff --git a/java/google/registry/tools/CreateAnchorTenantCommand.java b/java/google/registry/tools/CreateAnchorTenantCommand.java index 9d6bc7178..d4944e0b6 100644 --- a/java/google/registry/tools/CreateAnchorTenantCommand.java +++ b/java/google/registry/tools/CreateAnchorTenantCommand.java @@ -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(), diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index 7e0c36774..3abb55d67 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -179,9 +179,10 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase return createBillingEventForTransfer( domain, historyEntry, + "NewRegistrar", TRANSFER_REQUEST_TIME, TRANSFER_EXPIRATION_TIME, EXTENDED_REGISTRATION_YEARS); diff --git a/javatests/google/registry/model/registry/RegistryTest.java b/javatests/google/registry/model/registry/RegistryTest.java index de0d55b95..55fbd9918 100644 --- a/javatests/google/registry/model/registry/RegistryTest.java +++ b/javatests/google/registry/model/registry/RegistryTest.java @@ -311,9 +311,9 @@ public class RegistryTest extends EntityTestCase { public void testIsPremiumDomain() throws Exception { createTld("example"); Registry registry = Registry.get("example"); - assertThat(registry.isPremiumName("poor.example")).isFalse(); - assertThat(registry.isPremiumName("rich.example")).isTrue(); - assertThat(registry.isPremiumName("richer.example")).isTrue(); + assertThat(registry.isPremiumName("poor.example", clock.nowUtc(), "TheRegistrar")).isFalse(); + assertThat(registry.isPremiumName("rich.example", clock.nowUtc(), "TheRegistrar")).isTrue(); + assertThat(registry.isPremiumName("richer.example", clock.nowUtc(), "TheRegistrar")).isTrue(); } public void testGetDomainCreateCost() throws Exception { @@ -321,10 +321,14 @@ public class RegistryTest extends EntityTestCase { createTld("example"); Registry registry = Registry.get("example"); // The default value of 17 is set in createTld(). - assertThat(registry.getDomainCreateCost("poor.example", 1)).isEqualTo(Money.of(USD, 13)); - assertThat(registry.getDomainCreateCost("poor.example", 2)).isEqualTo(Money.of(USD, 26)); - assertThat(registry.getDomainCreateCost("rich.example", 1)).isEqualTo(Money.of(USD, 100)); - assertThat(registry.getDomainCreateCost("rich.example", 2)).isEqualTo(Money.of(USD, 200)); + assertThat(registry.getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 1)) + .isEqualTo(Money.of(USD, 13)); + assertThat(registry.getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 2)) + .isEqualTo(Money.of(USD, 26)); + assertThat(registry.getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 1)) + .isEqualTo(Money.of(USD, 100)); + assertThat(registry.getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 2)) + .isEqualTo(Money.of(USD, 200)); } @Test @@ -336,21 +340,21 @@ public class RegistryTest extends EntityTestCase { START_OF_TIME, Money.of(USD, 8), clock.nowUtc(), Money.of(USD, 10))) .build(); - assertThat(registry.getDomainRenewCost("poor.example", 1, START_OF_TIME)) + assertThat(registry.getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 1)) .isEqualTo(Money.of(USD, 8)); - assertThat(registry.getDomainRenewCost("poor.example", 2, START_OF_TIME)) + assertThat(registry.getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 2)) .isEqualTo(Money.of(USD, 16)); - assertThat(registry.getDomainRenewCost("poor.example", 1, clock.nowUtc())) + assertThat(registry.getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 1)) .isEqualTo(Money.of(USD, 10)); - assertThat(registry.getDomainRenewCost("poor.example", 2, clock.nowUtc())) + assertThat(registry.getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 2)) .isEqualTo(Money.of(USD, 20)); - assertThat(registry.getDomainRenewCost("rich.example", 1, START_OF_TIME)) + assertThat(registry.getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 1)) .isEqualTo(Money.of(USD, 100)); - assertThat(registry.getDomainRenewCost("rich.example", 2, START_OF_TIME)) + assertThat(registry.getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 2)) .isEqualTo(Money.of(USD, 200)); - assertThat(registry.getDomainRenewCost("rich.example", 1, clock.nowUtc())) + assertThat(registry.getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 1)) .isEqualTo(Money.of(USD, 100)); - assertThat(registry.getDomainRenewCost("rich.example", 2, clock.nowUtc())) + assertThat(registry.getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 2)) .isEqualTo(Money.of(USD, 200)); } @@ -454,39 +458,41 @@ public class RegistryTest extends EntityTestCase { @Test public void testFailure_isPremiumNameForSldNotUnderTld() { thrown.expect(IllegalArgumentException.class); - Registry.get("tld").isPremiumName("test.example"); + Registry.get("tld").isPremiumName("test.example", clock.nowUtc(), "TheRegistrar"); } @Test public void testFailure_isPremiumNameForSldSubdomain() throws Exception { createTld("example"); thrown.expect(IllegalArgumentException.class); - Registry.get("example").isPremiumName("rich.sld.example"); + Registry.get("example").isPremiumName("rich.sld.example", clock.nowUtc(), "TheRegistrar"); } @Test public void testFailure_getCreateCostForSldNotUnderTld() { thrown.expect(IllegalArgumentException.class); - Registry.get("tld").getDomainCreateCost("test.example", 1); + Registry.get("tld").getDomainCreateCost("test.example", clock.nowUtc(), "TheRegistrar", 1); } @Test public void testFailure_getCreateCostForSldSubdomain() throws Exception { createTld("example"); thrown.expect(IllegalArgumentException.class); - Registry.get("example").getDomainCreateCost("rich.sld.example", 1); + Registry.get("example") + .getDomainCreateCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1); } @Test public void testFailure_getRenewCostForSldNotUnderTld() { thrown.expect(IllegalArgumentException.class); - Registry.get("tld").getDomainRenewCost("test.example", 1, clock.nowUtc()); + Registry.get("tld").getDomainRenewCost("test.example", clock.nowUtc(), "TheRegistrar", 1); } @Test public void testFailure_getRenewCostForSldSubdomain() throws Exception { createTld("example"); thrown.expect(IllegalArgumentException.class); - Registry.get("example").getDomainRenewCost("rich.sld.example", 1, clock.nowUtc()); + Registry.get("example") + .getDomainRenewCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1); } } diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index f4735a2c8..e74475376 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -424,6 +424,7 @@ public class DatastoreHelper { public static BillingEvent.OneTime createBillingEventForTransfer( DomainResource domain, HistoryEntry historyEntry, + String gainingClientId, DateTime costLookupTime, DateTime eventTime, Integer extendedRegistrationYears) { @@ -437,8 +438,9 @@ public class DatastoreHelper { .setPeriodYears(extendedRegistrationYears) .setCost(Registry.get(domain.getTld()).getDomainRenewCost( domain.getFullyQualifiedDomainName(), - extendedRegistrationYears, - costLookupTime)) + costLookupTime, + gainingClientId, + extendedRegistrationYears)) .setParent(historyEntry) .build(); } @@ -499,6 +501,7 @@ public class DatastoreHelper { BillingEvent.OneTime transferBillingEvent = persistResource(createBillingEventForTransfer( domain, historyEntryDomainTransfer, + "NewRegistrar", requestTime, expirationTime, extendedRegistrationYears));