CRM-16555 call extracted form snippet not overloaded form snippet.
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 27 May 2015 22:26:56 +0000 (10:26 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Thu, 28 May 2015 12:59:58 +0000 (00:59 +1200)
The payment form snippet has been extracted so it can be called from anywhere, use this & remove the over-loaded snippet
note the change of field name is to align front end & back-end but still an issue as back-end is select & front end is radio

CRM-16555 last may have been too agressive

CRM-16555 test fixes

x

CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Event/Form/Registration/Register.php
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Core/BillingBlockWrapper.tpl
templates/CRM/Event/Form/Registration/Register.tpl
templates/CRM/common/paymentBlock.tpl
tests/phpunit/api/v3/ContributionPageTest.php

index 2231fecd5b149be59ae2e7d43f840305046d019c..487ee06759743c3645a25c9944616a7c34065425 100644 (file)
@@ -767,6 +767,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     if ($this->_online) {
       $element->freeze();
     }
+
     $totalAmount = NULL;
     if (empty($this->_lineItems)) {
       $buildPriceSet = FALSE;
index a74688cc2ca23a7b12e5d0599151fac5dd497985..bab7659e916a03c3e24754dee7d67e0c64757aca 100644 (file)
@@ -730,7 +730,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
   public function postProcess() {
     $contactID = $this->getContactID();
     $isPayLater = $this->_params['is_pay_later'];
-    if (isset($this->_params['payment_processor']) && $this->_params['payment_processor'] == 0) {
+    if (isset($this->_params['payment_processor_id']) && $this->_params['payment_processor_id'] == 0) {
       $this->_params['is_pay_later'] = $isPayLater = TRUE;
     }
     // add a description field at the very beginning
@@ -2046,8 +2046,10 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     $form->_values['fee'] = $priceSetFields['fields'];
     $form->_priceSetId = $priceSetID;
     $form->setFormAmountFields($priceSetID);
-    if (!empty($params['payment_processor'])) {
-      $form->_paymentProcessor = civicrm_api3('payment_processor', 'getsingle', array('id' => $params['payment_processor']));
+    if (!empty($params['payment_processor_id'])) {
+      $form->_paymentProcessor = civicrm_api3('payment_processor', 'getsingle', array(
+        'id' => $params['payment_processor_id'],
+      ));
       if ($form->_paymentProcessor['billing_mode'] == 1) {
         $form->_contributeMode = 'direct';
       }
@@ -2056,7 +2058,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       }
     }
     else {
-      $form->_params['payment_processor'] = 0;
+      $form->_params['payment_processor_id'] = 0;
     }
     $priceFields = $priceFields[$priceSetID]['fields'];
     CRM_Price_BAO_PriceSet::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
@@ -2077,7 +2079,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
    */
   public static function getFormParams($id, array $params) {
     if (!isset($params['is_pay_later'])) {
-      if (!empty($params['payment_processor'])) {
+      if (!empty($params['payment_processor_id'])) {
         $params['is_pay_later'] = 0;
       }
       else {
index b5951826d3f03a71a891d2a3e304a174b9e25b0d..52dc3f6adc6b86a5f1d57831b5ea4f6855f2306b 100644 (file)
@@ -347,7 +347,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     if (!empty($this->_paymentProcessors)) {
       foreach ($this->_paymentProcessors as $pid => $value) {
         if (!empty($value['is_default'])) {
-          $this->_defaults['payment_processor'] = $pid;
+          $this->_defaults['payment_processor_id'] = $pid;
         }
       }
     }
@@ -375,7 +375,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     // Build payment processor form
     if (empty($_GET['onbehalf'])) {
       CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
-      // Return if we are in an ajax callback
+      // Return if we are in an ajax - this is probably redundant now as
+      // processor does not call this form for a snippet anymore - but unsure about
+      // cdType
       if ($this->_snippet) {
         return;
       }
@@ -420,14 +422,14 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
 
     if (count($pps) > 1) {
-      $this->addRadio('payment_processor', ts('Payment Method'), $pps,
+      $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
         NULL, "&nbsp;", TRUE
       );
     }
     elseif (!empty($pps)) {
       $key = array_keys($pps);
       $key = array_pop($key);
-      $this->addElement('hidden', 'payment_processor', $key);
+      $this->addElement('hidden', 'payment_processor_id', $key);
       if ($key === 0) {
         $this->assign('is_pay_later', $this->_values['is_pay_later']);
         $this->assign('pay_later_text', $this->_values['pay_later_text']);
@@ -961,7 +963,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
 
     if (!empty($fields['is_recur']) &&
-      CRM_Utils_Array::value('payment_processor', $fields) == 0
+      CRM_Utils_Array::value('payment_processor_id', $fields) == 0
     ) {
       $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
     }
@@ -1049,7 +1051,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
 
     // also return if paylater mode
-    if (CRM_Utils_Array::value('payment_processor', $fields) == 0 && $self->_isBillingAddressRequiredForPayLater == 0) {
+    if (CRM_Utils_Array::value('payment_processor_id', $fields) == 0 && $self->_isBillingAddressRequiredForPayLater == 0) {
       return empty($errors) ? TRUE : $errors;
     }
 
@@ -1063,7 +1065,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     if (!empty($self->_paymentFields)) {
       CRM_Core_Form::validateMandatoryFields($self->_paymentFields, $fields, $errors);
     }
-    CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor'], $fields, $errors, $self);
+    CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, $self);
 
     foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
       if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
@@ -1179,7 +1181,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     if (($this->_values['is_pay_later'] &&
         empty($this->_paymentProcessor) &&
         !array_key_exists('hidden_processor', $params)) ||
-      (!empty($params['payment_processor']) && $params['payment_processor'] == 0)
+      (!empty($params['payment_processor_id']) && $params['payment_processor_id'] == 0)
     ) {
       $params['is_pay_later'] = 1;
     }
@@ -1386,13 +1388,8 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     $form->_paymentProcessors = $noFees ? array() : $form->get('paymentProcessors');
     $form->_paymentProcessorID = NULL;
     if ($form->_paymentProcessors) {
-      // Fetch type during ajax request
-      if (isset($_GET['type']) && $form->_snippet) {
-        $form->_paymentProcessorID = CRM_Utils_Request::retrieve('type', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, 0);
-      }
-      // Remember type during form post
-      elseif (!empty($form->_submitValues)) {
-        $form->_paymentProcessorID = CRM_Utils_Array::value('payment_processor', $form->_submitValues);
+      if (!empty($form->_submitValues)) {
+        $form->_paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $form->_submitValues);
         $form->_paymentProcessor = CRM_Utils_Array::value($form->_paymentProcessorID, $form->_paymentProcessors);
         $form->set('type', $form->_paymentProcessorID);
         $form->set('mode', $form->_mode);
index 33fc16c1dea7465c13e9b260ddac3ebddc8a4bdb..b1533d351ed2177e8dc411632646b9cc006c9e21 100644 (file)
@@ -199,7 +199,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     if (!empty($this->_paymentProcessors)) {
       foreach ($this->_paymentProcessors as $pid => $value) {
         if (!empty($value['is_default'])) {
-          $this->_defaults['payment_processor'] = $pid;
+          $this->_defaults['payment_processor_id'] = $pid;
         }
       }
     }
@@ -442,14 +442,14 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
 
     if ($this->_values['event']['is_monetary']) {
       if (count($pps) > 1) {
-        $this->addRadio('payment_processor', ts('Payment Method'), $pps,
+        $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
           NULL, "&nbsp;"
         );
       }
       elseif (!empty($pps)) {
         $ppKeys = array_keys($pps);
         $currentPP = array_pop($ppKeys);
-        $this->addElement('hidden', 'payment_processor', $currentPP);
+        $this->addElement('hidden', 'payment_processor_id', $currentPP);
       }
     }
 
@@ -894,8 +894,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     }
 
     if ($self->_values['event']['is_monetary']) {
-      if (empty($self->_requireApproval) && !empty($fields['amount']) && $fields['amount'] > 0 && !isset($fields['payment_processor'])) {
-        $errors['payment_processor'] = ts('Please select a Payment Method');
+      if (empty($self->_requireApproval) && !empty($fields['amount']) && $fields['amount'] > 0 && !isset
+        ($fields['payment_processor_id'])) {
+        $errors['payment_processor_id'] = ts('Please select a Payment Method');
       }
       // return if this is express mode
       if ($self->_paymentProcessor &&
@@ -992,7 +993,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     $params['is_primary'] = 1;
 
     if ($this->_values['event']['is_pay_later']
-      && (!array_key_exists('hidden_processor', $params) || $params['payment_processor'] == 0)
+      && (!array_key_exists('hidden_processor', $params) || $params['payment_processor_id'] == 0)
     ) {
       $params['is_pay_later'] = 1;
     }
index e90b8354bceee762c37c8d71d284dd3bb119a6e8..57297875479f799377d6d342d438b7b59fa94491 100644 (file)
@@ -80,7 +80,7 @@
       <td>{$form.contact_id.html}</td>
     {/if}
     {if $contributionMode}
-    <tr class="crm-contribution-form-block-payment_processor_id"><td class="label nowrap">{$form.payment_processor_id.label}<span class="marker"> * </span></td><td>{$form.payment_processor_id.html}</td></tr>
+      <tr class="crm-contribution-form-block-payment_processor_id"><td class="label nowrap">{$form.payment_processor_id.label}<span class="marker"> * </span></td><td>{$form.payment_processor_id.html}</td></tr>
     {/if}
     <tr class="crm-contribution-form-block-contribution_type_id crm-contribution-form-block-financial_type_id">
       <td class="label">{$form.financial_type_id.label}</td><td{$valueStyle}>{$form.financial_type_id.html}&nbsp;
 
   </table>
 
+  <div id="billing-payment-block">
   <div class="accordion ui-accordion ui-widget ui-helper-reset">
     {* Billing Pane is the only billing pane currently *}
     {foreach from=$billingPanes key=paneName item=paneValue}
       </div>
     {/foreach}
   </div>
+  </div>
+  {include file="CRM/common/paymentBlock.tpl"}
 
     <!-- start of soft credit -->
     <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed {if $noSoftCredit}collapsed{/if}" id="softCredit">
index df84e8382ee2ec5f14e17f275be286589762b7d6..c86835de9ad690d994612a80cd435a3890b868e0 100644 (file)
 {if $snippet and !empty($isOnBehalfCallback)}
   {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl" context="front-end"}
 
-{* Callback snippet: Load payment processor *}
-{elseif $snippet}
-{include file="CRM/Core/BillingBlock.tpl"}
-  {if $is_monetary}
-  {* Put PayPal Express button after customPost block since it's the submit button in this case. *}
-    {if $paymentProcessor.payment_processor_type EQ 'PayPal_Express'}
-    <div id="paypalExpress">
-      {assign var=expressButtonName value='_qf_Main_upload_express'}
-      <fieldset class="crm-group paypal_checkout-group">
-        <legend>{ts}Checkout with PayPal{/ts}</legend>
-        <div class="section">
-          <div class="crm-section paypalButtonInfo-section">
-            <div class="content">
-              <span class="description">{ts}Click the PayPal button to continue.{/ts}</span>
-            </div>
-            <div class="clear"></div>
-          </div>
-          <div class="crm-section {$expressButtonName}-section">
-            <div class="content">
-              {$form.$expressButtonName.html} <span class="description">Checkout securely. Pay without sharing your financial information. </span>
-            </div>
-            <div class="clear"></div>
-          </div>
-        </div>
-      </fieldset>
-    </div>
-    {/if}
-  {/if}
-
-{* Main Form *}
 {else}
   {literal}
   <script type="text/javascript">
   </fieldset>
   {/if}
 
-  {if $form.payment_processor.label}
+  {if $form.payment_processor_id.label}
   {* PP selection only works with JS enabled, so we hide it initially *}
   <fieldset class="crm-group payment_options-group" style="display:none;">
     <legend>{ts}Payment Options{/ts}</legend>
     <div class="crm-section payment_processor-section">
-      <div class="label">{$form.payment_processor.label}</div>
-      <div class="content">{$form.payment_processor.html}</div>
+      <div class="label">{$form.payment_processor_id.label}</div>
+      <div class="content">{$form.payment_processor_id.html}</div>
       <div class="clear"></div>
     </div>
   </fieldset>
   <div id="billing-payment-block">
     {* If we have a payment processor, load it - otherwise it happens via ajax *}
     {if $paymentProcessorID or $isBillingAddressRequiredForPayLater}
-      {include file="CRM/Contribute/Form/Contribution/Main.tpl" snippet=4}
+      {include file="CRM/Financial/Form/Payment.tpl" snippet=4}
     {/if}
   </div>
   {include file="CRM/common/paymentBlock.tpl"}
       payment_information.show();
     }
   }
-  
+
   function skipPaymentMethod() {
     var flag = false;
     cj('.price-set-option-content input').each( function(){
index 274c62801d37cfad08bdd7ed7eaca1244572b725..3012b9e547438f753ea3ac837ad7f12f6570a716 100644 (file)
@@ -29,3 +29,4 @@ This allows the billing block to change when the card type changes *}
 <div id="billing-payment-block">
   {include file="CRM/Core/BillingBlock.tpl"}
 </div>
+{include file="CRM/common/paymentBlock.tpl"}
index 230a3eb8b12f9c8c5b8eb57d4dd494f8c4875d95..cb3049fcb4ee862cd417f4a937da3c3bdd55a793 100644 (file)
  +--------------------------------------------------------------------+
 *}
 {* Callback snippet: Load payment processor *}
-{if $snippet}
-  {include file="CRM/Core/BillingBlock.tpl"}
-  <div id="paypalExpress">
-    {* Put PayPal Express button after customPost block since it's the submit button in this case. *}
-    {if $paymentProcessor.payment_processor_type EQ 'PayPal_Express'}
-      {assign var=expressButtonName value='_qf_Register_upload_express'}
-      <fieldset class="crm-group payPalExpress-group">
-        <legend>{ts}Checkout with PayPal{/ts}</legend>
-        <div class="description">{ts}Click the PayPal button to continue.{/ts}</div>
-        <div>{$form.$expressButtonName.html} <span style="font-size:11px; font-family: Arial, Verdana;">Checkout securely.  Pay without sharing your financial information. </span>
-        </div>
-      </fieldset>
-    {/if}
-  </div>
-{else}
+
   {if $action & 1024}
     {include file="CRM/Event/Form/Registration/PreviewHeader.tpl"}
   {/if}
       </fieldset>
     {/if}
 
-    {if $form.payment_processor.label}
+    {if $form.payment_processor_id.label}
       <fieldset class="crm-group payment_options-group" style="display:none;">
         <legend>{ts}Payment Options{/ts}</legend>
         <div class="crm-section payment_processor-section">
-          <div class="label">{$form.payment_processor.label}</div>
-          <div class="content">{$form.payment_processor.html}</div>
+          <div class="label">{$form.payment_processor_id.label}</div>
+          <div class="content">{$form.payment_processor_id.html}</div>
           <div class="clear"></div>
         </div>
       </fieldset>
     {literal}
     function toggleConfirmButton() {
       var payPalExpressId = "{/literal}{$payPalExpressId}{literal}";
-      var elementObj = cj('input[name="payment_processor"]');
+      var elementObj = cj('input[name="payment_processor_id"]');
       if (elementObj.attr('type') == 'hidden') {
         var processorTypeId = elementObj.val();
       }
       }
     }
 
-    cj('input[name="payment_processor"]').change(function () {
+    cj('input[name="payment_processor_id"]').change(function () {
       toggleConfirmButton();
     });
 
         payment_processor.hide();
         payment_information.hide();
         // also unset selected payment methods
-        cj('input[name="payment_processor"]').removeProp('checked');
+        cj('input[name="payment_processor_id"]').removeProp('checked');
       }
       else {
         payment_options.show();
       }
     }
   }
-  {/literal}{/if}{literal}
+  {/literal}{literal}
 
 </script>
 {/literal}
index e3c883f319c0ab8cc87e420ad5455439031e56aa..4131f829a20c2cafafae99c329840bbfe1eaefbe 100644 (file)
@@ -36,7 +36,7 @@ function buildPaymentBlock(type) {
   }
   {/literal}{/if}{literal}
 
-  var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&type='}"{literal} + type;
+  var dataUrl = {/literal}"{crmURL p='civicrm/payment/form' h=0 q='snippet=4&processor_id='}"{literal} + type;
 
   {/literal}
     {if $urlPathVar}
@@ -47,9 +47,6 @@ function buildPaymentBlock(type) {
             dataUrl = dataUrl + '&id=' + '{$contributionPageID}'
         {/if}
 
-    {if $qfKey}
-      dataUrl = dataUrl + '&qfKey=' + '{$qfKey}'
-    {/if}
   {literal}
 
   var response = cj.ajax({
@@ -63,7 +60,7 @@ function buildPaymentBlock(type) {
 CRM.$(function($) {
     $('.crm-group.payment_options-group').show();
 
-    $('input[name="payment_processor"]').change( function() {
+    $('#payment_processor_id').change( function() {
         buildPaymentBlock( $(this).val() );
     });
 });
index 2051df4ee90503db4ffd2c803633dd82aefaa2e9..a2157cb7a4db22b300e4d00a5dd26768c66c1c95 100644 (file)
@@ -236,7 +236,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'billing_middle_name' => 'Goat',
       'billing_last_name' => 'Gruff',
       'selectMembership' => $this->_ids['membership_type'],
-      'payment_processor' => 1,
+      'payment_processor_id' => 1,
       'credit_card_number' => '4111111111111111',
       'credit_card_type' => 'Visa',
       'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
@@ -279,7 +279,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'billing_last_name' => 'Gruff',
       'email' => 'billy@goat.gruff',
       'selectMembership' => $this->_ids['membership_type'],
-      'payment_processor' => 1,
+      'payment_processor_id' => 1,
       'credit_card_number' => '4111111111111111',
       'credit_card_type' => 'Visa',
       'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
@@ -341,7 +341,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'billing_last_name' => 'Gruff',
       'email' => 'billy@goat.gruff',
       'selectMembership' => $this->_ids['membership_type'],
-      'payment_processor' => 1,
+      'payment_processor_id' => 1,
       'credit_card_number' => '4111111111111111',
       'credit_card_type' => 'Visa',
       'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),