diff --git a/includes/wf_crm_webform_base.inc b/includes/wf_crm_webform_base.inc index 926edf4..3ae6ed6 100644 --- a/includes/wf_crm_webform_base.inc +++ b/includes/wf_crm_webform_base.inc @@ -24,6 +24,8 @@ abstract class wf_crm_webform_base { // tax integration private $_tax_rate; + private $_civicrm_version; + /** * Magic method to retrieve otherwise inaccessible properties * @param $name @@ -58,6 +60,13 @@ abstract class wf_crm_webform_base { } return; + case 'civicrm_version': + if (!$this->_civicrm_version) { + $civicrm = system_get_info('module', 'civicrm'); + $this->_civicrm_version = $civicrm['version']; + } + return $this->_civicrm_version; + default: throw new Exception('Unknown property'); } diff --git a/includes/wf_crm_webform_postprocess.inc b/includes/wf_crm_webform_postprocess.inc index 83693a8..67041aa 100644 --- a/includes/wf_crm_webform_postprocess.inc +++ b/includes/wf_crm_webform_postprocess.inc @@ -1775,6 +1775,32 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base { } } + // Fix bug for testing. + if ($params['is_test'] == 1) { + $liveProcessorName = wf_civicrm_api('payment_processor', 'getvalue', array( + 'id' => $params['payment_processor_id'], + 'return' => 'name', + )); + // Lookup current domain for multisite support + static $domain = 0; + if (!$domain) { + $domain = wf_civicrm_api('domain', 'get', array('current_domain' => 1, 'return' => 'id')); + $domain = wf_crm_aval($domain, 'id', 1); + } + $params['payment_processor_id'] = wf_civicrm_api('payment_processor', 'getvalue', array( + 'return' => 'id', + 'name' => $liveProcessorName, + 'is_test' => 1, + 'domain_id' => $domain, + )); + } + + // doPayment requries payment_processor and payment_processor_mode fields. + if ($this->civicrm_version >= '4.7') { + $params['payment_processor'] = $params['payment_processor_id']; + + } + // Save this stuff for later unset($params['soft'], $params['honor_contact_id'], $params['honor_type_id']); return $params; diff --git a/includes/wf_crm_webform_preprocess.inc b/includes/wf_crm_webform_preprocess.inc index abddcf4..53cb20f 100644 --- a/includes/wf_crm_webform_preprocess.inc +++ b/includes/wf_crm_webform_preprocess.inc @@ -183,12 +183,21 @@ class wf_crm_webform_preprocess extends wf_crm_webform_base { 'scope' => 'footer', ); $page_id = $this->data['contribution'][1]['contribution'][1]['contribution_page_id']; - $contributionCallbackQuery = array('reset' => 1, 'id' => $page_id, 'qfKey' => $this->getQfKey(), 'snippet' => 4); + if ($this->civicrm_version >= '4.7') { + $currency = '$'; // FIXME + $contributionCallbackQuery = array('currency' => $currency, 'snippet' => 4); + $contributionCallbackUrl = 'civicrm/payment/form'; + $js_vars['processor_id_key'] = 'processor_id'; + } else { + $contributionCallbackQuery = array('currency' => '$', 'reset' => 1, 'id' => $page_id, 'qfKey' => $this->getQfKey(), 'snippet' => 4); + $contributionCallbackUrl = 'civicrm/contribute/transact'; + $js_vars['processor_id_key'] = 'type'; + } if (!empty($this->data['contribution'][1]['contribution'][1]['is_test'])) { // RM: This is needed in order for CiviCRM to know that this is a 'test' (i.e. 'preview' action in CiviCRM) transaction - otherwise, CiviCRM defaults to 'live' and returns the payment form with public key for the live payment processor! $contributionCallbackQuery['action'] = CRM_Core_Action::description(CRM_Core_Action::PREVIEW); } - $js_vars['contributionCallback'] = url('civicrm/contribute/transact', array('query' => $contributionCallbackQuery, 'alias' => TRUE)); + $js_vars['contributionCallback'] = url($contributionCallbackUrl, array('query' => $contributionCallbackQuery, 'alias' => TRUE)); // Add payment processor - note we have to search in 2 places because $this->loadMultipageData hasn't been run. Maybe it should be? $fid = 'civicrm_1_contribution_1_contribution_payment_processor_id'; if (!empty($this->enabled[$fid])) { diff --git a/js/webform_civicrm_payment.js b/js/webform_civicrm_payment.js index 886c1cf..33081b0 100644 --- a/js/webform_civicrm_payment.js +++ b/js/webform_civicrm_payment.js @@ -16,7 +16,7 @@ cj(function($) { function loadBillingBlock() { var type = getPaymentProcessor(); if (type && type != '0') { - $('#billing-payment-block').load(setting.contributionCallback + '&type=' + type, function() { + $('#billing-payment-block').load(setting.contributionCallback + '&' + setting.processor_id_key + '=' + type, function() { $('#billing-payment-block').trigger('crmLoad').trigger('crmFormLoad'); if (setting.billingSubmission) { $.each(setting.billingSubmission, function(key, val) {