From 05c32c86d5a4dbdb0b00db0156ded979190b9a3c Mon Sep 17 00:00:00 2001
Message-Id: <05c32c86d5a4dbdb0b00db0156ded979190b9a3c.1337852751.git.magicmyth@magicmyth.com>
From: Adam Lyall <magicmyth@magicmyth.com>
Date: Thu, 24 May 2012 10:45:33 +0100
Subject: [PATCH] DRAFT: Issue #1569386

Non-local payment method selection should now work again. However, error
notices are still appearing regarding: undefined index payment_details.
---
 commerce_worldpay_bg.module |   28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/commerce_worldpay_bg.module b/commerce_worldpay_bg.module
index 00863d8..9efd32b 100644
--- a/commerce_worldpay_bg.module
+++ b/commerce_worldpay_bg.module
@@ -500,20 +500,22 @@ function commerce_worldpay_bg_submit_form($payment_method, $pane_values, $checko
  *
  */
 function commerce_worldpay_bg_submit_form_validate($payment_method, $pane_form, $pane_values, $order, $form_parents = array()) {
-  // Make sure "Please select" is not selected
-  if ($pane_values['paymentType'] == 'not_selected') {
-    form_set_error(implode('][', array_merge($form_parents, array('paymentType'))), t('You must select a payment method.'));
-
-    return FALSE;
-  }
-  // Check if it is a value we allow
-  if (!array_key_exists($pane_values['paymentType'], _commerce_worldpay_bg_payment_card_types())) {
-    form_set_error(implode('][', array_merge($form_parents, array('paymentType'))), t('An invalid WorldPay payment method choice was recived. Please try choosing a payment method again.'));
+  if ($payment_method['settings']['payment_parameters']['pm_select_localy']) {
+    // Make sure "Please select" is not selected
+    if ($pane_values['paymentType'] == 'not_selected') {
+      form_set_error(implode('][', array_merge($form_parents, array('paymentType'))), t('You must select a payment method.'));
 
-    // Even though the form error is enough to stop the submission of the form,
-    // it's not enough to stop it from a Commerce standpoint because of the
-    // combined validation / submission going on per-pane in the checkout form.
-    return FALSE;
+      return FALSE;
+    }
+    // Check if it is a value we allow
+    if (!array_key_exists($pane_values['paymentType'], _commerce_worldpay_bg_payment_card_types())) {
+      form_set_error(implode('][', array_merge($form_parents, array('paymentType'))), t('An invalid WorldPay payment method choice was recived. Please try choosing a payment method again.'));
+
+      // Even though the form error is enough to stop the submission of the form,
+      // it's not enough to stop it from a Commerce standpoint because of the
+      // combined validation / submission going on per-pane in the checkout form.
+      return FALSE;
+    }
   }
 }
 
-- 
1.7.9.5

