mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 02:36:03 +02:00
mv com/google/domain/registry google/registry
This change renames directories in preparation for the great package rename. The repository is now in a broken state because the code itself hasn't been updated. However this should ensure that git correctly preserves history for each file.
This commit is contained in:
parent
a41677aea1
commit
5012893c1d
2396 changed files with 0 additions and 0 deletions
212
java/google/registry/model/billing/RegistrarBillingEntry.java
Normal file
212
java/google/registry/model/billing/RegistrarBillingEntry.java
Normal file
|
@ -0,0 +1,212 @@
|
|||
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.model.billing;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static com.google.common.base.Verify.verifyNotNull;
|
||||
|
||||
import com.google.domain.registry.model.Buildable;
|
||||
import com.google.domain.registry.model.ImmutableObject;
|
||||
import com.google.domain.registry.model.JsonMapBuilder;
|
||||
import com.google.domain.registry.model.Jsonifiable;
|
||||
import com.google.domain.registry.model.registrar.Registrar;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import com.googlecode.objectify.annotation.Parent;
|
||||
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Log of monthly invoices and payments for a Registrar customer.
|
||||
*
|
||||
* <p>This is a one-off single-entry bookkeeping system. There is a separate account for each
|
||||
* (registrar, currency) pair.
|
||||
*
|
||||
* <p>You should never update these entities once they've been inserted into datastore. If you need
|
||||
* to change something, add a correction entry.
|
||||
*/
|
||||
@Entity
|
||||
public class RegistrarBillingEntry extends ImmutableObject implements Jsonifiable {
|
||||
|
||||
@Parent
|
||||
Key<Registrar> parent;
|
||||
|
||||
/** Arbitrary unique identifier. */
|
||||
@Id
|
||||
long id;
|
||||
|
||||
/**
|
||||
* External transaction identifier or {@code null} if this is an invoice entry.
|
||||
*
|
||||
* <p>This is the ID or token that the payment gateway gives us, which represents the transaction
|
||||
* in their database.
|
||||
*/
|
||||
@Nullable
|
||||
String transactionId;
|
||||
|
||||
/**
|
||||
* Time at which this entry was created.
|
||||
*
|
||||
* <p>This value is unique and monotonic for a given ({@link #parent}, {@link #currency}) pair.
|
||||
*/
|
||||
@Index
|
||||
DateTime created;
|
||||
|
||||
/** Completely arbitrary description of payment. */
|
||||
String description;
|
||||
|
||||
/**
|
||||
* Currency of transaction.
|
||||
*
|
||||
* <p>This field is identical to {@code amount.getCurrencyUnit()} and is only here so it can be
|
||||
* indexed in datastore.
|
||||
*/
|
||||
@Index
|
||||
CurrencyUnit currency;
|
||||
|
||||
/**
|
||||
* Amount and currency of invoice or payment.
|
||||
*
|
||||
* <p>This field is positive for debits (e.g. monthly invoice entries) and negative for credits
|
||||
* (e.g. credit card payment transaction entries.)
|
||||
*/
|
||||
Money amount;
|
||||
|
||||
/**
|
||||
* Balance of account for this currency.
|
||||
*
|
||||
* <p>This is {@code amount + previous.balance}.
|
||||
*/
|
||||
Money balance;
|
||||
|
||||
public Key<Registrar> getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public DateTime getCreated() {
|
||||
return verifyNotNull(created, "created missing: %s", this);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return verifyNotNull(description, "description missing: %s", this);
|
||||
}
|
||||
|
||||
public CurrencyUnit getCurrency() {
|
||||
return verifyNotNull(currency, "currency missing: %s", this);
|
||||
}
|
||||
|
||||
public Money getAmount() {
|
||||
return verifyNotNull(amount, "amount missing: %s", this);
|
||||
}
|
||||
|
||||
public Money getBalance() {
|
||||
return verifyNotNull(balance, "balance missing: %s", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toJsonMap() {
|
||||
return new JsonMapBuilder()
|
||||
.put("id", id)
|
||||
.put("transactionId", getTransactionId())
|
||||
.putString("created", getCreated())
|
||||
.put("description", getDescription())
|
||||
.putString("currency", getCurrency())
|
||||
.putString("amount", getAmount().getAmount())
|
||||
.putString("balance", getBalance().getAmount())
|
||||
.build();
|
||||
}
|
||||
|
||||
/** A builder for constructing a {@link RegistrarBillingEntry}, since it's immutable. */
|
||||
public static class Builder extends Buildable.Builder<RegistrarBillingEntry> {
|
||||
|
||||
@Nullable
|
||||
private RegistrarBillingEntry previous;
|
||||
|
||||
public Builder() {}
|
||||
|
||||
public Builder setParent(Registrar parent) {
|
||||
getInstance().parent = Key.create(parent);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCreated(DateTime created) {
|
||||
getInstance().created = created;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPrevious(@Nullable RegistrarBillingEntry previous) {
|
||||
this.previous = previous;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTransactionId(@Nullable String transactionId) {
|
||||
getInstance().transactionId = transactionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDescription(String description) {
|
||||
getInstance().description = checkNotNull(emptyToNull(description));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAmount(Money amount) {
|
||||
checkArgument(!amount.isZero(), "Amount can't be zero");
|
||||
getInstance().amount = amount;
|
||||
getInstance().currency = amount.getCurrencyUnit();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistrarBillingEntry build() {
|
||||
checkNotNull(getInstance().parent, "parent");
|
||||
checkNotNull(getInstance().created, "created");
|
||||
checkNotNull(getInstance().description, "description");
|
||||
checkNotNull(getInstance().amount, "amount");
|
||||
if (previous == null) {
|
||||
getInstance().balance = getInstance().amount;
|
||||
} else {
|
||||
getInstance().balance = previous.balance.plus(getInstance().amount);
|
||||
checkState(getInstance().parent.equals(previous.parent),
|
||||
"Parent not same as previous:\nNew: %s\nPrevious: %s",
|
||||
getInstance(), previous);
|
||||
checkState(getInstance().created.isAfter(previous.created),
|
||||
"Created timestamp not after previous:\nNew: %s\nPrevious: %s",
|
||||
getInstance(), previous);
|
||||
}
|
||||
return cloneEmptyToNull(super.build());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue