diff --git a/java/google/registry/tools/CreateDomainCommand.java b/java/google/registry/tools/CreateDomainCommand.java index be328afeb..5b0ee91a6 100644 --- a/java/google/registry/tools/CreateDomainCommand.java +++ b/java/google/registry/tools/CreateDomainCommand.java @@ -16,23 +16,34 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; +import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; +import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.template.soy.data.SoyMapData; +import google.registry.model.pricing.PremiumPricingEngine.DomainPrices; +import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.soy.DomainCreateSoyInfo; import google.registry.util.StringGenerator; import javax.inject.Inject; +import org.joda.money.Money; +import org.joda.time.DateTime; /** A command to create a new domain via EPP. */ @Parameters(separators = " =", commandDescription = "Create a new domain via EPP.") -final class CreateDomainCommand extends CreateOrUpdateDomainCommand { +final class CreateDomainCommand extends CreateOrUpdateDomainCommand implements RemoteApiCommand { @Parameter( names = "--period", description = "Initial registration period, in years.") - private Integer period; + private int period = 1; + + @Parameter( + names = "--force_premiums", + description = "Force the creation of premium domains.") + private boolean forcePremiums; @Inject StringGenerator passwordGenerator; @@ -49,17 +60,36 @@ final class CreateDomainCommand extends CreateOrUpdateDomainCommand { } for (String domain : domains) { + String currency = null; + String cost = null; + DomainPrices prices = getPricesForDomainName(domain, DateTime.now(UTC)); + + // Check if the domain is premium and set the fee on the create command if so. + if (prices.isPremium()) { + checkArgument( + !force || forcePremiums, + "Forced creates on premium domain(s) require --force_premiums"); + Money createCost = prices.getCreateCost(); + currency = createCost.getCurrencyUnit().getCurrencyCode(); + cost = createCost.multipliedBy(period).getAmount().toString(); + System.out.printf( + "NOTE: %s is premium at %s per year; sending total cost for %d year(s) of %s %s.\n", + domain, createCost, period, currency, cost); + } + setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE); addSoyRecord( clientId, new SoyMapData( "domain", domain, - "period", period == null ? null : period.toString(), + "period", period, "nameservers", nameservers, "registrant", registrant, "admins", admins, "techs", techs, "password", password, + "currency", currency, + "price", cost, "dsRecords", DsRecord.convertToSoy(dsRecords))); } } diff --git a/java/google/registry/tools/soy/DomainCreate.soy b/java/google/registry/tools/soy/DomainCreate.soy index f4455f8d7..fc34d4516 100644 --- a/java/google/registry/tools/soy/DomainCreate.soy +++ b/java/google/registry/tools/soy/DomainCreate.soy @@ -18,12 +18,14 @@ */ {template .domaincreate stricthtml="false"} {@param domain: string} - {@param? period: string} + {@param period: int} {@param nameservers: list} {@param registrant: string} {@param admins: list} {@param techs: list} {@param password: string} + {@param? currency: string} + {@param? price: string} {@param dsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>} @@ -32,9 +34,7 @@ {$domain} - {if $period} - {$period} - {/if} + {$period} {if length($nameservers) > 0} {for $s in $nameservers} @@ -54,18 +54,26 @@ - {if length($dsRecords) > 0} + {if length($dsRecords) > 0 or $price != null} - - {for $dsRecord in $dsRecords} - - {$dsRecord.keyTag} - {$dsRecord.alg} - {$dsRecord.digestType} - {$dsRecord.digest} - - {/for} - + {if $price != null} + + {$currency} + {$price} + + {/if} + {if length($dsRecords) > 0} + + {for $dsRecord in $dsRecords} + + {$dsRecord.keyTag} + {$dsRecord.alg} + {$dsRecord.digestType} + {$dsRecord.digest} + + {/for} + + {/if} {/if} RegistryTool diff --git a/javatests/google/registry/testing/default_premium_list_testdata.csv b/javatests/google/registry/testing/default_premium_list_testdata.csv index edd206e01..f96e0db6f 100644 --- a/javatests/google/registry/testing/default_premium_list_testdata.csv +++ b/javatests/google/registry/testing/default_premium_list_testdata.csv @@ -10,3 +10,4 @@ palladium,USD 877 aluminum,USD 11 copper,USD 15 brass,USD 20 +parajiumu,JPY 96083 diff --git a/javatests/google/registry/tools/CreateDomainCommandTest.java b/javatests/google/registry/tools/CreateDomainCommandTest.java index 5aae9d23b..9ce514acb 100644 --- a/javatests/google/registry/tools/CreateDomainCommandTest.java +++ b/javatests/google/registry/tools/CreateDomainCommandTest.java @@ -15,6 +15,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.JUnitBackports.assertThrows; import com.beust.jcommander.ParameterException; @@ -60,6 +61,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--admins=crr-admin", + "--techs=crr-tech", + "gold.tld")); + assertThat(thrown) + .hasMessageThat() + .isEqualTo("Forced creates on premium domain(s) require --force_premiums"); + } } diff --git a/javatests/google/registry/tools/server/testdata/domain_create_minimal.xml b/javatests/google/registry/tools/server/testdata/domain_create_minimal.xml index d01b94656..c04c1e1a8 100644 --- a/javatests/google/registry/tools/server/testdata/domain_create_minimal.xml +++ b/javatests/google/registry/tools/server/testdata/domain_create_minimal.xml @@ -5,6 +5,7 @@ example.tld + 1 crr-admin crr-admin crr-tech diff --git a/javatests/google/registry/tools/server/testdata/domain_create_minimal_abc.xml b/javatests/google/registry/tools/server/testdata/domain_create_minimal_abc.xml index 09b6a0343..af23b7156 100644 --- a/javatests/google/registry/tools/server/testdata/domain_create_minimal_abc.xml +++ b/javatests/google/registry/tools/server/testdata/domain_create_minimal_abc.xml @@ -5,6 +5,7 @@ example.abc + 1 crr-admin crr-admin crr-tech diff --git a/javatests/google/registry/tools/server/testdata/domain_create_palladium.xml b/javatests/google/registry/tools/server/testdata/domain_create_palladium.xml new file mode 100644 index 000000000..e5e2ff288 --- /dev/null +++ b/javatests/google/registry/tools/server/testdata/domain_create_palladium.xml @@ -0,0 +1,25 @@ + + + + + + palladium.tld + 1 + crr-admin + crr-admin + crr-tech + + abcdefghijklmnop + + + + + + USD + 877.00 + + + RegistryTool + + diff --git a/javatests/google/registry/tools/server/testdata/domain_create_parajiumu_3yrs.xml b/javatests/google/registry/tools/server/testdata/domain_create_parajiumu_3yrs.xml new file mode 100644 index 000000000..e02091f8b --- /dev/null +++ b/javatests/google/registry/tools/server/testdata/domain_create_parajiumu_3yrs.xml @@ -0,0 +1,25 @@ + + + + + + parajiumu.tld + 3 + crr-admin + crr-admin + crr-tech + + abcdefghijklmnop + + + + + + JPY + 288249 + + + RegistryTool + +