Add premium support to nomulus create_domain command

Premium prices are automatically detected and set, with an informational
message displayed to the user prior to executing the command.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=199223541
This commit is contained in:
mcilwain 2018-06-04 17:43:17 -07:00 committed by Ben McIlwain
parent 61f6e666b1
commit 7c0b8cab0b
8 changed files with 165 additions and 18 deletions

View file

@ -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)));
}
}

View file

@ -18,12 +18,14 @@
*/
{template .domaincreate stricthtml="false"}
{@param domain: string}
{@param? period: string}
{@param period: int}
{@param nameservers: list<string>}
{@param registrant: string}
{@param admins: list<string>}
{@param techs: list<string>}
{@param password: string}
{@param? currency: string}
{@param? price: string}
{@param dsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@ -32,9 +34,7 @@
<create>
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>{$domain}</domain:name>
{if $period}
<domain:period unit="y">{$period}</domain:period>
{/if}
{if length($nameservers) > 0}
<domain:ns>
{for $s in $nameservers}
@ -54,8 +54,15 @@
</domain:authInfo>
</domain:create>
</create>
{if length($dsRecords) > 0}
{if length($dsRecords) > 0 or $price != null}
<extension>
{if $price != null}
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
<fee:currency>{$currency}</fee:currency>
<fee:fee>{$price}</fee:fee>
</fee:create>
{/if}
{if length($dsRecords) > 0}
<secDNS:create xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
{for $dsRecord in $dsRecords}
<secDNS:dsData>
@ -66,6 +73,7 @@
</secDNS:dsData>
{/for}
</secDNS:create>
{/if}
</extension>
{/if}
<clTRID>RegistryTool</clTRID>

View file

@ -10,3 +10,4 @@ palladium,USD 877
aluminum,USD 11
copper,USD 15
brass,USD 20
parajiumu,JPY 96083

1 rich USD 100
10 aluminum USD 11
11 copper USD 15
12 brass USD 20
13 parajiumu JPY 96083

View file

@ -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<CreateDomain
@Test
public void testSuccess_multipleDomains() throws Exception {
createTld("abc");
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
@ -72,6 +74,43 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
.verifySent("domain_create_minimal_abc.xml");
}
@Test
public void testSuccess_premiumDomain() throws Exception {
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admins=crr-admin",
"--techs=crr-tech",
"--period=3",
"--force_premiums",
"parajiumu.tld");
eppVerifier.verifySent("domain_create_parajiumu_3yrs.xml");
assertInStdout(
"parajiumu.tld is premium at JPY 96083 per year; "
+ "sending total cost for 3 year(s) of JPY 288249.");
}
@Test
public void testSuccess_multipleDomainsWithPremium() throws Exception {
createTld("abc");
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admins=crr-admin",
"--techs=crr-tech",
"--force_premiums",
"example.tld",
"palladium.tld",
"example.abc");
eppVerifier
.verifySent("domain_create_minimal.xml")
.verifySent("domain_create_palladium.xml")
.verifySent("domain_create_minimal_abc.xml");
assertInStdout(
"palladium.tld is premium at USD 877.00 per year; "
+ "sending total cost for 1 year(s) of USD 877.00.");
}
@Test
public void testFailure_duplicateDomains() throws Exception {
IllegalArgumentException thrown =
@ -288,4 +327,21 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
"example.tld"));
assertThat(thrown).hasMessageThat().contains("length 5");
}
@Test
public void testFailure_cantForceCreatePremiumDomain_withoutForcePremiums() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() ->
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");
}
}

View file

@ -5,6 +5,7 @@
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:period unit="y">1</domain:period>
<domain:registrant>crr-admin</domain:registrant>
<domain:contact type="admin">crr-admin</domain:contact>
<domain:contact type="tech">crr-tech</domain:contact>

View file

@ -5,6 +5,7 @@
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.abc</domain:name>
<domain:period unit="y">1</domain:period>
<domain:registrant>crr-admin</domain:registrant>
<domain:contact type="admin">crr-admin</domain:contact>
<domain:contact type="tech">crr-tech</domain:contact>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>palladium.tld</domain:name>
<domain:period unit="y">1</domain:period>
<domain:registrant>crr-admin</domain:registrant>
<domain:contact type="admin">crr-admin</domain:contact>
<domain:contact type="tech">crr-tech</domain:contact>
<domain:authInfo>
<domain:pw>abcdefghijklmnop</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<extension>
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
<fee:currency>USD</fee:currency>
<fee:fee>877.00</fee:fee>
</fee:create>
</extension>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>parajiumu.tld</domain:name>
<domain:period unit="y">3</domain:period>
<domain:registrant>crr-admin</domain:registrant>
<domain:contact type="admin">crr-admin</domain:contact>
<domain:contact type="tech">crr-tech</domain:contact>
<domain:authInfo>
<domain:pw>abcdefghijklmnop</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<extension>
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
<fee:currency>JPY</fee:currency>
<fee:fee>288249</fee:fee>
</fee:create>
</extension>
<clTRID>RegistryTool</clTRID>
</command>
</epp>