mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Modify create price custom logic to return FeesAndCredits
Previously DomainPricingCustomLogic#customizeCreatePrice takes in the create price itself and modifies it. Change it to take in the entire FeesAndCredits (previously named EppCommandOperations) which may contain other fees related to domain creation, such as EAP fees, and returns FeesAndCredits that may either change the fees or add new type of fees. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=141600614
This commit is contained in:
parent
a56a0677ba
commit
74d64f502e
7 changed files with 90 additions and 91 deletions
|
@ -19,8 +19,8 @@ import com.google.common.net.InternetDomainName;
|
||||||
import google.registry.flows.EppException;
|
import google.registry.flows.EppException;
|
||||||
import google.registry.flows.SessionMetadata;
|
import google.registry.flows.SessionMetadata;
|
||||||
import google.registry.flows.domain.DomainPricingLogic;
|
import google.registry.flows.domain.DomainPricingLogic;
|
||||||
|
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.domain.fee.BaseFee;
|
|
||||||
import google.registry.model.eppinput.EppInput;
|
import google.registry.model.eppinput.EppInput;
|
||||||
import google.registry.model.registry.Registry;
|
import google.registry.model.registry.Registry;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
@ -38,16 +38,16 @@ public class DomainPricingCustomLogic extends BaseFlowCustomLogic {
|
||||||
|
|
||||||
/** A hook that customizes create price. */
|
/** A hook that customizes create price. */
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public BaseFee customizeCreatePrice(CreatePriceParameters createPriceParameters)
|
public FeesAndCredits customizeCreatePrice(CreatePriceParameters createPriceParameters)
|
||||||
throws EppException {
|
throws EppException {
|
||||||
return createPriceParameters.createFee();
|
return createPriceParameters.feesAndCredits();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A class to encapsulate parameters for a call to {@link #customizeCreatePrice} . */
|
/** A class to encapsulate parameters for a call to {@link #customizeCreatePrice} . */
|
||||||
@AutoValue
|
@AutoValue
|
||||||
public abstract static class CreatePriceParameters extends ImmutableObject {
|
public abstract static class CreatePriceParameters extends ImmutableObject {
|
||||||
|
|
||||||
public abstract BaseFee createFee();
|
public abstract FeesAndCredits feesAndCredits();
|
||||||
|
|
||||||
public abstract Registry registry();
|
public abstract Registry registry();
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class DomainPricingCustomLogic extends BaseFlowCustomLogic {
|
||||||
@AutoValue.Builder
|
@AutoValue.Builder
|
||||||
public abstract static class Builder {
|
public abstract static class Builder {
|
||||||
|
|
||||||
public abstract Builder setCreateFee(BaseFee createFee);
|
public abstract Builder setFeesAndCredits(FeesAndCredits feesAndCredits);
|
||||||
|
|
||||||
public abstract Builder setRegistry(Registry registry);
|
public abstract Builder setRegistry(Registry registry);
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ import google.registry.flows.FlowModule.ClientId;
|
||||||
import google.registry.flows.FlowModule.Superuser;
|
import google.registry.flows.FlowModule.Superuser;
|
||||||
import google.registry.flows.FlowModule.TargetId;
|
import google.registry.flows.FlowModule.TargetId;
|
||||||
import google.registry.flows.TransactionalFlow;
|
import google.registry.flows.TransactionalFlow;
|
||||||
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
|
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.billing.BillingEvent;
|
import google.registry.model.billing.BillingEvent;
|
||||||
import google.registry.model.billing.BillingEvent.Flag;
|
import google.registry.model.billing.BillingEvent.Flag;
|
||||||
|
@ -390,13 +390,12 @@ public class DomainAllocateFlow implements TransactionalFlow {
|
||||||
|
|
||||||
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
||||||
DateTime now, Registry registry, int years) throws EppException {
|
DateTime now, Registry registry, int years) throws EppException {
|
||||||
EppCommandOperations commandOperations =
|
FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice(registry, targetId, now, years);
|
||||||
pricingLogic.getCreatePrice(registry, targetId, now, years);
|
|
||||||
FeeCreateCommandExtension feeCreate =
|
FeeCreateCommandExtension feeCreate =
|
||||||
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
||||||
return (feeCreate == null)
|
return (feeCreate == null)
|
||||||
? ImmutableList.<FeeTransformResponseExtension>of()
|
? ImmutableList.<FeeTransformResponseExtension>of()
|
||||||
: ImmutableList.of(createFeeCreateResponse(feeCreate, commandOperations));
|
: ImmutableList.of(createFeeCreateResponse(feeCreate, feesAndCredits));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Domain application with specific ROID does not exist. */
|
/** Domain application with specific ROID does not exist. */
|
||||||
|
|
|
@ -64,7 +64,7 @@ import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.After
|
||||||
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseParameters;
|
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseParameters;
|
||||||
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseReturnData;
|
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseReturnData;
|
||||||
import google.registry.flows.custom.EntityChanges;
|
import google.registry.flows.custom.EntityChanges;
|
||||||
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
|
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.domain.DomainApplication;
|
import google.registry.model.domain.DomainApplication;
|
||||||
import google.registry.model.domain.DomainCommand.Create;
|
import google.registry.model.domain.DomainCommand.Create;
|
||||||
|
@ -201,7 +201,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
||||||
String tld = domainName.parent().toString();
|
String tld = domainName.parent().toString();
|
||||||
checkAllowedAccessToTld(clientId, tld);
|
checkAllowedAccessToTld(clientId, tld);
|
||||||
Registry registry = Registry.get(tld);
|
Registry registry = Registry.get(tld);
|
||||||
EppCommandOperations commandOperations =
|
FeesAndCredits feesAndCredits =
|
||||||
pricingLogic.getCreatePrice(registry, targetId, now, command.getPeriod().getValue());
|
pricingLogic.getCreatePrice(registry, targetId, now, command.getPeriod().getValue());
|
||||||
// Superusers can create reserved domains, force creations on domains that require a claims
|
// Superusers can create reserved domains, force creations on domains that require a claims
|
||||||
// notice without specifying a claims key, and override blocks on registering premium domains.
|
// notice without specifying a claims key, and override blocks on registering premium domains.
|
||||||
|
@ -224,7 +224,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
||||||
}
|
}
|
||||||
FeeCreateCommandExtension feeCreate =
|
FeeCreateCommandExtension feeCreate =
|
||||||
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
||||||
validateFeeChallenge(targetId, tld, now, feeCreate, commandOperations.getTotalCost());
|
validateFeeChallenge(targetId, tld, now, feeCreate, feesAndCredits.getTotalCost());
|
||||||
SecDnsCreateExtension secDnsCreate =
|
SecDnsCreateExtension secDnsCreate =
|
||||||
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
|
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
|
||||||
customLogic.afterValidation(
|
customLogic.afterValidation(
|
||||||
|
@ -292,7 +292,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
||||||
newApplication.getForeignKey(),
|
newApplication.getForeignKey(),
|
||||||
launchCreate.getPhase(),
|
launchCreate.getPhase(),
|
||||||
feeCreate,
|
feeCreate,
|
||||||
commandOperations))
|
feesAndCredits))
|
||||||
.build());
|
.build());
|
||||||
return responseBuilder
|
return responseBuilder
|
||||||
.setResData(responseData.resData())
|
.setResData(responseData.resData())
|
||||||
|
@ -366,11 +366,11 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableList<ResponseExtension> createResponseExtensions(
|
private static ImmutableList<ResponseExtension> createResponseExtensions(
|
||||||
String applicationId,
|
String applicationId,
|
||||||
LaunchPhase launchPhase,
|
LaunchPhase launchPhase,
|
||||||
FeeTransformCommandExtension feeCreate,
|
FeeTransformCommandExtension feeCreate,
|
||||||
EppCommandOperations commandOperations) {
|
FeesAndCredits feesAndCredits) {
|
||||||
ImmutableList.Builder<ResponseExtension> responseExtensionsBuilder =
|
ImmutableList.Builder<ResponseExtension> responseExtensionsBuilder =
|
||||||
new ImmutableList.Builder<>();
|
new ImmutableList.Builder<>();
|
||||||
responseExtensionsBuilder.add(new LaunchCreateResponseExtension.Builder()
|
responseExtensionsBuilder.add(new LaunchCreateResponseExtension.Builder()
|
||||||
|
@ -378,7 +378,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
||||||
.setApplicationId(applicationId)
|
.setApplicationId(applicationId)
|
||||||
.build());
|
.build());
|
||||||
if (feeCreate != null) {
|
if (feeCreate != null) {
|
||||||
responseExtensionsBuilder.add(createFeeCreateResponse(feeCreate, commandOperations));
|
responseExtensionsBuilder.add(createFeeCreateResponse(feeCreate, feesAndCredits));
|
||||||
}
|
}
|
||||||
return responseExtensionsBuilder.build();
|
return responseExtensionsBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ import google.registry.flows.custom.DomainCreateFlowCustomLogic;
|
||||||
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseParameters;
|
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseParameters;
|
||||||
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseReturnData;
|
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseReturnData;
|
||||||
import google.registry.flows.custom.EntityChanges;
|
import google.registry.flows.custom.EntityChanges;
|
||||||
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
|
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.billing.BillingEvent;
|
import google.registry.model.billing.BillingEvent;
|
||||||
import google.registry.model.billing.BillingEvent.Flag;
|
import google.registry.model.billing.BillingEvent.Flag;
|
||||||
|
@ -211,10 +211,9 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
|
|
||||||
FeeCreateCommandExtension feeCreate =
|
FeeCreateCommandExtension feeCreate =
|
||||||
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
||||||
EppCommandOperations commandOperations =
|
FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice(registry, targetId, now, years);
|
||||||
pricingLogic.getCreatePrice(registry, targetId, now, years);
|
|
||||||
validateFeeChallenge(
|
validateFeeChallenge(
|
||||||
targetId, registry.getTldStr(), now, feeCreate, commandOperations.getTotalCost());
|
targetId, registry.getTldStr(), now, feeCreate, feesAndCredits.getTotalCost());
|
||||||
// Superusers can create reserved domains, force creations on domains that require a claims
|
// Superusers can create reserved domains, force creations on domains that require a claims
|
||||||
// notice without specifying a claims key, ignore the registry phase, and override blocks on
|
// notice without specifying a claims key, ignore the registry phase, and override blocks on
|
||||||
// registering premium domains.
|
// registering premium domains.
|
||||||
|
@ -242,8 +241,9 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
DateTime registrationExpirationTime = leapSafeAddYears(now, years);
|
DateTime registrationExpirationTime = leapSafeAddYears(now, years);
|
||||||
HistoryEntry historyEntry = buildHistory(repoId, period, now);
|
HistoryEntry historyEntry = buildHistory(repoId, period, now);
|
||||||
// Bill for the create.
|
// Bill for the create.
|
||||||
BillingEvent.OneTime createBillingEvent = createOneTimeBillingEvent(
|
BillingEvent.OneTime createBillingEvent =
|
||||||
registry, isAnchorTenant, years, commandOperations, historyEntry, now);
|
createOneTimeBillingEvent(
|
||||||
|
registry, isAnchorTenant, years, feesAndCredits, historyEntry, now);
|
||||||
// Create a new autorenew billing event and poll message starting at the expiration time.
|
// Create a new autorenew billing event and poll message starting at the expiration time.
|
||||||
BillingEvent.Recurring autorenewBillingEvent =
|
BillingEvent.Recurring autorenewBillingEvent =
|
||||||
createAutorenewBillingEvent(historyEntry, registrationExpirationTime);
|
createAutorenewBillingEvent(historyEntry, registrationExpirationTime);
|
||||||
|
@ -256,8 +256,8 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
autorenewBillingEvent,
|
autorenewBillingEvent,
|
||||||
autorenewPollMessage);
|
autorenewPollMessage);
|
||||||
// Bill for EAP cost, if any.
|
// Bill for EAP cost, if any.
|
||||||
if (!commandOperations.getEapCost().isZero()) {
|
if (!feesAndCredits.getEapCost().isZero()) {
|
||||||
entitiesToSave.add(createEapBillingEvent(commandOperations, createBillingEvent));
|
entitiesToSave.add(createEapBillingEvent(feesAndCredits, createBillingEvent));
|
||||||
}
|
}
|
||||||
DomainResource newDomain = new DomainResource.Builder()
|
DomainResource newDomain = new DomainResource.Builder()
|
||||||
.setCreationClientId(clientId)
|
.setCreationClientId(clientId)
|
||||||
|
@ -308,7 +308,7 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
customLogic.beforeResponse(
|
customLogic.beforeResponse(
|
||||||
BeforeResponseParameters.newBuilder()
|
BeforeResponseParameters.newBuilder()
|
||||||
.setResData(DomainCreateData.create(targetId, now, registrationExpirationTime))
|
.setResData(DomainCreateData.create(targetId, now, registrationExpirationTime))
|
||||||
.setResponseExtensions(createResponseExtensions(feeCreate, commandOperations))
|
.setResponseExtensions(createResponseExtensions(feeCreate, feesAndCredits))
|
||||||
.build());
|
.build());
|
||||||
return responseBuilder
|
return responseBuilder
|
||||||
.setResData(responseData.resData())
|
.setResData(responseData.resData())
|
||||||
|
@ -352,7 +352,7 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
Registry registry,
|
Registry registry,
|
||||||
boolean isAnchorTenant,
|
boolean isAnchorTenant,
|
||||||
int years,
|
int years,
|
||||||
EppCommandOperations commandOperations,
|
FeesAndCredits feesAndCredits,
|
||||||
HistoryEntry historyEntry,
|
HistoryEntry historyEntry,
|
||||||
DateTime now) {
|
DateTime now) {
|
||||||
return new BillingEvent.OneTime.Builder()
|
return new BillingEvent.OneTime.Builder()
|
||||||
|
@ -360,14 +360,17 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
.setTargetId(targetId)
|
.setTargetId(targetId)
|
||||||
.setClientId(clientId)
|
.setClientId(clientId)
|
||||||
.setPeriodYears(years)
|
.setPeriodYears(years)
|
||||||
.setCost(commandOperations.getCreateCost())
|
.setCost(feesAndCredits.getCreateCost())
|
||||||
.setEventTime(now)
|
.setEventTime(now)
|
||||||
.setBillingTime(now.plus(isAnchorTenant
|
.setBillingTime(
|
||||||
? registry.getAnchorTenantAddGracePeriodLength()
|
now.plus(
|
||||||
: registry.getAddGracePeriodLength()))
|
isAnchorTenant
|
||||||
.setFlags(isAnchorTenant
|
? registry.getAnchorTenantAddGracePeriodLength()
|
||||||
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT)
|
: registry.getAddGracePeriodLength()))
|
||||||
: ImmutableSet.<BillingEvent.Flag>of())
|
.setFlags(
|
||||||
|
isAnchorTenant
|
||||||
|
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT)
|
||||||
|
: ImmutableSet.<BillingEvent.Flag>of())
|
||||||
.setParent(historyEntry)
|
.setParent(historyEntry)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -396,13 +399,13 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private OneTime createEapBillingEvent(EppCommandOperations commandOperations,
|
private static OneTime createEapBillingEvent(
|
||||||
BillingEvent.OneTime createBillingEvent) {
|
FeesAndCredits feesAndCredits, BillingEvent.OneTime createBillingEvent) {
|
||||||
return new BillingEvent.OneTime.Builder()
|
return new BillingEvent.OneTime.Builder()
|
||||||
.setReason(Reason.FEE_EARLY_ACCESS)
|
.setReason(Reason.FEE_EARLY_ACCESS)
|
||||||
.setTargetId(createBillingEvent.getTargetId())
|
.setTargetId(createBillingEvent.getTargetId())
|
||||||
.setClientId(createBillingEvent.getClientId())
|
.setClientId(createBillingEvent.getClientId())
|
||||||
.setCost(commandOperations.getEapCost())
|
.setCost(feesAndCredits.getEapCost())
|
||||||
.setEventTime(createBillingEvent.getEventTime())
|
.setEventTime(createBillingEvent.getEventTime())
|
||||||
.setBillingTime(createBillingEvent.getBillingTime())
|
.setBillingTime(createBillingEvent.getBillingTime())
|
||||||
.setFlags(createBillingEvent.getFlags())
|
.setFlags(createBillingEvent.getFlags())
|
||||||
|
@ -424,11 +427,11 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
private static ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
||||||
FeeCreateCommandExtension feeCreate, EppCommandOperations commandOperations) {
|
FeeCreateCommandExtension feeCreate, FeesAndCredits feesAndCredits) {
|
||||||
return (feeCreate == null)
|
return (feeCreate == null)
|
||||||
? ImmutableList.<FeeTransformResponseExtension>of()
|
? ImmutableList.<FeeTransformResponseExtension>of()
|
||||||
: ImmutableList.of(createFeeCreateResponse(feeCreate, commandOperations));
|
: ImmutableList.of(createFeeCreateResponse(feeCreate, feesAndCredits));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** There is an open application for this domain. */
|
/** There is an open application for this domain. */
|
||||||
|
|
|
@ -56,7 +56,7 @@ import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
|
||||||
import google.registry.flows.EppException.RequiredParameterMissingException;
|
import google.registry.flows.EppException.RequiredParameterMissingException;
|
||||||
import google.registry.flows.EppException.StatusProhibitsOperationException;
|
import google.registry.flows.EppException.StatusProhibitsOperationException;
|
||||||
import google.registry.flows.EppException.UnimplementedOptionException;
|
import google.registry.flows.EppException.UnimplementedOptionException;
|
||||||
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
|
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
|
||||||
import google.registry.flows.exceptions.ResourceAlreadyExistsException;
|
import google.registry.flows.exceptions.ResourceAlreadyExistsException;
|
||||||
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
|
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
|
||||||
import google.registry.model.EppResource;
|
import google.registry.model.EppResource;
|
||||||
|
@ -994,12 +994,12 @@ public class DomainFlowUtils {
|
||||||
|
|
||||||
/** Create a response extension listign the fees on a domain or application create. */
|
/** Create a response extension listign the fees on a domain or application create. */
|
||||||
static FeeTransformResponseExtension createFeeCreateResponse(
|
static FeeTransformResponseExtension createFeeCreateResponse(
|
||||||
FeeTransformCommandExtension feeCreate,
|
FeeTransformCommandExtension feeCreate, FeesAndCredits feesAndCredits) {
|
||||||
EppCommandOperations commandOperations) {
|
return feeCreate
|
||||||
return feeCreate.createResponseBuilder()
|
.createResponseBuilder()
|
||||||
.setCurrency(commandOperations.getCurrency())
|
.setCurrency(feesAndCredits.getCurrency())
|
||||||
.setFees(commandOperations.getFees())
|
.setFees(feesAndCredits.getFees())
|
||||||
.setCredits(commandOperations.getCredits())
|
.setCredits(feesAndCredits.getCredits())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
package google.registry.flows.domain;
|
package google.registry.flows.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
|
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
|
||||||
|
@ -62,31 +61,17 @@ public final class DomainPricingLogic {
|
||||||
DomainPricingLogic() {}
|
DomainPricingLogic() {}
|
||||||
|
|
||||||
/** A collection of fees and credits for a specific EPP transform. */
|
/** A collection of fees and credits for a specific EPP transform. */
|
||||||
public static final class EppCommandOperations extends ImmutableObject {
|
public static final class FeesAndCredits extends ImmutableObject {
|
||||||
private final CurrencyUnit currency;
|
private final CurrencyUnit currency;
|
||||||
private final ImmutableList<Fee> fees;
|
private final ImmutableList<Fee> fees;
|
||||||
private final ImmutableList<Credit> credits;
|
private final ImmutableList<Credit> credits;
|
||||||
|
|
||||||
/** Constructs an EppCommandOperations object using separate lists of fees and credits. */
|
/** Constructs an FeesAndCredits object. The arguments are sorted into fees and credits. */
|
||||||
EppCommandOperations(
|
public FeesAndCredits(CurrencyUnit currency, BaseFee... baseFees) {
|
||||||
CurrencyUnit currency, ImmutableList<Fee> fees, ImmutableList<Credit> credits) {
|
this.currency = checkArgumentNotNull(currency, "Currency may not be null in FeesAndCredits.");
|
||||||
this.currency =
|
|
||||||
checkArgumentNotNull(currency, "Currency may not be null in EppCommandOperations.");
|
|
||||||
checkArgument(!fees.isEmpty(), "You must specify one or more fees.");
|
|
||||||
this.fees = checkArgumentNotNull(fees, "Fees may not be null in EppCommandOperations.");
|
|
||||||
this.credits =
|
|
||||||
checkArgumentNotNull(credits, "Credits may not be null in EppCommandOperations.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs an EppCommandOperations object. The arguments are sorted into fees and credits.
|
|
||||||
*/
|
|
||||||
EppCommandOperations(CurrencyUnit currency, BaseFee... feesAndCredits) {
|
|
||||||
this.currency =
|
|
||||||
checkArgumentNotNull(currency, "Currency may not be null in EppCommandOperations.");
|
|
||||||
ImmutableList.Builder<Fee> feeBuilder = new ImmutableList.Builder<>();
|
ImmutableList.Builder<Fee> feeBuilder = new ImmutableList.Builder<>();
|
||||||
ImmutableList.Builder<Credit> creditBuilder = new ImmutableList.Builder<>();
|
ImmutableList.Builder<Credit> creditBuilder = new ImmutableList.Builder<>();
|
||||||
for (BaseFee feeOrCredit : feesAndCredits) {
|
for (BaseFee feeOrCredit : baseFees) {
|
||||||
if (feeOrCredit instanceof Credit) {
|
if (feeOrCredit instanceof Credit) {
|
||||||
creditBuilder.add((Credit) feeOrCredit);
|
creditBuilder.add((Credit) feeOrCredit);
|
||||||
} else {
|
} else {
|
||||||
|
@ -147,7 +132,7 @@ public final class DomainPricingLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new create price for the Pricer. */
|
/** Returns a new create price for the Pricer. */
|
||||||
public EppCommandOperations getCreatePrice(
|
public FeesAndCredits getCreatePrice(
|
||||||
Registry registry, String domainName, DateTime date, int years) throws EppException {
|
Registry registry, String domainName, DateTime date, int years) throws EppException {
|
||||||
CurrencyUnit currency = registry.getCurrency();
|
CurrencyUnit currency = registry.getCurrency();
|
||||||
|
|
||||||
|
@ -155,24 +140,26 @@ public final class DomainPricingLogic {
|
||||||
BaseFee createFeeOrCredit =
|
BaseFee createFeeOrCredit =
|
||||||
Fee.create(getDomainCreateCost(domainName, date, years).getAmount(), FeeType.CREATE);
|
Fee.create(getDomainCreateCost(domainName, date, years).getAmount(), FeeType.CREATE);
|
||||||
|
|
||||||
// Apply custom logic to the create fee, if any.
|
FeesAndCredits feesAndCredits;
|
||||||
createFeeOrCredit =
|
|
||||||
customLogic.customizeCreatePrice(
|
|
||||||
CreatePriceParameters.newBuilder()
|
|
||||||
.setCreateFee(createFeeOrCredit)
|
|
||||||
.setRegistry(registry)
|
|
||||||
.setDomainName(InternetDomainName.from(domainName))
|
|
||||||
.setAsOfDate(date)
|
|
||||||
.setYears(years)
|
|
||||||
.build());
|
|
||||||
|
|
||||||
// Create fees for the cost and the EAP fee, if any.
|
// Create fees for the cost and the EAP fee, if any.
|
||||||
Fee eapFee = registry.getEapFeeFor(date);
|
Fee eapFee = registry.getEapFeeFor(date);
|
||||||
if (!eapFee.hasZeroCost()) {
|
if (!eapFee.hasZeroCost()) {
|
||||||
return new EppCommandOperations(currency, createFeeOrCredit, eapFee);
|
feesAndCredits = new FeesAndCredits(currency, createFeeOrCredit, eapFee);
|
||||||
} else {
|
} else {
|
||||||
return new EppCommandOperations(currency, createFeeOrCredit);
|
feesAndCredits = new FeesAndCredits(currency, createFeeOrCredit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply custom logic to the create fee, if any.
|
||||||
|
return customLogic.customizeCreatePrice(
|
||||||
|
CreatePriceParameters.newBuilder()
|
||||||
|
.setFeesAndCredits(feesAndCredits)
|
||||||
|
.setRegistry(registry)
|
||||||
|
.setDomainName(InternetDomainName.from(domainName))
|
||||||
|
.setAsOfDate(date)
|
||||||
|
.setYears(years)
|
||||||
|
.build());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (b/33000134) clean up the rest of the pricing calls.
|
// TODO: (b/33000134) clean up the rest of the pricing calls.
|
||||||
|
@ -204,7 +191,7 @@ public final class DomainPricingLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new renew price for the pricer. */
|
/** Returns a new renew price for the pricer. */
|
||||||
public static EppCommandOperations getRenewPrice(
|
public static FeesAndCredits getRenewPrice(
|
||||||
Registry registry,
|
Registry registry,
|
||||||
String domainName,
|
String domainName,
|
||||||
String clientId,
|
String clientId,
|
||||||
|
@ -212,23 +199,23 @@ public final class DomainPricingLogic {
|
||||||
int years,
|
int years,
|
||||||
EppInput eppInput)
|
EppInput eppInput)
|
||||||
throws EppException {
|
throws EppException {
|
||||||
return new EppCommandOperations(
|
return new FeesAndCredits(
|
||||||
registry.getCurrency(),
|
registry.getCurrency(),
|
||||||
getRenewFeeOrCredit(registry, domainName, clientId, date, years, eppInput));
|
getRenewFeeOrCredit(registry, domainName, clientId, date, years, eppInput));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new restore price for the pricer. */
|
/** Returns a new restore price for the pricer. */
|
||||||
public static EppCommandOperations getRestorePrice(
|
public static FeesAndCredits getRestorePrice(
|
||||||
Registry registry, String domainName, String clientId, DateTime date, EppInput eppInput)
|
Registry registry, String domainName, String clientId, DateTime date, EppInput eppInput)
|
||||||
throws EppException {
|
throws EppException {
|
||||||
return new EppCommandOperations(
|
return new FeesAndCredits(
|
||||||
registry.getCurrency(),
|
registry.getCurrency(),
|
||||||
getRenewFeeOrCredit(registry, domainName, clientId, date, 1, eppInput),
|
getRenewFeeOrCredit(registry, domainName, clientId, date, 1, eppInput),
|
||||||
Fee.create(registry.getStandardRestoreCost().getAmount(), FeeType.RESTORE));
|
Fee.create(registry.getStandardRestoreCost().getAmount(), FeeType.RESTORE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new transfer price for the pricer. */
|
/** Returns a new transfer price for the pricer. */
|
||||||
public static EppCommandOperations getTransferPrice(
|
public static FeesAndCredits getTransferPrice(
|
||||||
Registry registry,
|
Registry registry,
|
||||||
String domainName,
|
String domainName,
|
||||||
String clientId,
|
String clientId,
|
||||||
|
@ -241,7 +228,7 @@ public final class DomainPricingLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new update price for the pricer. */
|
/** Returns a new update price for the pricer. */
|
||||||
public static EppCommandOperations getUpdatePrice(
|
public static FeesAndCredits getUpdatePrice(
|
||||||
Registry registry, String domainName, String clientId, DateTime date, EppInput eppInput)
|
Registry registry, String domainName, String clientId, DateTime date, EppInput eppInput)
|
||||||
throws EppException {
|
throws EppException {
|
||||||
CurrencyUnit currency = registry.getCurrency();
|
CurrencyUnit currency = registry.getCurrency();
|
||||||
|
@ -261,11 +248,11 @@ public final class DomainPricingLogic {
|
||||||
feeOrCredit = Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE);
|
feeOrCredit = Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EppCommandOperations(currency, feeOrCredit);
|
return new FeesAndCredits(currency, feeOrCredit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new domain application update price for the pricer. */
|
/** Returns a new domain application update price for the pricer. */
|
||||||
public static EppCommandOperations getApplicationUpdatePrice(
|
public static FeesAndCredits getApplicationUpdatePrice(
|
||||||
Registry registry,
|
Registry registry,
|
||||||
DomainApplication application,
|
DomainApplication application,
|
||||||
String clientId,
|
String clientId,
|
||||||
|
@ -287,7 +274,7 @@ public final class DomainPricingLogic {
|
||||||
feeOrCredit = Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE);
|
feeOrCredit = Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EppCommandOperations(currency, feeOrCredit);
|
return new FeesAndCredits(currency, feeOrCredit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the fee class for a given domain and date. */
|
/** Returns the fee class for a given domain and date. */
|
||||||
|
|
|
@ -18,11 +18,13 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import com.google.common.base.Ascii;
|
import com.google.common.base.Ascii;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.net.InternetDomainName;
|
import com.google.common.net.InternetDomainName;
|
||||||
import google.registry.flows.EppException;
|
import google.registry.flows.EppException;
|
||||||
import google.registry.flows.SessionMetadata;
|
import google.registry.flows.SessionMetadata;
|
||||||
import google.registry.flows.domain.DomainPricingLogic;
|
import google.registry.flows.domain.DomainPricingLogic;
|
||||||
|
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
|
||||||
import google.registry.model.domain.fee.BaseFee;
|
import google.registry.model.domain.fee.BaseFee;
|
||||||
import google.registry.model.domain.fee.BaseFee.FeeType;
|
import google.registry.model.domain.fee.BaseFee.FeeType;
|
||||||
import google.registry.model.domain.fee.Credit;
|
import google.registry.model.domain.fee.Credit;
|
||||||
|
@ -61,13 +63,21 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
||||||
|
|
||||||
/** A hook that customizes create price. */
|
/** A hook that customizes create price. */
|
||||||
@Override
|
@Override
|
||||||
public BaseFee customizeCreatePrice(CreatePriceParameters createPriceParameters)
|
public FeesAndCredits customizeCreatePrice(CreatePriceParameters createPriceParameters)
|
||||||
throws EppException {
|
throws EppException {
|
||||||
InternetDomainName domainName = createPriceParameters.domainName();
|
InternetDomainName domainName = createPriceParameters.domainName();
|
||||||
if (domainName.parent().toString().equals("flags")) {
|
if (domainName.parent().toString().equals("flags")) {
|
||||||
return domainNameToFeeOrCredit(domainName);
|
FeesAndCredits feesAndCredits = createPriceParameters.feesAndCredits();
|
||||||
|
ImmutableList.Builder<BaseFee> baseFeeBuilder = new ImmutableList.Builder<>();
|
||||||
|
baseFeeBuilder.addAll(feesAndCredits.getCredits());
|
||||||
|
for (BaseFee fee : feesAndCredits.getFees()) {
|
||||||
|
baseFeeBuilder.add(
|
||||||
|
fee.getType() == FeeType.CREATE ? domainNameToFeeOrCredit(domainName) : fee);
|
||||||
|
}
|
||||||
|
return new FeesAndCredits(
|
||||||
|
feesAndCredits.getCurrency(), Iterables.toArray(baseFeeBuilder.build(), BaseFee.class));
|
||||||
} else {
|
} else {
|
||||||
return createPriceParameters.createFee();
|
return createPriceParameters.feesAndCredits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue