Payment module uses commerce_payment_method_load() function to load payment_method into checkout payment pane. I believe we should replace it with commerce_payment_method_instance_load so CALLBACK_commerce_payment_method_submit_form() for each payment would have access to instance_id.

CommentFileSizeAuthor
#2 2614026.patch1.04 KBzaporylie
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zaporylie created an issue. See original summary.

zaporylie’s picture

Status: Needs work » Needs review
FileSize
1.04 KB
torgosPizza’s picture

Issue tags: +commerce-sprint

This actually seems quite reasonable to me. Perhaps we can get some other eyes on it, but I think this might solve some of the weird edge cases we've seen where an order needing payment somehow skips it. (Could be wrong.)

mglaman’s picture

+++ b/modules/payment/includes/commerce_payment.checkout_pane.inc
@@ -140,9 +140,7 @@ function commerce_payment_pane_checkout_form($form, &$form_state, $checkout_pane
-    $method_info = $order->payment_methods[$pane_form['payment_method']['#default_value']];
-    $payment_method = commerce_payment_method_load($method_info['method_id']);
-    $payment_method['settings'] = $method_info['settings'];
+    $payment_method = commerce_payment_method_instance_load($pane_form['payment_method']['#default_value']);

So basically instead of retrieving the payment method from the order's data attribute and rebuilding settings, you're loading it fresh. Correct?

This would need testing alongside other payment gateway contributed projects. I'm not sure if there's an easy way, but I'd want to check out these modules http://contrib.drupalcommerce.org/payment-modules and see how they are checking this data attribute.

For example, Commerce PayPal EC uses it to see if it's enabled for the order (and not affected.)

return in_array('paypal_ec|commerce_payment_paypal_ec', array_keys($order->payment_methods));

Would need rszrama to brain dump anything on this :)

torgosPizza’s picture

Ah, yes. On second thought you might be right. There are other instances in the form validate and submit funcs where it checks order data, so I do think it might be more important to use that from the beginning.

@zaporylie : Do you have a use case you can describe that brought you to create this patch? As @mglaman pointed out, we'd need some test coverage to ensure this works. I might suggest (correct me if I'm wrong) creating two payment methods and then using a condition only make one of them available to the order. If for some reason both methods are still available then I think we'll know this patch needs work. (At least, this makes sense in my head.)

zaporylie’s picture

That's actually the reason why I need payment checkout pane to be improved - situation with two instances of the same payment method. My case is that one of the payment gateways I'm recently working with, forces me to create commerce_payment_transaction when payment method is selected from the list of all available payment methods (even before submitting form/going to next step). It has to be like that to show snippet retrieved from their API and store remote_id for transaction. Instance_id is one of the payment transaction properties.

Generally when you load page with payment pane on it for the first time you don't have access to instance id of selected payment method, but when you change payment method back and forth - it's stored in pane values. That also might be the way how this issue could be solved - store default, pre-selected payment method instance into pane_values.

Hope I explained everything clearly, but if you want me to give some more details, just let me know.

mglaman’s picture

zaporylie, would a use case be: a shop in the United States which supports a lot of sales in Canada. You have two Authorize.net accounts, one for each country. If an order is for a Canadian customer you need to use that gateway.

The current implementation makes discerning the above difficult, correct? In knowing which gateway is currently being used?

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Just used this to debug issue mentioned in #7. This lets me identify the instance ID so I can tell if the Authorize.net USD or CAD method was used.

torgosPizza’s picture

Nice! Should we write a test for that?

rszrama’s picture

Category: Bug report » Feature request
Status: Reviewed & tested by the community » Needs review

Can we get a look at how the variable differs pre / post patch? Also, are there any points of alteration for one that wouldn't apply to the other that could cause unexpected behavior?

I'm not sure this change is required to address the OP's issue (for example, you can derive the currently selected payment method even on the initial page load just by looking at the radios element's options array / default value), so if anything is substantively different, it would probably be better to avoid the change.

smccabe’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed the 2 variables and the only difference with the new implementation is that the instance_id is provided, everything else is literally identical.

I think this does help OP's issue as they are referring to 2 payment gateways that are the same and may otherwise have the same options.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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