Add PayPal support to Payment Element Gateway

Created on 14 February 2024, about 1 year ago

Problem/Motivation

The PaymentElementGateway has been refactored to support additional payment method types in ๐Ÿ“Œ Refactor Stripe payment element for additional payment method types Fixed . At the same time, this change forces us to implement specific plugins for every supported payment method. For example, previously working PayPal payments now are no longer possible, as the gateway throws an exception on non-existing payment method plugins (see https://git.drupalcode.org/project/commerce_stripe/-/commit/bf118321d3fb...).

We'll need โœจ Add the option to not setup payment methods for future usage Fixed in order to actually being able to select PayPal, but we can nevertheless implement the plugin independently from that.

Proposed resolution

Implement the plugin.

Remaining tasks

Before we start:

  • Do we need any extra fields?
  • Any special treatment necessary?
  • Link to relevant parts of the Stripe API doc
๐Ÿ“Œ Task
Status

Active

Version

1.0

Component

Payment Element

Created by

๐Ÿ‡ฆ๐Ÿ‡นAustria agoradesign

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

Merge Requests

Comments & Activities

  • Issue created by @agoradesign
  • First commit to issue fork.
  • ๐Ÿ‡ฌ๐Ÿ‡ชGeorgia maximkashuba Batumi

    Added base PayPal support for Stripe Payment Element with on-session Payment method usage.
    Not tested with real payment, but only with test mode for Stripe.

  • First commit to issue fork.
  • Pipeline finished with Success
    9 months ago
    Total: 717s
    #253811
  • Pipeline finished with Failed
    9 months ago
    Total: 278s
    #253831
  • Pipeline finished with Success
    9 months ago
    Total: 652s
    #253842
  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom sergiur London, UK

    Merged in the latest changes from dev and fixed conflicts, switched to extend StripePaymentMethodTypeBase instead of PaymentMethodTypeBase and opened a merge request so we can patch via composer. Please review!

  • Status changed to Needs work 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States TomTech

    Thanks for the MR!

    There are a couple of items that need some work. I've left comments on the MR.

  • Assigned to sergiur
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom sergiur London, UK

    Thank you for the review! I'll be honest I mostly rerolled what was there, I should've checked the code in more detail to see what it's actually doing, my bad. Will have a look now.

  • Pipeline finished with Success
    9 months ago
    Total: 589s
    #254954
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom sergiur London, UK

    Implemented the changes, please let me know if I missed anything!

  • Pipeline finished with Success
    9 months ago
    Total: 900s
    #254998
  • Pipeline finished with Success
    9 months ago
    Total: 736s
    #255031
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sorabh.v6 Indore

    sorabh.v6 โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Success
    6 months ago
    Total: 253s
    #330901
  • First commit to issue fork.
  • Pipeline finished with Success
    2 months ago
    Total: 485s
    #440084
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathanshaw Stroud, UK

    @gaydabura why did you make the change you made to src/EventSubscriber/OrderPaymentIntentSubscriber.php?

    That change may have sigificant consequences on payment types other than paypal, so it is unlikely this can be committed with it.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine gaydabura

    @jonathanshaw I added PaymentIntent::STATUS_REQUIRES_ACTION because if the user selects PayPal (or other method which create state "require_action"), the PaymentIntent enters this state. However, if they return without completing the payment and modify their order, we need to update the PaymentIntent amount accordingly.

    I understand that this change might affect other payment methods. In this case we might need to provide more flexible logic. If you see any potential issues, let's discuss how to handle them properly.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathanshaw Stroud, UK

    if they return without completing the payment and modify their order, we need to update the PaymentIntent amount accordingly.

    @gaydabura thanks for the reply, much appreciated.

    (1) I agree that the scenario you mention is valid, and we need to be sure it addressed.

    (2) However, I'm suspect that the fix you suggest is not right. If you look at the examples screenshots in payment intent docs at https://docs.stripe.com/payments/paymentintents/lifecycle it illustrates that at the 'require_action' stage the customer is no longer concerned with verifying the amount and may not even be shown the amount. The change you made in OrderIntentSubscriber might conceivably allow other processes (like staff or price changes) to update the payment intent and change the amount charged but without the customer being aware of the final amount they were paying.

    (3) Is there are any reason why this issue of customers returning without completing the payment and modifying their order is a bigger concern with paypal than with card payments?

    (4) Given that this concern seems to be equally valid for all payment methods, I believe we should open a new issue for it and address it there for all payment methods. The general experience in the Drupal community seems to be that the more problems we try to solve in a single issue, the less likely we are to solve any of them. Smaller scoped issues make for faster progress.

    (5) I wonder if the right solution to the problem you give is in the StripeReview checkout pane. Perhaps if it finds an existing payment intent, it should check the amount of intent still matches the order price.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine gaydabura

    @jonathanshaw i have removed commit with change. Agree with you, it requires separate issue, with detailed descriptions of problem.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathanshaw Stroud, UK

    I think this is ready now.

Production build 0.71.5 2024