Utilize template method pattern for ensuring PaymentGatewayBase::create is always called

Created on 5 August 2024, about 1 month ago
Updated 16 August 2024, about 1 month ago

Describe your bug or feature request.

📌 Drupal 11 compatibility fixes for commerce Needs work has introduced a change to how payment gateways are initialized. Relevant code was moved from __construct to create to streamline dependency injection. Currently, there are 2 issues we are facing:
1. all contrib payment gateways will likely have to adapt to the new strategy but it hasn't been documented in any way
2. ensure the parent create method is always invoked as the correct initialization of the payment gateway plugin depends on it.

The (1) can be addressed by issuing the Change Notice. But before we do that I believe it makes sense to provide a code-level assurance to ensure parent create is called (2). The proposal is:

1. Declare PaymentGatewayBase::create as final.
2. Provide PaymentGatewayBase::init protected method that will be called from within PaymentGatewayBase::create. Pass the container to the PaymentGatewayBase::init so each payment gateway can perform dependency injection.

While this would address the problem with Payment Gateways, there are probably other plugin types declared as part of the Commerce Core that could use a similar approach.

📌 Task
Status

Closed: works as designed

Version

3.0

Component

Payment

Created by

🇳🇴Norway zaporylie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @zaporylie
  • Pipeline finished with Success
    about 1 month ago
    Total: 929s
    #244881
  • 🇮🇱Israel jsacksick

    1. all contrib payment gateways will likely have to adapt to the new strategy but it hasn't been documented in any way

    This is a common pattern, used everywhere in Drupal core... And also, we can fix that and update the documentation and/or create a change record. As a reminder, Commerce 3 hasn't been released yet...

    Also, this change would break Braintree & Stripe for example, since they're implementing their own init() method with a different signature (the container isn't passed).

    Still unsure I wanna proceed with this... I know at the very least Braintree, Paypal, Stripe are already ready and work with the current 3.x dev, and we can update the others if necessary.

  • Status changed to Closed: works as designed about 1 month ago
  • 🇳🇴Norway zaporylie

    I've been thinking about this for a while, and it grew on me. So I am ok just closing this with a CR in place.

Production build 0.71.5 2024