TenantId in Custom Invoice Formatter

71 views
Skip to first unread message

Florian Kunkel

unread,
Apr 25, 2024, 11:49:59 AM4/25/24
to Kill Bill users mailing-list
Hello


I am writing a custom invoice formatter and need the externalKey of the account to ask another web service for additional customer data I would like to add to the HTML invoice.

I got the invoice from this call:

org.killbill.billing.invoice.plugin.api.InvoiceFormatterFactory
    .createInvoiceFormatter(
        final String defaultLocale,
        final String catalogBundlePath,
        final Invoice invoice,
        final Locale locale,
        final CurrencyConversionApi currencyConversionApi,
        ResourceBundle bundle,
        ResourceBundle defaultBundle)


From the invoice I got the account id:

org.killbill.billing.invoice.api.Invoice
    .getAccountId()


And to get the account with the externalKey I tried to ask the AccountUserApi:

org.killbill.billing.account.api.AccountUserApi
    .getAccountById(
        UUID accountId,
        TenantContext context);


My problem is that I cannot find the tenant id. From other plugins, I am used to get some sort of context, like org.killbill.billing.util.callcontext.TenantContext or org.killbill.billing.invoice.plugin.api.InvoiceContext. But the InvoiceFormatterFactory does not provide such.

For now, I use the known tenant api key of our one and only tenant to get the tenant id via org.killbill.billing.tenant.api.TenantUserApi#getTenantByApiKey. It works like a charm. But we plan to have more than one tenant eventually. So that's not a long term solution.

Does anybody have a trick to obtain the tenant id that isn't too dirty? Perhaps I am just blind ...


Best regards
Florian

karan bansal

unread,
Apr 25, 2024, 1:37:08 PM4/25/24
to Kill Bill users mailing-list
Hi Florian,

Have you referred to the example plugin here that passes the tenant context?

Regards
Karan

Florian Kunkel

unread,
Apr 26, 2024, 4:51:07 AM4/26/24
to Kill Bill users mailing-list
Hi Karan

Thank you for replying so quickly.

This example plugin is where I get all my inspirations from ;) Unfortunately, I still don't see the TenantContext following your link … In which parameter is it hidden?

Best regards
Florian

karan bansal

unread,
Apr 30, 2024, 2:33:59 PM4/30/24
to Kill Bill users mailing-list
Hi Florian,

Thank you for pointing out the mistake. Looks like I wanted to point you to this repo that also has a similar name. I have raised https://github.com/killbill/killbill-custom-invoice-formatter/issues/5 to make tenant context available for killbill-custom-invoice-formatter too.

Regards
Karan

Florian Kunkel

unread,
May 3, 2024, 12:42:57 PM5/3/24
to Kill Bill users mailing-list
Hi Karan

That's awesome. Thank you so much.

Best regards
Florian
Reply all
Reply to author
Forward
0 new messages