Problem/Motivation

We are implementing a payment process by which the customer can pay a deposit, then come back in the pay the balance in the future. However, currently \Drupal\commerce_payment\Plugin\Commerce\CheckoutPane\PaymentProcess::buildPaneForm is only compatibly with paying the full balance of the order. Working round that means replicating 90 lines of code, just to change one line of code. It also means if Commerce were to make any fixes etc to the pane, you would not get them.

Proposed resolution

I can see a number of different potential approaches, not sure what you would consider to be the best approach:

  • Store the intended amount on the order: Pros: Very simple change, no complexity, matches how payment gateway is treated. Cons: Persists between new visits to the checkout and even users (already the case with gateway so may be fine). Could be a field or order data (probably the latter).
  • Private tempstore: Pros: No leaking between accounts/sessions. Cons: Introduces more dependencies.
  • Form state: Pros: No leaking between accounts/sessions. Cons: Probably requires extending PaymentProcess to set, in which case is form state the best solution?
  • Add a property/method for getting the payment amount: Pros: Extending panes can very simply set the amount they require.
  • Abstract payment creation into it's own method: Pros: Extending panes can very simply set the amount they require.
  • Refactor to break up the various bits of logic: Pros: Move flexible for other potential (but unknown) use cases. Cons: More work, should we allow other unexepected changes?

Remaining tasks

Decide on the approach, if any. Then implement!

User interface changes

None.

API changes

Allows other modules to control the payment amount.

Data model changes

Depends on the implementation.

Comments

andrewbelcher created an issue. See original summary.

andrewbelcher’s picture

I am very happy to write the code if a maintainer is happy to give some direction on what approach they would be happy with.

andrewbelcher’s picture

Assigned: Unassigned » andrewbelcher

From @bojanz in slack:

I'd be fine with moving the relevant bit of logic to a protected method for easier overriding

On that basis, I will implement a patch for the Abstract payment creation into it's own method solution.

andrewbelcher’s picture

Assigned: andrewbelcher » Unassigned
Status: Active » Needs review
StatusFileSize
new2.48 KB

Really simple patch!

bojanz’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

I'll commit in the next 24h.

andrewbelcher’s picture

Amazing, thanks @bojanz

  • bojanz committed a9e3e40 on 8.x-2.x authored by andrewbelcher
    Issue #3086504 by andrewbelcher: Allow the PraymentProcess pane to...
bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.