Problem/Motivation

Right now, you can alter Payment Element settings via a form alter, and I believe you can do the same with the Card Element. However, for discoverability / DX reasons, I believe we should make a straightforward alter hook as well.

Proposed resolution

Use a new alter hook called hook_commerce_stripe_payment_element_settings_alter() that passes the settings array as the $data parameter. I'd like to see a correlated hook_commerce_stripe_card_element_settings_alter() as well, which should just need to go in its PaymentMethodAddForm plugin.

Given these plugins aren't services ... I think the easiest way to get the module handler will just be the static container, e.g.:

\Drupal::moduleHandler()->alter('hook_name', $data);

cf. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rszrama created an issue. See original summary.

rszrama’s picture

Issue summary: View changes

vmarchuk made their first commit to this issue’s fork.

vmarchuk’s picture

Status: Active » Needs review
rszrama’s picture

Status: Needs review » Needs work

The change from drupalSettings.commerceStripe to drupalSettings.commerceStripePaymentElement makes sense, but I'm not sure why this MR also changes the name of the behavior from Drupal.behaviors.commerceStripePaymentElement to Drupal.behaviors.commerceStripePaymentElementForm. Was that really necessary? I think it's better without the "Form" suffix if we don't really need it.

vmarchuk’s picture

@rszrama

> I think it's better without the "Form" suffix if we don't really need it.
Because for most payment gateways, we use Form suffixes in the behavior name.
See examples below:
commerceAuthorizeNetForm
commerceBraintreeForm
commerceSquareForm
commerceCyberSourceForm

Also, it's a bit confusing if the behavior name and the JS settings name are the same (not a big deal, but still).
What do you think?

rszrama’s picture

Got it. In some of those cases, the API in question is actually described as a form, but since Stripe doesn't use that language for the Payment Element iframe, let's leave it as is. I'm not concerned about the behavior and the settings array having the same key. 👍🏻

  • rszrama committed ad00eeb8 on 8.x-1.x authored by vmarchuk
    Issue #3389953: Make it easier to alter Payment Element JavaScript...
rszrama’s picture

Title: Add an alter hook for Stripe JavaScript settings » Make it easier to alter Payment Element JavaScript settings
Assigned: vmarchuk » Unassigned
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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