The PaymentInformation checkout pane #ajax doesn't always result in the gateway JS being loaded.

Citing ransomweaver in #2854145: Order payment method should be selectable and default:

Wow, this little change really blew up my payment gateway module! In causing an existing payment method to be selected by default, an unintended consequence is that the payment gateway doesn't load (at least for my module) the JS libraries in the initial payment information form, because buildCreditCardForm with $element['#attached']['library'][] is not run until ajax does it when you switch to add a new payment method.

This core ajax issue is implicated, I think: https://www.drupal.org/node/1988968

To work around this I have had to move my js library attaching to a hook_form_alter, which is not great since I have different js libs to load depending on test vs production, which is found from the gateway plugin config.

vasike also reported the same thing while working on checkout support for multiple gateways.

Comments

bojanz created an issue. See original summary.

vasike’s picture

Now that we have #2827144: Support multiple payment gateways on Checkout Payment information pane

I think we need this, for me it smells like critical. Payment broken in checkout.

bojanz’s picture

Priority: Major » Critical

Agreed.

  • bojanz committed 3a8cb00 on 8.x-2.x
    Issue #2854852 by bojanz: Payment gateway JS is not always loaded
    
bojanz’s picture

Status: Active » Fixed

API expanded, Braintree updated to use it http://cgit.drupalcode.org/commerce_braintree/commit/?id=e2afa39

@vasike
Please update Stripe and Paymill.

sumanthkumarc’s picture

@bojanz and @vasike , just created new issues at stripe: https://www.drupal.org/node/2861409 and Paymill: https://www.drupal.org/node/2861410 , trying to help :P

vasike’s picture

Stripe and Paymill updated

@Bojan: what about keeping the library attach in buildCreditCardForm for Braintree?

http://cgit.drupalcode.org/commerce_braintree/tree/src/PluginForm/Hosted...

bojanz’s picture

That's the module-specific form JS, which should stay there. Our problem is only with the dependencies of such JS files. (You can load one level via #ajax but not several)

Status: Fixed » Closed (fixed)

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