Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
10 changed files
with
641 additions
and
280 deletions.
There are no files selected for viewing
285 changes: 99 additions & 186 deletions
285
...ice/src/main/java/org/killbill/billing/invoice/usage/ContiguousIntervalUsageInArrear.java
Large diffs are not rendered by default.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
...src/main/java/org/killbill/billing/invoice/usage/details/UsageCapacityInArrearDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...c/main/java/org/killbill/billing/invoice/usage/details/UsageConsumableInArrearDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...ava/org/killbill/billing/invoice/usage/details/UsageConsumableInArrearTierUnitDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
invoice/src/main/java/org/killbill/billing/invoice/usage/details/UsageInArrearDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
36 changes: 36 additions & 0 deletions
36
.../main/java/org/killbill/billing/invoice/usage/details/UsageInArrearDetailInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...src/main/java/org/killbill/billing/invoice/usage/details/UsageInArrearTierUnitDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.