Only one mandate per account: mandate stored as an account custom field instead of on the payment method

Open
#45 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java

Research direction

Start in src/main/java/org/killbill/billing/plugin/gocardless/GoCardlessPaymentPluginApi.java: addPaymentMethod writes the account custom field near L340 and getMandateId reads it back at L141. Copy the table shape from a sibling plugin's DDL under src/main/resources, add gocardless_payment_methods/gocardless_responses keyed on kb_payment_method_id, resolve the mandate from kbPaymentMethodId in purchasePayment, and implement getPaymentMethods/getPaymentMethodDetail/deletePaymentMethod/resetPaymentMethods. Done when a second payment method keeps its own mandate and existing GOCARDLESS_MANDATE_ID custom fields migrate onto the account's default method.

Written by the indexing model from the issue text.

Description

Problem

The GoCardless mandate is stored as a single account-level custom field named GOCARDLESS_MANDATE_ID, rather than being associated with the Kill Bill payment method.

Written in addPaymentMethod:

https://github.com/killbill/killbill-gocardless-plugin/blob/main/src/main/java/org/killbill/billing/plugin/gocardless/GoCardlessPaymentPluginApi.java#L340-L342

Read back in getMandateId, which returns the first match and stops:

https://github.com/killbill/killbill-gocardless-plugin/blob/main/src/main/java/org/killbill/billing/plugin/gocardless/GoCardlessPaymentPluginApi.java#L141-L152

Consequences

  1. One mandate per Kill Bill account, permanently. Adding a second payment method attempts to add a second custom field with the same name on the same account, which CustomFieldApiExceptions — so the second mandate cannot be stored at all.
  2. kbPaymentMethodId is ignored on the payment path. purchasePayment resolves the mandate from kbAccountId, never from the payment method it was actually asked to charge. If an account somehow ended up with two payment methods, both would charge the same mandate.
  3. No multi-scheme support. A customer cannot hold, say, a BACS mandate and a SEPA mandate, which is a normal requirement for a business collecting across the UK and the EU.
  4. deletePaymentMethod is a no-op, so the custom field outlives the payment method and the account is left permanently pinned to a stale mandate.
  5. getPaymentMethods always returns an empty list and getPaymentMethodDetail returns an empty GoCardlessPaymentMethodPlugin, so the mandate is invisible to KAUI and to the API.
  6. No plugin tables. Unlike the other Kill Bill payment plugins, there is no gocardless_payment_methods / gocardless_responses schema, so there is nowhere natural to put this.

Proposed work

Adopt the standard killbill-plugin-framework-java shape used by the Stripe/Adyen/Braintree plugins:

  1. Add DDL for gocardless_payment_methods and gocardless_responses (plus _transactions if useful), keyed on kb_payment_method_id.
  2. Store the mandate id, scheme, customer id and bank account summary on the payment method row, not on the account.
  3. Resolve the mandate from kbPaymentMethodId in purchasePayment, not from kbAccountId.
  4. Implement getPaymentMethods / getPaymentMethodDetail / deletePaymentMethod / resetPaymentMethods against those tables.
  5. Provide a migration for existing installs that moves GOCARDLESS_MANDATE_ID custom fields onto the account's default payment method.

Item 5 matters — the custom field is the current production storage, so this cannot be a clean break.

Dominant language
Java
Stars
4
Forks
7
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from killbill/killbill-gocardless-plugin

All issues in killbill/killbill-gocardless-plugin

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.