Search in sources :

Example 1 with InvoiceContext

use of org.killbill.billing.invoice.plugin.api.InvoiceContext in project killbill by killbill.

the class InvoicePluginDispatcher method onCompletionCall.

private void onCompletionCall(final boolean isSuccess, final LocalDate targetDate, @Nullable final DefaultInvoice originalInvoice, final List<Invoice> existingInvoices, final boolean isDryRun, final boolean isRescheduled, final CallContext callContext, // The pluginProperties list passed to plugins is mutable by the plugins
@SuppressWarnings("TypeMayBeWeakened") final LinkedList<PluginProperty> properties, final InternalTenantContext internalTenantContext) {
    final Collection<InvoicePluginApi> invoicePlugins = getInvoicePlugins(internalTenantContext).values();
    if (invoicePlugins.isEmpty()) {
        return;
    }
    // We clone the original invoice so plugins don't remove/add items
    final Invoice clonedInvoice = originalInvoice == null ? null : (Invoice) originalInvoice.clone();
    final InvoiceContext invoiceContext = new DefaultInvoiceContext(targetDate, clonedInvoice, existingInvoices, isDryRun, isRescheduled, callContext);
    for (final InvoicePluginApi invoicePlugin : invoicePlugins) {
        if (isSuccess) {
            invoicePlugin.onSuccessCall(invoiceContext, properties);
        } else {
            invoicePlugin.onFailureCall(invoiceContext, properties);
        }
    }
}
Also used : InvoicePluginApi(org.killbill.billing.invoice.plugin.api.InvoicePluginApi) InvoiceContext(org.killbill.billing.invoice.plugin.api.InvoiceContext) DefaultInvoiceContext(org.killbill.billing.invoice.api.DefaultInvoiceContext) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) DefaultInvoiceContext(org.killbill.billing.invoice.api.DefaultInvoiceContext)

Example 2 with InvoiceContext

use of org.killbill.billing.invoice.plugin.api.InvoiceContext in project killbill by killbill.

the class InvoicePluginDispatcher method priorCall.

public DateTime priorCall(final LocalDate targetDate, final List<Invoice> existingInvoices, final boolean isDryRun, final boolean isRescheduled, final CallContext callContext, // The pluginProperties list passed to plugins is mutable by the plugins
@SuppressWarnings("TypeMayBeWeakened") final LinkedList<PluginProperty> properties, final InternalTenantContext internalTenantContext) throws InvoiceApiException {
    log.debug("Invoking invoice plugins priorCall: targetDate='{}', isDryRun='{}', isRescheduled='{}'", targetDate, isDryRun, isRescheduled);
    final Map<String, InvoicePluginApi> invoicePlugins = getInvoicePlugins(internalTenantContext);
    if (invoicePlugins.isEmpty()) {
        return null;
    }
    DateTime earliestRescheduleDate = null;
    final InvoiceContext invoiceContext = new DefaultInvoiceContext(targetDate, null, existingInvoices, isDryRun, isRescheduled, callContext);
    for (final Entry<String, InvoicePluginApi> entry : invoicePlugins.entrySet()) {
        final String invoicePluginName = entry.getKey();
        final PriorInvoiceResult priorInvoiceResult = entry.getValue().priorCall(invoiceContext, properties);
        log.debug("Invoice plugin {} returned priorInvoiceResult='{}'", invoicePluginName, priorInvoiceResult);
        if (priorInvoiceResult == null) {
            // Naughty plugin...
            continue;
        }
        if (priorInvoiceResult.getRescheduleDate() != null && (earliestRescheduleDate == null || earliestRescheduleDate.compareTo(priorInvoiceResult.getRescheduleDate()) > 0)) {
            earliestRescheduleDate = priorInvoiceResult.getRescheduleDate();
            log.info("Invoice plugin {} rescheduled invoice generation to {} for targetDate {}", invoicePluginName, earliestRescheduleDate, targetDate);
        }
        if (priorInvoiceResult.isAborted()) {
            log.info("Invoice plugin {} aborted invoice generation for targetDate {}", invoicePluginName, targetDate);
            throw new InvoiceApiException(ErrorCode.INVOICE_PLUGIN_API_ABORTED, invoicePluginName);
        }
    }
    return earliestRescheduleDate;
}
Also used : InvoicePluginApi(org.killbill.billing.invoice.plugin.api.InvoicePluginApi) InvoiceContext(org.killbill.billing.invoice.plugin.api.InvoiceContext) DefaultInvoiceContext(org.killbill.billing.invoice.api.DefaultInvoiceContext) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) DefaultInvoiceContext(org.killbill.billing.invoice.api.DefaultInvoiceContext) PriorInvoiceResult(org.killbill.billing.invoice.plugin.api.PriorInvoiceResult) DateTime(org.joda.time.DateTime)

Aggregations

DefaultInvoiceContext (org.killbill.billing.invoice.api.DefaultInvoiceContext)2 InvoiceContext (org.killbill.billing.invoice.plugin.api.InvoiceContext)2 InvoicePluginApi (org.killbill.billing.invoice.plugin.api.InvoicePluginApi)2 DateTime (org.joda.time.DateTime)1 Invoice (org.killbill.billing.invoice.api.Invoice)1 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)1 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)1 PriorInvoiceResult (org.killbill.billing.invoice.plugin.api.PriorInvoiceResult)1