I’m developing an Invoice Control Plugin for Kill Bill v0.27.3, but I’m hitting compilation errors due to missing symbols and method signatures that don’t match the API in killbill-plugin-api-invoice-0.27.3.jar
Kill Bill API: org.kill-bill.billing:killbill-api:0.54.0
Invoice Plugin API: org.kill-bill.billing.plugin:killbill-plugin-api-invoice:0.27.3
Joda-Time (for retry): joda-time:2.12.5
Java 8, Maven 3.8+, macOS
----------------------------------------------
pom.xml
<dependencies>
<!-- Usage API -->
<dependency>
<groupId>org.kill-bill.billing</groupId>
<artifactId>killbill-api</artifactId>
<version>0.54.0</version>
<scope>provided</scope>
</dependency>
<!-- Invoice Plugin API -->
<dependency>
<groupId>org.kill-bill.billing.plugin</groupId>
<artifactId>killbill-plugin-api-invoice</artifactId>
<version>0.27.3</version>
<scope>provided</scope>
</dependency>
<!-- Joda-Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.12.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
----------------------------------------------------
Java code
package com.monsociete.plugin;
import org.killbill.billing.invoice.plugin.api.InvoicePluginApi;
import org.killbill.billing.invoice.plugin.api.InvoicePluginApiException;
import org.killbill.billing.invoice.plugin.api.InvoicePluginApiRetryException;
import org.killbill.billing.invoice.plugin.api.InvoiceContext;
import org.killbill.billing.invoice.api.Invoice;
import org.killbill.billing.invoice.api.InvoiceItem;
import org.killbill.billing.payment.api.PluginProperty;
import org.killbill.billing.usage.api.UsageUserApi;
import org.killbill.billing.usage.api.UsageRecord;
import org.killbill.billing.util.callcontext.TenantContext;
import org.joda.time.Period;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class MyInvoiceControlPlugin implements InvoicePluginApi {
private final UsageUserApi usageUserApi;
public MyInvoiceControlPlugin(final UsageUserApi usageUserApi) {
this.usageUserApi = usageUserApi;
}
@Override
public Iterable<InvoiceItem> getAdditionalInvoiceItems(final Invoice invoice,
final Iterable<PluginProperty> properties,
final InvoiceContext context)
throws InvoicePluginApiException {
UUID accountId = context.getAccountId();
TenantContext tenantContext = context.getTenantContext();
if (!accountHasUsagePlans(accountId, tenantContext)) {
return Collections.emptyList();
}
if (!areUsageDataUpToDate(accountId, tenantContext)) {
throw new InvoicePluginApiRetryException(Collections.singletonList(Period.hours(1)));
}
return Collections.emptyList();
}
private boolean accountHasUsagePlans(final UUID accountId,
final TenantContext tenantContext) {
return true;
}
private boolean areUsageDataUpToDate(final UUID accountId,
final TenantContext tenantContext) {
try {
LocalDate today = LocalDate.now();
LocalDateTime start = today.minusDays(1).atStartOfDay();
LocalDateTime end = today.atTime(23, 59);
List<UsageRecord> records = usageUserApi.getUsageForAccount(
accountId, start, end, tenantContext
);
return !records.isEmpty();
} catch (Exception e) {
return false;
}
}
}
--------------------------------------------------------
Is there a built-in feature that automatically prevents an invoice from being generated if usage data is not up to date?
Thank you for your feedback.
I've configured my pom.xml to use Java 11, however I'm still encountering errors that I haven't been able to resolve despite several attempts.
Pom.xml
Java code
[ERROR] /Applications/Projects/killbill/plugins/my-invoice-control-plugin/src/main/java/com/novatec/plugin/MyInvoiceControlPlugin.java:[20,8] com.monsociete.plugin.MyInvoiceControlPlugin is not abstract and does not override abstract method getAdditionalInvoiceItems(org.killbill.billing.invoice.api.Invoice,boolean,java.lang.Iterable<org.killbill.billing.payment.api.PluginProperty>,org.killbill.billing.invoice.plugin.api.InvoiceContext) in org.killbill.billing.invoice.plugin.api.InvoicePluginApi
[ERROR] /Applications/Projects/killbill/plugins/my-invoice-control-plugin/src/main/java/com/novatec/plugin/MyInvoiceControlPlugin.java:[39,34] getAdditionalInvoiceItems(org.killbill.billing.invoice.api.Invoice,boolean,java.lang.Iterable<org.killbill.billing.payment.api.PluginProperty>,org.killbill.billing.invoice.plugin.api.InvoiceContext) in com.monsociete.plugin.MyInvoiceControlPlugin cannot implement getAdditionalInvoiceItems(org.killbill.billing.invoice.api.Invoice,boolean,java.lang.Iterable<org.killbill.billing.payment.api.PluginProperty>,org.killbill.billing.invoice.plugin.api.InvoiceContext) in org.killbill.billing.invoice.plugin.api.InvoicePluginApi
[ERROR] return type java.lang.Iterable<org.killbill.billing.invoice.api.InvoiceItem> is not compatible with org.killbill.billing.invoice.plugin.api.AdditionalItemsResult
[ERROR] /Applications/Projects/killbill/plugins/my-invoice-control-plugin/src/main/java/com/novatec/plugin/MyInvoiceControlPlugin.java:[38,5] method does not override or implement a method from a supertype
[ERROR] /Applications/Projects/killbill/plugins/my-invoice-control-plugin/src/main/java/com/novatec/plugin/MyInvoiceControlPlugin.java:[45,42] cannot find symbol
[ERROR] symbol: method toCallContext(<nulltype>)
[ERROR] location: variable context of type org.killbill.billing.invoice.plugin.api.InvoiceContext
[ERROR] /Applications/Projects/killbill/plugins/my-invoice-control-plugin/src/main/java/com/novatec/plugin/MyInvoiceControlPlugin.java:[62,20] cannot find symbol
[ERROR] symbol: class DefaultOnFailureInvoiceResult
[ERROR] location: class com.monsociete.plugin.MyInvoiceControlPlugin
[ERROR] /Applications/Projects/killbill/plugins/my-invoice-control-plugin/src/main/java/com/novatec/plugin/MyInvoiceControlPlugin.java:[69,20] cannot find symbol
[ERROR] symbol: class DefaultOnSuccessInvoiceResult
[ERROR] location: class com.monsociete.plugin.MyInvoiceControlPlugin
[ERROR] /Applications/Projects/killbill/plugins/my-invoice-control-plugin/src/main/java/com/novatec/plugin/MyInvoiceControlPlugin.java:[90,55] cannot find symbol
[ERROR] symbol: method getRolledUpUsage(java.util.UUID,org.joda.time.DateTime,org.joda.time.DateTime,org.killbill.billing.util.callcontext.TenantContext)
[ERROR] location: variable usageUserApi of type org.killbill.billing.usage.api.UsageUserApi
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException