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...
Issue fork commerce_stripe-3389953
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
Comment #2
rszrama commentedComment #5
vmarchukComment #6
rszrama commentedThe change from
drupalSettings.commerceStripetodrupalSettings.commerceStripePaymentElementmakes sense, but I'm not sure why this MR also changes the name of the behavior fromDrupal.behaviors.commerceStripePaymentElementtoDrupal.behaviors.commerceStripePaymentElementForm. Was that really necessary? I think it's better without the "Form" suffix if we don't really need it.Comment #7
vmarchuk@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?
Comment #8
rszrama commentedGot 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. 👍🏻
Comment #10
rszrama commented