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

deviantintegral created an issue. See original summary.

deviantintegral’s picture

Issue summary: View changes
deviantintegral’s picture

Assigned: deviantintegral » Unassigned

I 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:

if (typeof Flex === 'undefined') {
  console.error('Flex.js is not loaded. You must attach it manually as it cannot be included as a Drupal Library dependency.');
  return;
}

  • jsacksick committed dc1bf023 on 8.x-1.x
    Issue #3544867 by deviantintegral, jsacksick: Remove the non existing...
jsacksick’s picture

Just as a side note: cybersource_commerce/checkout should be commerce_cybersource/checkout but 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-microform

deviantintegral’s picture

One thing I don't really get: why would you need to manually attach the library to the form yourself?

This 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!

jsacksick’s picture

Can we close this then?

deviantintegral’s picture

Status: Active » Fixed

Yes, lets, and thank you!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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