Ability to override paymentMethod per subscription/bundle
See original GitHub issueToday, when an invoice needs to be paid, the payment code extracts the default payment method associated with the account. An invoice contains potentially several items, each of which can map to a specific bundle/subscription. A Payment matches a specific invoice. Associating a payment method with a specific subscription or bundle will only work if the invoice associated with the payment contains only one subscription/bundle (or they all share the same overridden payment method).
Fortunately we have a mechanism in catalog to group certain subscription/bundle into one invoice. This is called billingAlignment
, and we support 3 cases:
-
ACCOUNT (all subscriptions will appear on one invoice)
-
BUNDLE (all subscriptions for a given bundle will appear on one invoice)
-
SUBSCRIPTION (only a specific subscription will appear on one given invoice)
In order to override that behavior and override payment method per subscription/bundle, there are several possible designs:
- Extend the current
InvoicePaymentRoutingPluginApi
to implement that functionality. TheInvoicePaymentRoutingPluginApi
implements thePaymentRoutingPluginApi
, and that api is called fromRetryOperationCallback
to potentially break the flow or override values such as amount to be paid, currency to use, but also payment method that should be be used.
So, that code could be extended in the following way:
- Add a new table (state) to capture the paymentMethodId associated to a given bundle/subscription
- Export a new endpoint to register the paymentMethodId associated to a given bundle/subscription
- Have the
InvoicePaymentRoutingPluginApi
check whether the payment method should be overridden by looking in the new table.
The issue is that this code (InvoicePaymentRoutingPluginApi
) has not been extracted as a first class citizen plugin and is still part of Kill Bill core.
- Modification of the previous proposal but in a custom plugin
The system property org.killbill.payment.invoice.plugin
allows to specify an order of PaymentRoutingPluginApi
that will be called by RetryOperationCallback
in the priorCall
method.
This one will now need to contain “INVOICE_PAYMENT_CONTROL_PLUGIN, <name_of_new_plugin>”, in that order.
The invoiceId that will be needed can be extracted using the property PROP_IPCD_INVOICE_ID
. See for instance how this is done in InvoicePaymentRoutingPluginApi
:
final PluginProperty invoiceProp = getPluginProperty(paymentRoutingContext.getPluginProperties(), PROP_IPCD_INVOICE_ID);
Issue Analytics
- State:
- Created 9 years ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top GitHub Comments
Any news on this? This would be a great feature to have.
Since a payment happens against a specific invoice, and since a given invoice may contain multiple line items (possibly for different bundles/subscriptions), we first need to create a mechanism to group specific line items to their own invoices. This feature is tracked by https://github.com/killbill/killbill/issues/1658.
Once we have the mechanism in place to create independent invoices for specific (group of) subscription(s), this feature can easily be implemented using a payment control plugin: The payment control plugin can check which payment method to use for a specific (group of) subscription(s), and update the payment accordingly.