mirror of
https://github.com/google/nomulus.git
synced 2025-08-06 01:35:17 +02:00
Reconcile FeesAndCredits handling in price customization
Also adds a mechanism to ensure that fee extensions are included when custom pricing logic adds a custom fee, and fixes up the domain restore flow to properly use the restore price. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=142715136
This commit is contained in:
parent
720f03cc17
commit
9d9c527917
19 changed files with 312 additions and 182 deletions
|
@ -15,8 +15,6 @@
|
|||
package google.registry.flows.custom;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static java.math.BigDecimal.TEN;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Splitter;
|
||||
|
@ -26,7 +24,7 @@ import com.google.common.net.InternetDomainName;
|
|||
import google.registry.flows.EppException;
|
||||
import google.registry.flows.SessionMetadata;
|
||||
import google.registry.flows.domain.DomainPricingLogic;
|
||||
import google.registry.flows.domain.DomainPricingLogic.FeesAndCredits;
|
||||
import google.registry.flows.domain.FeesAndCredits;
|
||||
import google.registry.model.domain.fee.BaseFee;
|
||||
import google.registry.model.domain.fee.BaseFee.FeeType;
|
||||
import google.registry.model.domain.fee.Credit;
|
||||
|
@ -34,10 +32,14 @@ import google.registry.model.domain.fee.Fee;
|
|||
import google.registry.model.eppinput.EppInput;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
|
||||
/** A class to customize {@link DomainPricingLogic} for testing. */
|
||||
public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
||||
|
||||
private static final BigDecimal ONE_HUNDRED_BUCKS = Money.of(CurrencyUnit.USD, 100).getAmount();
|
||||
|
||||
protected TestDomainPricingCustomLogic(EppInput eppInput, SessionMetadata sessionMetadata) {
|
||||
super(eppInput, sessionMetadata);
|
||||
}
|
||||
|
@ -48,14 +50,16 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
|||
InternetDomainName domainName = priceParameters.domainName();
|
||||
if (domainName.parent().toString().equals("flags")) {
|
||||
FeesAndCredits feesAndCredits = priceParameters.feesAndCredits();
|
||||
FeesAndCredits.Builder feesBuilder =
|
||||
new FeesAndCredits.Builder().setCurrency(feesAndCredits.getCurrency());
|
||||
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);
|
||||
feesBuilder.setFeeExtensionRequired(true);
|
||||
}
|
||||
return new FeesAndCredits(
|
||||
feesAndCredits.getCurrency(), Iterables.toArray(baseFeeBuilder.build(), BaseFee.class));
|
||||
return feesBuilder.setFeesAndCredits(baseFeeBuilder.build()).build();
|
||||
} else {
|
||||
return priceParameters.feesAndCredits();
|
||||
}
|
||||
|
@ -69,7 +73,7 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
|||
.getFullyQualifiedDomainName()
|
||||
.startsWith("non-free-update"))
|
||||
? addCustomFee(
|
||||
priceParameters.feesAndCredits(), Fee.create(BigDecimal.valueOf(100), FeeType.UPDATE))
|
||||
priceParameters.feesAndCredits(), Fee.create(ONE_HUNDRED_BUCKS, FeeType.UPDATE))
|
||||
: priceParameters.feesAndCredits();
|
||||
}
|
||||
|
||||
|
@ -78,7 +82,7 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
|||
throws EppException {
|
||||
return (priceParameters.domainName().toString().startsWith("costly-renew"))
|
||||
? addCustomFee(
|
||||
priceParameters.feesAndCredits(), Fee.create(BigDecimal.valueOf(100), FeeType.RENEW))
|
||||
priceParameters.feesAndCredits(), Fee.create(ONE_HUNDRED_BUCKS, FeeType.RENEW))
|
||||
: priceParameters.feesAndCredits();
|
||||
}
|
||||
|
||||
|
@ -87,25 +91,24 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
|||
throws EppException {
|
||||
return (priceParameters.domainName().toString().startsWith("expensive"))
|
||||
? addCustomFee(
|
||||
priceParameters.feesAndCredits(), Fee.create(BigDecimal.valueOf(100), FeeType.TRANSFER))
|
||||
priceParameters.feesAndCredits(), Fee.create(ONE_HUNDRED_BUCKS, FeeType.TRANSFER))
|
||||
: priceParameters.feesAndCredits();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeesAndCredits customizeUpdatePrice(UpdatePriceParameters priceParameters) {
|
||||
return (priceParameters.domainName().toString().startsWith("non-free-update"))
|
||||
? addCustomFee(priceParameters.feesAndCredits(), Fee.create(TEN, FeeType.UPDATE))
|
||||
? addCustomFee(
|
||||
priceParameters.feesAndCredits(), Fee.create(ONE_HUNDRED_BUCKS, FeeType.UPDATE))
|
||||
: priceParameters.feesAndCredits();
|
||||
}
|
||||
|
||||
private static FeesAndCredits addCustomFee(FeesAndCredits feesAndCredits, BaseFee customFee) {
|
||||
List<BaseFee> newFeesAndCredits =
|
||||
new ImmutableList.Builder<BaseFee>()
|
||||
.addAll(feesAndCredits.getFeesAndCredits())
|
||||
.add(customFee)
|
||||
.build();
|
||||
return new FeesAndCredits(
|
||||
feesAndCredits.getCurrency(), toArray(newFeesAndCredits, BaseFee.class));
|
||||
return feesAndCredits
|
||||
.asBuilder()
|
||||
.setFeeExtensionRequired(true)
|
||||
.addFeeOrCredit(customFee)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static BaseFee domainNameToFeeOrCredit(InternetDomainName domainName) {
|
||||
|
|
|
@ -679,7 +679,7 @@ public class DomainApplicationUpdateFlowTest
|
|||
newDomainApplication("non-free-update.tld").asBuilder().setRepoId("1-ROID").build());
|
||||
setEppInput(
|
||||
"domain_update_sunrise_fee.xml",
|
||||
ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12"));
|
||||
ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00"));
|
||||
clock.advanceOneMilli();
|
||||
thrown.expect(FeesMismatchException.class);
|
||||
runFlow();
|
||||
|
|
|
@ -84,13 +84,30 @@ import org.junit.Test;
|
|||
public class DomainTransferRequestFlowTest
|
||||
extends DomainTransferFlowTestCase<DomainTransferRequestFlow, DomainResource> {
|
||||
|
||||
private static final ImmutableMap<String, String> BASE_FEE_MAP =
|
||||
new ImmutableMap.Builder<String, String>()
|
||||
.put("DOMAIN", "example.tld")
|
||||
.put("YEARS", "1")
|
||||
.put("AMOUNT", "11.00")
|
||||
.build();
|
||||
private static final ImmutableMap<String, String> FEE_06_MAP =
|
||||
ImmutableMap.of("FEE_VERSION", "0.6", "FEE_NS", "fee");
|
||||
new ImmutableMap.Builder<String, String>()
|
||||
.putAll(BASE_FEE_MAP)
|
||||
.put("FEE_VERSION", "0.6")
|
||||
.put("FEE_NS", "fee")
|
||||
.build();
|
||||
private static final ImmutableMap<String, String> FEE_11_MAP =
|
||||
ImmutableMap.of("FEE_VERSION", "0.11", "FEE_NS", "fee11");
|
||||
new ImmutableMap.Builder<String, String>()
|
||||
.putAll(BASE_FEE_MAP)
|
||||
.put("FEE_VERSION", "0.11")
|
||||
.put("FEE_NS", "fee11")
|
||||
.build();
|
||||
private static final ImmutableMap<String, String> FEE_12_MAP =
|
||||
ImmutableMap.of("FEE_VERSION", "0.12", "FEE_NS", "fee12");
|
||||
|
||||
new ImmutableMap.Builder<String, String>()
|
||||
.putAll(BASE_FEE_MAP)
|
||||
.put("FEE_VERSION", "0.12")
|
||||
.put("FEE_NS", "fee12")
|
||||
.build();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -532,13 +549,16 @@ public class DomainTransferRequestFlowTest
|
|||
setupDomain("expensive-domain", "foo");
|
||||
clock.advanceOneMilli();
|
||||
doSuccessfulTest(
|
||||
"domain_transfer_request_wildcard.xml",
|
||||
"domain_transfer_request_response_wildcard.xml",
|
||||
"domain_transfer_request_fee.xml",
|
||||
"domain_transfer_request_response_fees.xml",
|
||||
domain.getRegistrationExpirationTime().plusYears(3),
|
||||
new ImmutableMap.Builder<String, String>()
|
||||
.put("DOMAIN", "expensive-domain.foo")
|
||||
.put("YEARS", "3")
|
||||
.put("AMOUNT", "133.00")
|
||||
.put("EXDATE", "2004-09-08T22:00:00.0Z")
|
||||
.put("FEE_VERSION", "0.6")
|
||||
.put("FEE_NS", "fee")
|
||||
.build(),
|
||||
Optional.of(Money.of(USD, 133)));
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ import google.registry.flows.ResourceFlowUtils.StatusNotClientSettableException;
|
|||
import google.registry.flows.domain.DomainFlowUtils.DuplicateContactForRoleException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.EmptySecDnsUpdateException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeesMismatchException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeesRequiredForNonFreeUpdateException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeesRequiredForNonFreeOperationException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.LinkedResourceInPendingDeleteProhibitsOperationException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.LinkedResourcesDoNotExistException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.MaxSigLifeChangeNotSupportedException;
|
||||
|
@ -1196,7 +1196,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
|
|||
setEppInput("domain_update_wildcard.xml", ImmutableMap.of("DOMAIN", "non-free-update.tld"));
|
||||
persistReferencedEntities();
|
||||
persistDomain();
|
||||
thrown.expect(FeesRequiredForNonFreeUpdateException.class);
|
||||
thrown.expect(FeesRequiredForNonFreeOperationException.class);
|
||||
runFlow();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
<transfer op="request">
|
||||
<domain:transfer
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.tld</domain:name>
|
||||
<domain:period unit="y">1</domain:period>
|
||||
<domain:name>%DOMAIN%</domain:name>
|
||||
<domain:period unit="y">%YEARS%</domain:period>
|
||||
<domain:authInfo>
|
||||
<domain:pw roid="JD1234-REP">2fooBAR</domain:pw>
|
||||
</domain:authInfo>
|
||||
|
@ -13,7 +13,7 @@
|
|||
<extension>
|
||||
<fee:transfer xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee>11.00</fee:fee>
|
||||
<fee:fee>%AMOUNT%</fee:fee>
|
||||
</fee:transfer>
|
||||
</extension>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
|
|
|
@ -15,6 +15,13 @@
|
|||
<domain:exDate>%EXDATE%</domain:exDate>
|
||||
</domain:trnData>
|
||||
</resData>
|
||||
<extension>
|
||||
<fee:trnData xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee description="renew">33.00</fee:fee>
|
||||
<fee:fee description="transfer">100.00</fee:fee>
|
||||
</fee:trnData>
|
||||
</extension>
|
||||
<trID>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
<svTRID>server-trid</svTRID>
|
Loading…
Add table
Add a link
Reference in a new issue