Problem/Motivation

Right now for the lightbox mode a new "Pay with Datatrans" button is created on the payment pane instead of using the payment form's "Continue to next step" button. This way the validation callbacks of the original form do not run. Since in commerce_datatrans_submit_form() we do not have access to the whole form we can't even tweak the "Pay with Datatrans" button to run these callbacks.

A use case is coupon validations, i.e. commerce_coupon_commerce_checkout_form_review_validate(). This runs only if we click the "Continue to next step" button.

Proposed resolution

I'm not sure if it's possible to do but try to send the "give me that lightbox" request to datatrans in the CALLBACK_commerce_payment_method_redirect_form() callback (see commerce_payment.api.php).

Remaining tasks

Agree if this is the desired method to use.
Write the patch.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

czigor created an issue. See original summary.

czigor’s picture

@maintainers, should I work on this? Do you see this getting committed?

czigor’s picture

Issue summary: View changes
Berdir’s picture

I'm not sure if that can be solved.

Just changing the button wouldn't work I think, it's just a fake client-side button, we don't submit the form, so it won't run that anyway, even if me manage to apply that JS to the normal continue button?

The only fix I can think of right now is to put the payment method selection on a separate checkout page that doesn't do anything else?

czigor’s picture

I solved this from a custom module by overriding commerce_datatrans.js and doing an AJAX request to call the form validation functions I needed before calling Datatrans.startPayment(). I understand if this is out of the scope of this module but then no modules (like commerce_coupon) that rely on the review order form validation callbacks will work.

This is of course true for any payment module that does not submit the review form (e.g. commerce_stripe). Maybe commerce core should consider implementing this AJAX framework to let such payment methods be fully compatible with other commerce contrib modules.

czigor’s picture

Status: Active » Closed (won't fix)