Skip to content

Commit

Permalink
invoice: Rework usage detail
Browse files Browse the repository at this point in the history
1. Modify json to make it different for capacity and consumable (otherwsie fields get too confusing)
2. Remove reconcialation logic; instead implement late usage data scenario by passing existing usage into existing logic -- to ensure correct tier amount/pricing is invoked

Code is stable'ish but needs major refactoring
  • Loading branch information
sbrossie committed Feb 10, 2018
1 parent e9e7db6 commit 7f8d89b
Show file tree
Hide file tree
Showing 10 changed files with 641 additions and 280 deletions.

Large diffs are not rendered by default.

@@ -0,0 +1,68 @@
/*
* Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2018 The Billing Project, LLC
*
* The Billing Project licenses this file to you 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 org.killbill.billing.invoice.usage.details;

import java.math.BigDecimal;
import java.util.List;

import org.killbill.billing.util.jackson.ObjectMapper;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Preconditions;

public class UsageCapacityInArrearDetail implements UsageInArrearDetail {

private final List<UsageInArrearTierUnitDetail> tierDetails;
private BigDecimal amount;

@JsonCreator
public UsageCapacityInArrearDetail(@JsonProperty("tierDetails") List<UsageInArrearTierUnitDetail> tierDetails,
@JsonProperty("amount") BigDecimal amount) {
this.tierDetails = tierDetails;
this.amount = amount;
}

public BigDecimal getAmount() {
return amount;
}

public void setAmount(BigDecimal amount) {
this.amount = amount;
}

public List<UsageInArrearTierUnitDetail> getTierDetails() {
return tierDetails;
}

// TODO STEPH optimize
@Override
public String toJson(final ObjectMapper objectMapper) {
String result = null;
if (tierDetails != null && tierDetails.size() > 0){
try {
result = objectMapper.writeValueAsString(tierDetails);
} catch (JsonProcessingException e) {
Preconditions.checkState(false, e.getMessage());
}
}
return result;
}

}
@@ -0,0 +1,74 @@
/*
* Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2018 The Billing Project, LLC
*
* The Billing Project licenses this file to you 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 org.killbill.billing.invoice.usage.details;

import java.math.BigDecimal;
import java.util.List;

import org.killbill.billing.util.jackson.ObjectMapper;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Preconditions;

public class UsageConsumableInArrearDetail implements UsageInArrearDetail {

private final List<UsageConsumableInArrearTierUnitDetail> tierDetails;
private BigDecimal amount;

public UsageConsumableInArrearDetail(@JsonProperty("tierDetails") List<UsageConsumableInArrearTierUnitDetail> tierDetails) {
this(tierDetails, computeAmount(tierDetails));
}

@JsonCreator
public UsageConsumableInArrearDetail(@JsonProperty("tierDetails") List<UsageConsumableInArrearTierUnitDetail> tierDetails,
@JsonProperty("amount") BigDecimal amount) {
this.tierDetails = tierDetails;
this.amount = amount;
}

public BigDecimal getAmount() {
return amount;
}

@Override
public String toJson(final ObjectMapper objectMapper) {
String result = null;
if (tierDetails != null && tierDetails.size() > 0){
try {
result = objectMapper.writeValueAsString(tierDetails);
} catch (JsonProcessingException e) {
Preconditions.checkState(false, e.getMessage());
}
}
return result;
}

public List<UsageConsumableInArrearTierUnitDetail> getTierDetails() {
return tierDetails;
}

private static BigDecimal computeAmount(final List<UsageConsumableInArrearTierUnitDetail> tierDetails) {
BigDecimal result = BigDecimal.ZERO;
for (UsageConsumableInArrearTierUnitDetail toBeBilled : tierDetails) {
result = result.add(toBeBilled.getAmount());
}
return result;
}
}
@@ -0,0 +1,73 @@
/*
* Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2018 The Billing Project, LLC
*
* The Billing Project licenses this file to you 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 org.killbill.billing.invoice.usage.details;

import java.math.BigDecimal;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class UsageConsumableInArrearTierUnitDetail extends UsageInArrearTierUnitDetail {

private final int tierBlockSize;
private BigDecimal amount;

public UsageConsumableInArrearTierUnitDetail(int tier, String tierUnit, BigDecimal tierPrice, Integer tierBlockSize, Integer quantity) {
this(tier, tierUnit, tierPrice, tierBlockSize, quantity, tierPrice.multiply(new BigDecimal(quantity)));
}

@JsonCreator
public UsageConsumableInArrearTierUnitDetail(@JsonProperty("tier") int tier,
@JsonProperty("tierUnit") String tierUnit,
@JsonProperty("tierPrice") BigDecimal tierPrice,
@JsonProperty("tierBlockSize") Integer tierBlockSize,
@JsonProperty("quantity") Integer quantity,
@JsonProperty("amount") BigDecimal amount) {
super(tier, tierUnit, tierPrice, quantity);
this.amount = amount;
this.tierBlockSize = tierBlockSize;
}

public int getTier() {
return tier;
}

public String getTierUnit() {
return tierUnit;
}

public BigDecimal getTierPrice() {
return tierPrice;
}

public Integer getQuantity() {
return quantity;
}

public BigDecimal getAmount() {
return amount;
}

public void setAmount(BigDecimal amount) {
this.amount = amount;
}

public int getTierBlockSize() {
return tierBlockSize;
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2018 The Billing Project, LLC
*
* The Billing Project licenses this file to you 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 org.killbill.billing.invoice.usage.details;

import java.math.BigDecimal;

import org.killbill.billing.util.jackson.ObjectMapper;

public interface UsageInArrearDetail {

BigDecimal getAmount();

String toJson(ObjectMapper mapper);
}
@@ -0,0 +1,36 @@
/*
* Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2018 The Billing Project, LLC
*
* The Billing Project licenses this file to you 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 org.killbill.billing.invoice.usage.details;

import java.math.BigDecimal;

import org.killbill.billing.util.jackson.ObjectMapper;

public class UsageInArrearDetailInitializer implements UsageInArrearDetail {

@Override
public BigDecimal getAmount() {
return BigDecimal.ZERO;
}

@Override
public String toJson(final ObjectMapper mapper) {
return null;
}

}
@@ -0,0 +1,58 @@
/*
* Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2018 The Billing Project, LLC
*
* The Billing Project licenses this file to you 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 org.killbill.billing.invoice.usage.details;

import java.math.BigDecimal;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class UsageInArrearTierUnitDetail {

protected final int tier;
protected final String tierUnit;
protected final BigDecimal tierPrice;
protected Integer quantity;

@JsonCreator
public UsageInArrearTierUnitDetail(@JsonProperty("tier") int tier,
@JsonProperty("tierUnit") String tierUnit,
@JsonProperty("tierPrice") BigDecimal tierPrice,
@JsonProperty("quantity") Integer quantity) {
this.tier = tier;
this.tierUnit = tierUnit;
this.tierPrice = tierPrice;
this.quantity = quantity;
}

public int getTier() {
return tier;
}

public String getTierUnit() {
return tierUnit;
}

public BigDecimal getTierPrice() {
return tierPrice;
}

public Integer getQuantity() {
return quantity;
}
}

0 comments on commit 7f8d89b

Please sign in to comment.