Problem/Motivation
If you attach cybersource_commerce/checkout to a page, the Flex library does not get added automatically.
This is because #3392602: Upgrade Flex payment gateway to "Microform Integration v2" split the library from flex-microform to flex-microform-test and flex-microform-production. While the commits on the branch removed the dependency, the merge commit restored it back.
Steps to reproduce
Set $form['#attached'][] = 'cybersource_commerce/checkout'; on a form, and note Flex is not available in the browser console.
Proposed resolution
This is a little tricky because we need to dynamically change the dependency based on the cybersource mode. I think we can do it with an alter hook when rebuilding libraries.
Comments
Comment #2
deviantintegral commentedComment #3
deviantintegral commentedI took a first pass at this, but realized that doing this in an alter hook won't work. I think there's actually a design issue with embedding JS in the module.
CyberSource provides two different URLs for the Flex library - one for production, and one for test. The module allows for each configured gateway to have it's own settings for production or test mode. However, the JS defines the same object ("Flex"), so if you try to embed both libraries at the same time you'll get an error. And if you only want to embed one, you can't know which payment gateway is being used when using `#attached`.
I think the prod / test mode should be moved to a global setting instead of being set on each payment gateway configuration entity. However, this could be considered a breaking change because there's no way to reconcile conflicting payment gateway settings in an update hook without intervention. That could be done in a new major release?
For 1.x, another option would be to remove the library dependency and document it with a comment. Then, we add something like this in checkout.js:
Comment #5
jsacksick commentedJust as a side note:
cybersource_commerce/checkoutshould becommerce_cybersource/checkoutbut ofc that doesn't solve the problem reported here.One thing I don't really get: why would you need to manually attach the library to the form yourself? And if so, what would be the problem of adding the flex library in addition?
I removed the faulty dependency:
- commerce_cybersource/flex-microformComment #6
deviantintegral commentedThis was in inherited code that I wasn't involved in, and I don't have information as to why it was done this way. Since filing this issue, we ended up deciding to do a major refactor, simplification, and upstreaming of code leading to #3221909: Add support for creating stored payment methods via the Flex Microform, #3548932: Show error messages when card validation fails, and #3549621: Support ACH / Check payments. Hopefully no one else goes down that path in the future!
Comment #7
jsacksick commentedCan we close this then?
Comment #8
deviantintegral commentedYes, lets, and thank you!