mirror of
https://github.com/google/nomulus.git
synced 2025-05-03 21:47:51 +02:00
We never used it and don't have any plans to use it going forward. All conceivable parts of its functionality that we might use going forward have already been subsumed into allocation tokens, which are a simpler way of handling the same use case that are also standards-compliant. Also gets rid of the hideous ANCHOR_ prefix on anchor tenant EPP authcodes that was only ever necessary because of overloading the authcode for anchor tenant creation. Going forward it'll be based on allocation tokens, so there's no risk of conflicts. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=209418194
186 lines
7.5 KiB
Java
186 lines
7.5 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.flows.domain;
|
|
|
|
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
|
|
import static google.registry.pricing.PricingEngineProxy.getDomainFeeClass;
|
|
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
|
|
|
import com.google.common.net.InternetDomainName;
|
|
import google.registry.flows.EppException;
|
|
import google.registry.flows.FlowScope;
|
|
import google.registry.flows.custom.DomainPricingCustomLogic;
|
|
import google.registry.flows.custom.DomainPricingCustomLogic.ApplicationUpdatePriceParameters;
|
|
import google.registry.flows.custom.DomainPricingCustomLogic.CreatePriceParameters;
|
|
import google.registry.flows.custom.DomainPricingCustomLogic.RenewPriceParameters;
|
|
import google.registry.flows.custom.DomainPricingCustomLogic.RestorePriceParameters;
|
|
import google.registry.flows.custom.DomainPricingCustomLogic.TransferPriceParameters;
|
|
import google.registry.flows.custom.DomainPricingCustomLogic.UpdatePriceParameters;
|
|
import google.registry.model.domain.DomainApplication;
|
|
import google.registry.model.domain.fee.BaseFee;
|
|
import google.registry.model.domain.fee.BaseFee.FeeType;
|
|
import google.registry.model.domain.fee.Fee;
|
|
import google.registry.model.registry.Registry;
|
|
import java.util.Optional;
|
|
import javax.inject.Inject;
|
|
import org.joda.money.CurrencyUnit;
|
|
import org.joda.money.Money;
|
|
import org.joda.time.DateTime;
|
|
|
|
/**
|
|
* Provides pricing for create, renew, etc, operations, with call-outs that can be customized by
|
|
* providing a {@link DomainPricingCustomLogic} implementation that operates on cross-TLD or per-TLD
|
|
* logic.
|
|
*/
|
|
@FlowScope
|
|
public final class DomainPricingLogic {
|
|
|
|
@Inject DomainPricingCustomLogic customLogic;
|
|
|
|
@Inject
|
|
DomainPricingLogic() {}
|
|
|
|
/** Returns a new create price for the pricer. */
|
|
public FeesAndCredits getCreatePrice(
|
|
Registry registry, String domainName, DateTime date, int years) throws EppException {
|
|
CurrencyUnit currency = registry.getCurrency();
|
|
|
|
// Get the vanilla create cost.
|
|
BaseFee createFeeOrCredit =
|
|
Fee.create(getDomainCreateCost(domainName, date, years).getAmount(), FeeType.CREATE);
|
|
|
|
// Create fees for the cost and the EAP fee, if any.
|
|
Fee eapFee = registry.getEapFeeFor(date);
|
|
FeesAndCredits.Builder feesBuilder =
|
|
new FeesAndCredits.Builder().setCurrency(currency).addFeeOrCredit(createFeeOrCredit);
|
|
if (!eapFee.hasZeroCost()) {
|
|
feesBuilder.addFeeOrCredit(eapFee);
|
|
}
|
|
|
|
// Apply custom logic to the create fee, if any.
|
|
return customLogic.customizeCreatePrice(
|
|
CreatePriceParameters.newBuilder()
|
|
.setFeesAndCredits(feesBuilder.build())
|
|
.setRegistry(registry)
|
|
.setDomainName(InternetDomainName.from(domainName))
|
|
.setAsOfDate(date)
|
|
.setYears(years)
|
|
.build());
|
|
|
|
}
|
|
|
|
/** Returns a new renew price for the pricer. */
|
|
@SuppressWarnings("unused")
|
|
public FeesAndCredits getRenewPrice(
|
|
Registry registry,
|
|
String domainName,
|
|
DateTime date,
|
|
int years)
|
|
throws EppException {
|
|
Money renewCost = getDomainRenewCost(domainName, date, years);
|
|
return customLogic.customizeRenewPrice(
|
|
RenewPriceParameters.newBuilder()
|
|
.setFeesAndCredits(
|
|
new FeesAndCredits.Builder()
|
|
.setCurrency(registry.getCurrency())
|
|
.addFeeOrCredit(Fee.create(renewCost.getAmount(), FeeType.RENEW))
|
|
.build())
|
|
.setRegistry(registry)
|
|
.setDomainName(InternetDomainName.from(domainName))
|
|
.setAsOfDate(date)
|
|
.setYears(years)
|
|
.build());
|
|
}
|
|
|
|
/** Returns a new restore price for the pricer. */
|
|
public FeesAndCredits getRestorePrice(Registry registry, String domainName, DateTime date)
|
|
throws EppException {
|
|
FeesAndCredits feesAndCredits =
|
|
new FeesAndCredits.Builder()
|
|
.setCurrency(registry.getCurrency())
|
|
.addFeeOrCredit(
|
|
Fee.create(getDomainRenewCost(domainName, date, 1).getAmount(), FeeType.RENEW))
|
|
.addFeeOrCredit(
|
|
Fee.create(registry.getStandardRestoreCost().getAmount(), FeeType.RESTORE))
|
|
.build();
|
|
return customLogic.customizeRestorePrice(
|
|
RestorePriceParameters.newBuilder()
|
|
.setFeesAndCredits(feesAndCredits)
|
|
.setRegistry(registry)
|
|
.setDomainName(InternetDomainName.from(domainName))
|
|
.setAsOfDate(date)
|
|
.build());
|
|
}
|
|
|
|
/** Returns a new transfer price for the pricer. */
|
|
public FeesAndCredits getTransferPrice(Registry registry, String domainName, DateTime date)
|
|
throws EppException {
|
|
Money renewCost = getDomainRenewCost(domainName, date, 1);
|
|
return customLogic.customizeTransferPrice(
|
|
TransferPriceParameters.newBuilder()
|
|
.setFeesAndCredits(
|
|
new FeesAndCredits.Builder()
|
|
.setCurrency(registry.getCurrency())
|
|
.addFeeOrCredit(Fee.create(renewCost.getAmount(), FeeType.RENEW))
|
|
.build())
|
|
.setRegistry(registry)
|
|
.setDomainName(InternetDomainName.from(domainName))
|
|
.setAsOfDate(date)
|
|
.build());
|
|
}
|
|
|
|
/** Returns a new update price for the pricer. */
|
|
public FeesAndCredits getUpdatePrice(Registry registry, String domainName, DateTime date)
|
|
throws EppException {
|
|
CurrencyUnit currency = registry.getCurrency();
|
|
BaseFee feeOrCredit =
|
|
Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE);
|
|
return customLogic.customizeUpdatePrice(
|
|
UpdatePriceParameters.newBuilder()
|
|
.setFeesAndCredits(
|
|
new FeesAndCredits.Builder()
|
|
.setCurrency(currency)
|
|
.addFeeOrCredit(feeOrCredit)
|
|
.build())
|
|
.setRegistry(registry)
|
|
.setDomainName(InternetDomainName.from(domainName))
|
|
.setAsOfDate(date)
|
|
.build());
|
|
}
|
|
|
|
/** Returns a new domain application update price for the pricer. */
|
|
@SuppressWarnings("unused")
|
|
public FeesAndCredits getApplicationUpdatePrice(
|
|
Registry registry, DomainApplication application, DateTime date) throws EppException {
|
|
BaseFee feeOrCredit =
|
|
Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE);
|
|
return customLogic.customizeApplicationUpdatePrice(
|
|
ApplicationUpdatePriceParameters.newBuilder()
|
|
.setFeesAndCredits(
|
|
new FeesAndCredits.Builder()
|
|
.setCurrency(registry.getCurrency())
|
|
.setFeesAndCredits(feeOrCredit)
|
|
.build())
|
|
.setRegistry(registry)
|
|
.setDomainApplication(application)
|
|
.setAsOfDate(date)
|
|
.build());
|
|
}
|
|
|
|
/** Returns the fee class for a given domain and date. */
|
|
public Optional<String> getFeeClass(String domainName, DateTime date) {
|
|
return getDomainFeeClass(domainName, date);
|
|
}
|
|
}
|