Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to link usage tracking ids with generated invoices. #1068

Merged
merged 8 commits into from
Dec 4, 2018
2 changes: 2 additions & 0 deletions api/src/main/java/org/killbill/billing/usage/RawUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface RawUsage {
String getUnitType();

Long getAmount();

String getTrackingId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ public void beforeClass() throws Exception {
return;
}


final InvoiceConfig defaultInvoiceConfig = new ConfigurationObjectFactory(skifeConfigSource).build(InvoiceConfig.class);
invoiceConfig = new ConfigurableInvoiceConfig(defaultInvoiceConfig);
final Injector g = Guice.createInjector(Stage.PRODUCTION, new BeatrixIntegrationModule(configSource, clock, invoiceConfig));
Expand Down Expand Up @@ -596,7 +595,6 @@ public Payment apply(@Nullable final Void input) {
}, events);
}


protected Payment refundPaymentWithInvoiceItemAdjAndCheckForCompletion(final Account account, final Payment payment, final Map<UUID, BigDecimal> iias, final NextEvent... events) {
return refundPaymentWithInvoiceItemAdjAndCheckForCompletion(account, payment, payment.getPurchasedAmount(), payment.getCurrency(), iias, events);
}
Expand Down Expand Up @@ -888,7 +886,6 @@ protected void remove_AUTO_PAY_OFF_Tag(final UUID id, final ObjectType type, fin
remove_account_Tag(id, ControlTagType.AUTO_PAY_OFF, type, additionalEvents);
}


protected void remove_AUTO_INVOICING_OFF_Tag(final UUID id, final ObjectType type, final NextEvent... additionalEvents) throws TagDefinitionApiException, TagApiException {
remove_account_Tag(id, ControlTagType.AUTO_INVOICING_OFF, type, additionalEvents);
}
Expand All @@ -897,8 +894,7 @@ protected void remove_AUTO_INVOICING_DRAFT_Tag(final UUID id, final ObjectType t
remove_account_Tag(id, ControlTagType.AUTO_INVOICING_DRAFT, type, additionalEvents);
}


private void remove_account_Tag(final UUID id, final ControlTagType controlTagType, final ObjectType type, final NextEvent... additionalEvents) throws TagDefinitionApiException, TagApiException {
private void remove_account_Tag(final UUID id, final ControlTagType controlTagType, final ObjectType type, final NextEvent... additionalEvents) throws TagDefinitionApiException, TagApiException {
busHandler.pushExpectedEvent(NextEvent.TAG);
busHandler.pushExpectedEvents(additionalEvents);
tagUserApi.removeTag(id, type, controlTagType.getId(), callContext);
Expand All @@ -918,16 +914,20 @@ private <T> T doCallAndCheckForCompletion(final Function<Void, T> f, final NextE
return result;
}

protected void recordUsageData(final UUID subscriptionId, final String unitType, final LocalDate startDate, final Long amount, final CallContext context) throws UsageApiException {
protected void recordUsageData(final UUID subscriptionId, final String trackingId, final String unitType, final LocalDate startDate, final Long amount, final CallContext context) throws UsageApiException {
final List<UsageRecord> usageRecords = new ArrayList<UsageRecord>();
usageRecords.add(new UsageRecord(startDate, amount));
final List<UnitUsageRecord> unitUsageRecords = new ArrayList<UnitUsageRecord>();
unitUsageRecords.add(new UnitUsageRecord(unitType, usageRecords));
final SubscriptionUsageRecord record = new SubscriptionUsageRecord(subscriptionId, UUID.randomUUID().toString(), unitUsageRecords);
final SubscriptionUsageRecord record = new SubscriptionUsageRecord(subscriptionId, trackingId, unitUsageRecords);
usageUserApi.recordRolledUpUsage(record, context);
}


protected void recordUsageData(final SubscriptionUsageRecord usageRecord, final CallContext context) throws UsageApiException {
usageUserApi.recordRolledUpUsage(usageRecord, context);
}

protected void removeUsageData(final UUID subscriptionId, final String unitType, final LocalDate recordedDate) {
dbi.withHandle(new HandleCallback<Void>() {
@Override
Expand All @@ -939,7 +939,6 @@ public Void withHandle(final Handle handle) throws Exception {
});
}


protected static class TestDryRunArguments implements DryRunArguments {

private final DryRunType dryRunType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
Expand Down Expand Up @@ -720,7 +721,7 @@ public void testWithSuperflousRepairedItems() throws Exception {
newItems.add(recurring3);
newItems.add(repair3);
shellInvoice.addInvoiceItems(newItems);
invoiceDao.createInvoice(shellInvoice, new FutureAccountNotifications(), internalCallContext);
invoiceDao.createInvoice(shellInvoice, ImmutableSet.of(), new FutureAccountNotifications(), internalCallContext);


// Move ahead one month, verify nothing from previous data was generated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,8 @@ public void testBCDChangeForConsumableInArrearPlan() throws Exception {
assertNull(bpSubscription.getSubscriptionBase().getChargedThroughDate());

// Record usage for first month
recordUsageData(aoSubscription.getId(), "bullets", new LocalDate(2012, 4, 5), 100L, callContext);
recordUsageData(aoSubscription.getId(), "bullets", new LocalDate(2012, 4, 15), 100L, callContext);
recordUsageData(aoSubscription.getId(), "tracking-1", "bullets", new LocalDate(2012, 4, 5), 100L, callContext);
recordUsageData(aoSubscription.getId(), "tracking-1", "bullets", new LocalDate(2012, 4, 15), 100L, callContext);

// 2012-05-01
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.NULL_INVOICE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
Expand Down Expand Up @@ -841,8 +841,8 @@ public void testBCDChangeForConsumableInArrearPlan() throws Exception {
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 5), InvoiceItemType.USAGE, BigDecimal.ZERO));

// Record usage for second month
recordUsageData(aoSubscription.getId(), "bullets", new LocalDate(2012, 5, 5), 100L, callContext);
recordUsageData(aoSubscription.getId(), "bullets", new LocalDate(2012, 6, 4), 100L, callContext);
recordUsageData(aoSubscription.getId(), "tracking-1", "bullets", new LocalDate(2012, 5, 5), 100L, callContext);
recordUsageData(aoSubscription.getId(), "tracking-1", "bullets", new LocalDate(2012, 6, 4), 100L, callContext);

// 2012-06-05
busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
Expand Down
Loading