mirror of
https://github.com/google/nomulus.git
synced 2025-05-20 03:09:33 +02:00
Add billing account map to Registrar entity
A CurrencyUnit-to-BillingAccountEntry map is persisted in the Registrar entity. It provides flexibility for billing systems that assign different account ids for accounts under different currencies of the same registrar. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=151022753
This commit is contained in:
parent
ab9b7c613d
commit
d7e2009ddf
8 changed files with 225 additions and 39 deletions
|
@ -41,6 +41,7 @@ import com.google.common.base.Predicates;
|
|||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -48,12 +49,15 @@ import com.google.re2j.Pattern;
|
|||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Work;
|
||||
import com.googlecode.objectify.annotation.Cache;
|
||||
import com.googlecode.objectify.annotation.Embed;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.IgnoreSave;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import com.googlecode.objectify.annotation.Mapify;
|
||||
import com.googlecode.objectify.annotation.Parent;
|
||||
import com.googlecode.objectify.condition.IfNull;
|
||||
import com.googlecode.objectify.mapper.Mapper;
|
||||
import google.registry.model.Buildable;
|
||||
import google.registry.model.CreateAutoTimestamp;
|
||||
import google.registry.model.ImmutableObject;
|
||||
|
@ -62,6 +66,7 @@ import google.registry.model.Jsonifiable;
|
|||
import google.registry.model.UpdateAutoTimestamp;
|
||||
import google.registry.model.annotations.ReportedOn;
|
||||
import google.registry.model.common.EntityGroupRoot;
|
||||
import google.registry.model.registrar.Registrar.BillingAccountEntry.CurrencyMapper;
|
||||
import google.registry.util.CidrAddressBlock;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import java.security.MessageDigest;
|
||||
|
@ -74,6 +79,7 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Information about a registrar. */
|
||||
|
@ -293,6 +299,39 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
/** Identifier of registrar used in external billing system (e.g. Oracle). */
|
||||
Long billingIdentifier;
|
||||
|
||||
/**
|
||||
* Map of currency-to-billing account for the registrar.
|
||||
*
|
||||
* <p>A registrar can have different billing accounts that are denoted in different currencies.
|
||||
* This provides flexibility for billing systems that require such distinction.
|
||||
*/
|
||||
@Nullable
|
||||
@Mapify(CurrencyMapper.class)
|
||||
Map<CurrencyUnit, BillingAccountEntry> billingAccountMap;
|
||||
|
||||
/** A billing account entry for this registrar, consisting of a currency and an account Id. */
|
||||
@Embed
|
||||
static class BillingAccountEntry extends ImmutableObject {
|
||||
|
||||
CurrencyUnit currency;
|
||||
String accountId;
|
||||
|
||||
BillingAccountEntry() {};
|
||||
|
||||
BillingAccountEntry(CurrencyUnit currency, String accountId) {
|
||||
this.accountId = accountId;
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
/** Mapper to use for {@code @Mapify}. */
|
||||
static class CurrencyMapper implements Mapper<CurrencyUnit, BillingAccountEntry> {
|
||||
@Override
|
||||
public CurrencyUnit getKey(BillingAccountEntry billingAccountEntry) {
|
||||
return billingAccountEntry.currency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** URL of registrar's website. */
|
||||
String url;
|
||||
|
||||
|
@ -370,6 +409,18 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
return billingIdentifier;
|
||||
}
|
||||
|
||||
public ImmutableMap<CurrencyUnit, String> getBillingAccountMap() {
|
||||
if (billingAccountMap == null) {
|
||||
return ImmutableMap.of();
|
||||
}
|
||||
ImmutableMap.Builder<CurrencyUnit, String> billingAccountMapBuilder =
|
||||
new ImmutableMap.Builder<>();
|
||||
for (Map.Entry<CurrencyUnit, BillingAccountEntry> entry : billingAccountMap.entrySet()) {
|
||||
billingAccountMapBuilder.put(entry.getKey(), entry.getValue().accountId);
|
||||
}
|
||||
return billingAccountMapBuilder.build();
|
||||
}
|
||||
|
||||
public DateTime getLastUpdateTime() {
|
||||
return lastUpdateTime.getTimestamp();
|
||||
}
|
||||
|
@ -588,6 +639,21 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setBillingAccountMap(Map<CurrencyUnit, String> billingAccountMap) {
|
||||
if (billingAccountMap == null) {
|
||||
getInstance().billingAccountMap = null;
|
||||
} else {
|
||||
ImmutableMap.Builder<CurrencyUnit, BillingAccountEntry> billingAccountMapBuilder =
|
||||
new ImmutableMap.Builder<>();
|
||||
for (Map.Entry<CurrencyUnit, String> entry : billingAccountMap.entrySet()) {
|
||||
CurrencyUnit key = entry.getKey();
|
||||
billingAccountMapBuilder.put(key, new BillingAccountEntry(key, entry.getValue()));
|
||||
}
|
||||
getInstance().billingAccountMap = billingAccountMapBuilder.build();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRegistrarName(String registrarName) {
|
||||
getInstance().registrarName = registrarName;
|
||||
return this;
|
||||
|
|
|
@ -32,6 +32,7 @@ import google.registry.model.billing.RegistrarBillingUtils;
|
|||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.Registrar.BillingMethod;
|
||||
import google.registry.model.registrar.RegistrarAddress;
|
||||
import google.registry.tools.params.KeyValueMapParameter.CurrencyUnitToStringMap;
|
||||
import google.registry.tools.params.OptionalLongParameter;
|
||||
import google.registry.tools.params.OptionalPhoneNumberParameter;
|
||||
import google.registry.tools.params.OptionalStringParameter;
|
||||
|
@ -169,6 +170,18 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
|
|||
validateWith = OptionalLongParameter.class)
|
||||
private Optional<Long> billingId;
|
||||
|
||||
@Nullable
|
||||
@Parameter(
|
||||
names = "--billing_account_map",
|
||||
description =
|
||||
"Registrar Billing Account key-value pairs (formatted as key=value[,key=value...]), "
|
||||
+ "where key is a currency unit (USD, JPY, etc) and value is the registrar's billing "
|
||||
+ "account id for that currency.",
|
||||
converter = CurrencyUnitToStringMap.class,
|
||||
validateWith = CurrencyUnitToStringMap.class
|
||||
)
|
||||
private Map<CurrencyUnit, String> billingAccountMap;
|
||||
|
||||
@Nullable
|
||||
@Parameter(
|
||||
names = "--billing_method",
|
||||
|
@ -334,6 +347,9 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
|
|||
if (billingId != null) {
|
||||
builder.setBillingIdentifier(billingId.orNull());
|
||||
}
|
||||
if (billingAccountMap != null) {
|
||||
builder.setBillingAccountMap(billingAccountMap);
|
||||
}
|
||||
if (billingMethod != null) {
|
||||
if (oldRegistrar != null && !billingMethod.equals(oldRegistrar.getBillingMethod())) {
|
||||
Map<CurrencyUnit, Money> balances = RegistrarBillingUtils.loadBalance(oldRegistrar);
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.google.common.base.Splitter;
|
|||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
|
||||
/**
|
||||
* Combined converter and validator class for key-value map JCommander argument strings.
|
||||
|
@ -93,4 +94,17 @@ public abstract class KeyValueMapParameter<K, V>
|
|||
return Integer.parseInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
/** Combined converter and validator class for currency unit-to-string Map argument strings. */
|
||||
public static class CurrencyUnitToStringMap extends KeyValueMapParameter<CurrencyUnit, String> {
|
||||
@Override
|
||||
protected CurrencyUnit parseKey(String rawKey) {
|
||||
return CurrencyUnit.of(rawKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String parseValue(String value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue