mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 17:56:08 +02:00
Add additional return values to PricingEngine interface
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123658519
This commit is contained in:
parent
ca585dd0b5
commit
91f6c7006e
21 changed files with 191 additions and 191 deletions
|
@ -23,12 +23,70 @@ import org.joda.time.DateTime;
|
|||
public interface PricingEngine {
|
||||
|
||||
/**
|
||||
* Returns the premium price for the given domain name at the given time for the given registrar,
|
||||
* or absent if the domain name isn't premium.
|
||||
* Returns the prices for the given fully qualified domain name at the given time.
|
||||
*
|
||||
* <p>Note that fullyQualifiedDomainName must not include any subdomains. It should be a single
|
||||
* level above the TLD (which may be multi-part).
|
||||
* <p>Note that the fullyQualifiedDomainName must only contain a single part left of the TLD, i.e.
|
||||
* subdomains are not allowed, but multi-part TLDs are.
|
||||
*/
|
||||
public Optional<Money> getPremiumPrice(
|
||||
String fullyQualifiedDomainName, DateTime priceTime, String clientIdentifier);
|
||||
public DomainPrices getDomainPrices(String fullyQualifiedDomainName, DateTime priceTime);
|
||||
|
||||
/**
|
||||
* A class containing information on prices for a specific domain name.
|
||||
*
|
||||
* <p>Any implementation of PricingEngine is responsible for determining all of these.
|
||||
*/
|
||||
public static class DomainPrices {
|
||||
|
||||
private boolean isPremium;
|
||||
// TODO(b/26901539): Refactor return values to support an arbitrary list of costs for each of
|
||||
// create, renew, restore, and transfer.
|
||||
private Money createCost;
|
||||
private Money renewCost;
|
||||
private Optional<Money> oneTimeFee;
|
||||
private Optional<String> feeClass;
|
||||
|
||||
static DomainPrices create(
|
||||
boolean isPremium,
|
||||
Money createCost,
|
||||
Money renewCost,
|
||||
Optional<Money> oneTimeFee,
|
||||
Optional<String> feeClass) {
|
||||
DomainPrices instance = new DomainPrices();
|
||||
instance.isPremium = isPremium;
|
||||
instance.createCost = createCost;
|
||||
instance.renewCost = renewCost;
|
||||
instance.oneTimeFee = oneTimeFee;
|
||||
instance.feeClass = feeClass;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** Returns whether the domain is premium. */
|
||||
public boolean isPremium() {
|
||||
return isPremium;
|
||||
}
|
||||
|
||||
/** Returns the cost to create the domain. */
|
||||
public Money getCreateCost() {
|
||||
return createCost;
|
||||
}
|
||||
|
||||
/** Returns the cost to renew the domain. */
|
||||
public Money getRenewCost() {
|
||||
return renewCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the one time fee to register a domain if there is one.
|
||||
*
|
||||
* <p>This is primarily used for EAP registration fees.
|
||||
*/
|
||||
public Optional<Money> getOneTimeFee() {
|
||||
return oneTimeFee;
|
||||
}
|
||||
|
||||
/** Returns the fee class of the cost (used for the Fee extension). */
|
||||
public Optional<String> getFeeClass() {
|
||||
return feeClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,13 @@ package google.registry.model.pricing;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static google.registry.model.registry.Registry.TldState.SUNRISE;
|
||||
import static google.registry.model.registry.label.ReservationType.NAME_COLLISION;
|
||||
import static google.registry.model.registry.label.ReservedList.getReservation;
|
||||
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
||||
|
@ -35,19 +40,28 @@ public final class StaticPremiumListPricingEngine implements PricingEngine {
|
|||
@Inject StaticPremiumListPricingEngine() {}
|
||||
|
||||
@Override
|
||||
public Optional<Money> getPremiumPrice(
|
||||
String fullyQualifiedDomainName, DateTime priceTime, String clientIdentifier) {
|
||||
// Note that clientIdentifier and priceTime are not used for determining premium pricing for
|
||||
// static premium lists.
|
||||
public DomainPrices getDomainPrices(String fullyQualifiedDomainName, DateTime priceTime) {
|
||||
String tld = getTldFromDomainName(fullyQualifiedDomainName);
|
||||
Registry registry = Registry.get(checkNotNull(tld, "tld"));
|
||||
if (registry.getPremiumList() == null) {
|
||||
return Optional.<Money>absent();
|
||||
}
|
||||
String listName = registry.getPremiumList().getName();
|
||||
Optional<PremiumList> premiumList = PremiumList.get(listName);
|
||||
checkState(premiumList.isPresent(), "Could not load premium list: %s", listName);
|
||||
String label = InternetDomainName.from(fullyQualifiedDomainName).parts().get(0);
|
||||
return premiumList.get().getPremiumPrice(label);
|
||||
Registry registry = Registry.get(checkNotNull(tld, "tld"));
|
||||
Optional<Money> premiumPrice = Optional.<Money>absent();
|
||||
if (registry.getPremiumList() != null) {
|
||||
String listName = registry.getPremiumList().getName();
|
||||
Optional<PremiumList> premiumList = PremiumList.get(listName);
|
||||
checkState(premiumList.isPresent(), "Could not load premium list: %s", listName);
|
||||
premiumPrice = premiumList.get().getPremiumPrice(label);
|
||||
}
|
||||
boolean isNameCollisionInSunrise =
|
||||
registry.getTldState(priceTime).equals(SUNRISE)
|
||||
&& getReservation(label, tld) == NAME_COLLISION;
|
||||
String feeClass = emptyToNull(Joiner.on('-').skipNulls().join(
|
||||
premiumPrice.isPresent() ? "premium" : null,
|
||||
isNameCollisionInSunrise ? "collision" : null));
|
||||
return DomainPrices.create(
|
||||
premiumPrice.isPresent(),
|
||||
premiumPrice.or(registry.getStandardCreateCost()),
|
||||
premiumPrice.or(registry.getStandardRenewCost(priceTime)),
|
||||
Optional.<Money>absent(),
|
||||
Optional.<String>fromNullable(feeClass));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue