Create a separate billing event when EAP is applied

When EAP is involed we current have one billing event for domain create that
has the create fee and EAP fee lumped together. Change it to record two
separate billing events for each.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132335349
This commit is contained in:
jianglai 2016-09-06 10:28:56 -07:00 committed by Ben McIlwain
parent 969d9483ae
commit 6641f105b7
12 changed files with 196 additions and 72 deletions

View file

@ -14,11 +14,13 @@
package google.registry.flows.domain;
import static com.google.common.collect.Sets.union;
import static google.registry.flows.domain.DomainFlowUtils.validateFeeChallenge;
import static google.registry.model.domain.fee.Fee.FEE_CREATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER;
import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import google.registry.flows.EppException;
@ -146,23 +148,42 @@ public class DomainCreateFlow extends DomainCreateOrAllocateFlow {
Registry registry = Registry.get(getTld());
// Bill for the create.
BillingEvent.OneTime createEvent = new BillingEvent.OneTime.Builder()
.setReason(Reason.CREATE)
.setTargetId(targetId)
.setClientId(getClientId())
.setPeriodYears(command.getPeriod().getValue())
// TODO(b/29089413): the EAP fee needs to be a separate billing event.
.setCost(commandOperations.getTotalCost())
.setEventTime(now)
.setBillingTime(now.plus(isAnchorTenant()
? registry.getAnchorTenantAddGracePeriodLength()
: registry.getAddGracePeriodLength()))
.setFlags(isAnchorTenant()
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT)
: ImmutableSet.<BillingEvent.Flag>of())
.setParent(historyEntry)
.build();
BillingEvent.OneTime createEvent =
new BillingEvent.OneTime.Builder()
.setReason(Reason.CREATE)
.setTargetId(targetId)
.setClientId(getClientId())
.setPeriodYears(command.getPeriod().getValue())
.setCost(commandOperations.getCreateCost())
.setEventTime(now)
.setBillingTime(now.plus(isAnchorTenant()
? registry.getAnchorTenantAddGracePeriodLength()
: registry.getAddGracePeriodLength()))
.setFlags(isAnchorTenant()
? ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT)
: ImmutableSet.<BillingEvent.Flag>of())
.setParent(historyEntry)
.build();
ofy().save().entity(createEvent);
// Bill for EAP cost, if any.
if (!commandOperations.getEapCost().isZero()) {
BillingEvent.OneTime eapEvent =
new BillingEvent.OneTime.Builder()
.setReason(createEvent.getReason())
.setTargetId(createEvent.getTargetId())
.setClientId(createEvent.getClientId())
.setPeriodYears(createEvent.getPeriodYears())
.setCost(commandOperations.getEapCost())
.setEventTime(createEvent.getEventTime())
.setBillingTime(createEvent.getBillingTime())
.setFlags(union(createEvent.getFlags(),
ImmutableSet.of(BillingEvent.Flag.EAP)).immutableCopy())
.setParent(createEvent.getParentKey())
.build();
ofy().save().entity(eapEvent);
}
builder.addGracePeriod(GracePeriod.forBillingEvent(GracePeriodStatus.ADD, createEvent));
if (launchCreate != null && (launchCreate.getNotice() != null || hasSignedMarks)) {
builder

View file

@ -42,6 +42,7 @@ import google.registry.model.domain.DomainRenewData;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.Period;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.fee.FeeTransformCommandExtension;
import google.registry.model.domain.rgp.GracePeriodStatus;
@ -174,13 +175,16 @@ public class DomainRenewFlow extends OwnedResourceMutateFlow<DomainResource, Ren
return createOutput(
Success,
DomainRenewData.create(
newResource.getFullyQualifiedDomainName(),
newResource.getRegistrationExpirationTime()),
(feeRenew == null) ? null : ImmutableList.of(
feeRenew.createResponseBuilder()
.setCurrency(renewCost.getCurrencyUnit())
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), "renew")))
.build()));
newResource.getFullyQualifiedDomainName(), newResource.getRegistrationExpirationTime()),
(feeRenew == null)
? null
: ImmutableList.of(
feeRenew
.createResponseBuilder()
.setCurrency(renewCost.getCurrencyUnit())
.setFees(
ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW)))
.build()));
}
/** The domain has a pending transfer on it and so can't be explicitly renewed. */

View file

@ -38,6 +38,7 @@ import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainCommand.Update;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.fee.FeeTransformCommandExtension;
import google.registry.model.domain.rgp.GracePeriodStatus;
@ -187,13 +188,17 @@ public class DomainRestoreRequestFlow extends OwnedResourceMutateFlow<DomainReso
return createOutput(
Success,
null,
(feeUpdate == null) ? null : ImmutableList.of(
feeUpdate.createResponseBuilder()
.setCurrency(restoreCost.getCurrencyUnit())
.setFees(ImmutableList.of(
Fee.create(restoreCost.getAmount(), "restore"),
Fee.create(renewCost.getAmount(), "renew")))
.build()));
(feeUpdate == null)
? null
: ImmutableList.of(
feeUpdate
.createResponseBuilder()
.setCurrency(restoreCost.getCurrencyUnit())
.setFees(
ImmutableList.of(
Fee.create(restoreCost.getAmount(), FeeType.RESTORE),
Fee.create(renewCost.getAmount(), FeeType.RENEW)))
.build()));
}
/** Restore command cannot have other changes specified. */

View file

@ -36,6 +36,7 @@ import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainCommand.Transfer;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.Period;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.fee.FeeTransformCommandExtension;
import google.registry.model.eppoutput.EppResponse.ResponseExtension;
@ -161,10 +162,12 @@ public class DomainTransferRequestFlow
@Override
protected ImmutableList<? extends ResponseExtension> getTransferResponseExtensions() {
if (feeTransfer != null) {
return ImmutableList.of(feeTransfer.createResponseBuilder()
.setCurrency(renewCost.getCurrencyUnit())
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), "renew")))
.build());
return ImmutableList.of(
feeTransfer
.createResponseBuilder()
.setCurrency(renewCost.getCurrencyUnit())
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW)))
.build());
} else {
return null;
}