Show price of reserved domains when using matching allocation token (#632)

* Show price of reserved domains when using matching allocation token

When the registrar passes the fee extension, this shows the price of the domain
on a check command for reserved domains if the provided allocation token is a
match. Of course, the price is already always displayed on non-reserved names
(regardless of whether the specific provided token is a match or not).

This affects domain checks only; the price is already always displayed on domain
creates because you already by definition have access to register the domain in
question.
This commit is contained in:
Ben McIlwain
2020-06-18 11:57:22 -04:00
committed by GitHub
parent d43564172f
commit 57113b4746
7 changed files with 151 additions and 9 deletions
@@ -163,7 +163,8 @@ public final class DomainCheckFlow implements Flow {
clientId,
now));
ImmutableList.Builder<DomainCheck> checks = new ImmutableList.Builder<>();
ImmutableList.Builder<DomainCheck> checksBuilder = new ImmutableList.Builder<>();
ImmutableSet.Builder<String> availableDomains = new ImmutableSet.Builder<>();
ImmutableMap<String, TldState> tldStates =
Maps.toMap(seenTlds, tld -> Registry.get(tld).getTldState(now));
ImmutableMap<InternetDomainName, String> domainCheckResults =
@@ -180,13 +181,19 @@ public final class DomainCheckFlow implements Flow {
domainCheckResults,
tldStates,
allocationToken);
checks.add(DomainCheck.create(!message.isPresent(), targetId, message.orElse(null)));
boolean isAvailable = !message.isPresent();
checksBuilder.add(DomainCheck.create(isAvailable, targetId, message.orElse(null)));
if (isAvailable) {
availableDomains.add(targetId);
}
}
BeforeResponseReturnData responseData =
flowCustomLogic.beforeResponse(
BeforeResponseParameters.newBuilder()
.setDomainChecks(checks.build())
.setResponseExtensions(getResponseExtensions(domainNames, now, allocationToken))
.setDomainChecks(checksBuilder.build())
.setResponseExtensions(
getResponseExtensions(
domainNames, availableDomains.build(), now, allocationToken))
.setAsOfDate(now)
.build());
return responseBuilder
@@ -221,6 +228,7 @@ public final class DomainCheckFlow implements Flow {
/** Handle the fee check extension. */
private ImmutableList<? extends ResponseExtension> getResponseExtensions(
ImmutableMap<String, InternetDomainName> domainNames,
ImmutableSet<String> availableDomains,
DateTime now,
Optional<AllocationToken> allocationToken)
throws EppException {
@@ -242,7 +250,8 @@ public final class DomainCheckFlow implements Flow {
feeCheck.getCurrency(),
now,
pricingLogic,
allocationToken);
allocationToken,
availableDomains.contains(domainName));
responseItems.add(builder.setDomainNameIfSupported(domainName).build());
}
}
@@ -555,7 +555,8 @@ public class DomainFlowUtils {
@Nullable CurrencyUnit topLevelCurrency,
DateTime currentDate,
DomainPricingLogic pricingLogic,
Optional<AllocationToken> allocationToken)
Optional<AllocationToken> allocationToken,
boolean isAvailable)
throws EppException {
DateTime now = currentDate;
// Use the custom effective date specified in the fee check request, if there is one.
@@ -587,7 +588,8 @@ public class DomainFlowUtils {
ImmutableList<Fee> fees = ImmutableList.of();
switch (feeRequest.getCommandName()) {
case CREATE:
if (isReserved(domain, isSunrise)) { // Don't return a create price for reserved names.
// Don't return a create price for reserved names.
if (isReserved(domain, isSunrise) && !isAvailable) {
builder.setClass("reserved"); // Override whatever class we've set above.
builder.setAvailIfSupported(false);
builder.setReasonIfSupported("reserved");
@@ -164,7 +164,8 @@ public final class DomainInfoFlow implements Flow {
null,
now,
pricingLogic,
Optional.empty());
Optional.empty(),
false);
extensions.add(builder.build());
}
return extensions.build();