CRM-15509 remove hard-coded billing & card blocks in the tpl in favour of assigned...
authorEileen McNaughton <eileen@fuzion.co.nz>
Mon, 27 Oct 2014 21:02:49 +0000 (10:02 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 27 Oct 2014 21:02:49 +0000 (10:02 +1300)
(note that a next step will be to allow processors to interact with the defined fields

CRM/Core/Payment/Form.php
CRM/Core/Payment/ProcessorForm.php
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Core/BillingBlock.tpl
templates/CRM/Event/Form/Registration/Register.tpl

index af794418857ee8f414bca74cee6c059bccfc4a72..dacf7c583fa0599a045eb08013c65b51767ed59e 100644 (file)
@@ -132,6 +132,18 @@ class CRM_Core_Payment_Form {
       CRM_Core_PseudoConstant::country(),
       'is_required' => TRUE,
     );
+    //CRM-15509 working towards giving control over billing fields to payment processors. For now removing tpl hard-coding
+    $smarty = CRM_Core_Smarty::singleton();
+    $smarty->assign('billingDetailsFields', array(
+      'billing_first_name',
+      'billing_middle_name',
+      'billing_last_name',
+      "billing_street_address-{$bltID}",
+      "billing_city-{$bltID}",
+      "billing_country_id-{$bltID}",
+      "billing_state_province_id-{$bltID}".
+      "billing_postal_code-{$bltID}",
+    ));
   }
 
   /**
@@ -190,10 +202,17 @@ class CRM_Core_Payment_Form {
     $smarty = CRM_Core_Smarty::singleton();
     $smarty->assign('paymentTypeName', 'credit_card');
     $smarty->assign('paymentTypeLabel', ts('Credit Card Information'));
+    $smarty->assign('paymentFields', array(
+      'credit_card_type',
+      'credit_card_number',
+      'cvv2',
+      'credit_card_exp_date',
+    ));
   }
 
   /**
    * @param CRM_Core_Form $form
+   * @param bool $useRequired
    */
   static function addCommonFields(&$form, $useRequired) {
     foreach ($form->_paymentFields as $name => $field) {
@@ -267,6 +286,12 @@ class CRM_Core_Payment_Form {
     // replace these payment type names with an option group - moving name & label assumptions out of the tpl is a step towards that
     $smarty->assign('paymentTypeName', 'direct_debit');
     $smarty->assign('paymentTypeLabel', ts('Direct Debit Information'));
+    $smarty->assign('paymentFields', array(
+      'account_holder',
+      'bank_account_number',
+      'bank_identification_number',
+      'bank_name',
+    ));
   }
 
   /**
index 5ac1f8c8a4b87ca05cef433359304e6793ee9344..b0591b30629d60903300ac797460fc90d05f925e 100644 (file)
@@ -134,10 +134,10 @@ class CRM_Core_Payment_ProcessorForm {
     }
 
     if (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT)) {
-      CRM_Core_Payment_Form::buildDirectDebit($form);
+      CRM_Core_Payment_Form::buildDirectDebit($form, TRUE);
     }
     elseif (($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD)) {
-      CRM_Core_Payment_Form::buildCreditCard($form);
+      CRM_Core_Payment_Form::buildCreditCard($form, TRUE);
     }
   }
 }
index 4a64c72409368facb2a4cd1b364391f75a87a54d..0c2d706647295aef062dc63e4991f73b21d598f4 100644 (file)
@@ -29,7 +29,7 @@
 
 {* Callback snippet: Load payment processor *}
 {elseif $snippet}
-{include file="CRM/Core/BillingBlock.tpl" context="front-end"}
+{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'}
        cj('input[name="soft_credit_type_id"]').on('change', function() {
                enableHonorType();
        });
-       
+
   function enableHonorType( ) {
-    var selectedValue = cj('input[name="soft_credit_type_id"]:checked'); 
+    var selectedValue = cj('input[name="soft_credit_type_id"]:checked');
     if ( selectedValue.val() > 0) {
       cj('#honorType').show();
     }
        });
 
   function showRecurHelp( ) {
-    var showHelp = cj('input[id="is_recur"]:checked'); 
+    var showHelp = cj('input[id="is_recur"]:checked');
     if ( showHelp.val() > 0) {
       cj('#recurHelp').show();
     }
       cj('#recurHelp').hide();
     }
   }
-       
+
   function pcpAnonymous( ) {
     // clear nickname field if anonymous is true
     if (document.getElementsByName("pcp_is_anonymous")[1].checked) {
     updatePriceSetHighlight();
 
     function toggleBillingBlockIfFree(){
-      var total_amount_tmp =  $(this).data('raw-total'); 
+      var total_amount_tmp =  $(this).data('raw-total');
       // Hide billing questions if this is free
       if (total_amount_tmp == 0){
         cj("#billing-payment-block").hide();
-        cj(".payment_options-group").hide();  
-      } 
+        cj(".payment_options-group").hide();
+      }
       else {
         cj("#billing-payment-block").show();
-        cj(".payment_options-group").show(); 
+        cj(".payment_options-group").show();
       }
     }
 
index eb40dd9ff354b2c023436eebb94a4ecf76f0bc0f..8d6b04d4d5124b67425e92bab7eaca246286e343 100644 (file)
  +--------------------------------------------------------------------+
 *}
 {crmRegion name="billing-block"}
-  {* Add 'required' marker to billing fields in this template for front-end / online contribution and event registration forms only. *}
-{if $context EQ 'front-end'}
-  {assign var=reqMark value=' <span class="crm-marker" title="This field is required.">*</span>'}
-{else}
-  {assign var=reqMark value=''}
-{/if}
 
-{if $form.credit_card_number or $form.bank_account_number}
+{if $paymentFields}
   <div id="payment_information">
     <fieldset class="billing_mode-group {$paymentTypeName}_info-group">
       <legend>
           </div>
         </div>
       {/if}
-
-      {if $paymentProcessor.billing_mode & 1}
-      <div class="crm-section billing_mode-section {if $paymentProcessor.payment_type & 2}direct_debit_info-section{else}credit_card_info-section{/if}">
-        {if $paymentProcessor.payment_type & 2}
-          <div class="crm-section {$form.account_holder.name}-section">
-            <div class="label">{$form.account_holder.label}</div>
-            <div class="content">{$form.account_holder.html}</div>
-            <div class="clear"></div>
-          </div>
-          <div class="crm-section {$form.bank_account_number.name}-section">
-            <div class="label">{$form.bank_account_number.label}</div>
-            <div class="content">{$form.bank_account_number.html}</div>
-            <div class="clear"></div>
-          </div>
-          <div class="crm-section {$form.bank_identification_number.name}-section">
-            <div class="label">{$form.bank_identification_number.label}</div>
-            <div class="content">{$form.bank_identification_number.html}</div>
-            <div class="clear"></div>
-          </div>
-          <div class="crm-section {$form.bank_name.name}-section">
-            <div class="label">{$form.bank_name.label}</div>
-            <div class="content">{$form.bank_name.html}</div>
-            <div class="clear"></div>
-          </div>
-        {else}
-          <div class="crm-section {$form.credit_card_type.name}-section">
-            <div class="label">{$form.credit_card_type.label} {$reqMark}</div>
-            <div class="content">
-              {$form.credit_card_type.html}
-              <div class="crm-credit_card_type-icons"></div>
-            </div>
-            <div class="clear"></div>
-          </div>
-          <div class="crm-section {$form.credit_card_number.name}-section">
-            <div class="label">{$form.credit_card_number.label} {$reqMark}</div>
-            <div class="content">{$form.credit_card_number.html|crmAddClass:creditcard}</div>
-            <div class="clear"></div>
-          </div>
-          <div class="crm-section {$form.cvv2.name}-section">
-            <div class="label">{$form.cvv2.label} {$reqMark}</div>
-            <div class="content">
-              {$form.cvv2.html}
-              <span class="cvv2-icon"
-                    title="{ts}Usually the last 3-4 digits in the signature area on the back of the card.{/ts}"> </span>
+      <div class="crm-section billing_mode-section {$paymentTypeName}_info-section">
+        {foreach from=$paymentFields item=paymentField}
+          <div class="crm-section {$form.$paymentField.name}-section">
+            <div class="label">{$form.$paymentField.label}</div>
+            <div class="content">{$form.$paymentField.html}
+              {if $paymentField == 'cvv2'}{* @todo move to form assignment*}
+                <span class="cvv2-icon" title="{ts}Usually the last 3-4 digits in the signature area on the back of the card.{/ts}"> </span>
+              {/if}
+              {if $paymentField == 'credit_card_type'}
+                <div class="crm-credit_card_type-icons"></div>
+              {/if}
             </div>
             <div class="clear"></div>
           </div>
-          <div class="crm-section {$form.credit_card_exp_date.name}-section">
-            <div class="label">{$form.credit_card_exp_date.label} {$reqMark}</div>
-            <div class="content">{$form.credit_card_exp_date.html}</div>
-            <div class="clear"></div>
-          </div>
-        {/if}
+        {/foreach}
       </div>
-    </fieldset>
-    {else}
-    </fieldset>
-    {/if}
     {/if}
-    {if $profileAddressFields}
-      <input type="checkbox" id="billingcheckbox" value="0">
-      <label for="billingcheckbox">{ts}My billing address is the same as above{/ts}</label>
-    {/if}
-    <fieldset class="billing_name_address-group">
-      <legend>{ts}Billing Name and Address{/ts}</legend>
-      <div class="crm-section billing_name_address-section">
-        <div class="crm-section {$form.billing_first_name.name}-section">
-          <div class="label">{$form.billing_first_name.label} {$reqMark}</div>
-          <div class="content">{$form.billing_first_name.html}</div>
-          <div class="clear"></div>
-        </div>
-        <div class="crm-section {$form.billing_middle_name.name}-section">
-          <div class="label">{$form.billing_middle_name.label}</div>
-          <div class="content">{$form.billing_middle_name.html}</div>
-          <div class="clear"></div>
-        </div>
-        <div class="crm-section {$form.billing_last_name.name}-section">
-          <div class="label">{$form.billing_last_name.label} {$reqMark}</div>
-          <div class="content">{$form.billing_last_name.html}</div>
-          <div class="clear"></div>
-        </div>
-        {assign var=n value=billing_street_address-$bltID}
-        <div class="crm-section {$form.$n.name}-section">
-          <div class="label">{$form.$n.label} {$reqMark}</div>
-          <div class="content">{$form.$n.html}</div>
-          <div class="clear"></div>
-        </div>
-        {assign var=n value=billing_city-$bltID}
-        <div class="crm-section {$form.$n.name}-section">
-          <div class="label">{$form.$n.label} {$reqMark}</div>
-          <div class="content">{$form.$n.html}</div>
-          <div class="clear"></div>
-        </div>
-        {assign var=n value=billing_country_id-$bltID}
-        <div class="crm-section {$form.$n.name}-section">
-          <div class="label">{$form.$n.label} {$reqMark}</div>
-          <div class="content">{$form.$n.html|crmAddClass:big}</div>
-          <div class="clear"></div>
-        </div>
-        {assign var=n value=billing_state_province_id-$bltID}
-        <div class="crm-section {$form.$n.name}-section">
-          <div class="label">{$form.$n.label} {$reqMark}</div>
-          <div class="content">{$form.$n.html|crmAddClass:big}</div>
-          <div class="clear"></div>
-        </div>
-        {assign var=n value=billing_postal_code-$bltID}
-        <div class="crm-section {$form.$n.name}-section">
-          <div class="label">{$form.$n.label} {$reqMark}</div>
-          <div class="content">{$form.$n.html}</div>
-          <div class="clear"></div>
+    {if $billingDetailsFields}
+      {if $profileAddressFields}
+        <input type="checkbox" id="billingcheckbox" value="0">
+        <label for="billingcheckbox">{ts}My billing address is the same as above{/ts}</label>
+      {/if}
+      <fieldset class="billing_name_address-group">
+        <legend>{ts}Billing Name and Address{/ts}</legend>
+        <div class="crm-section billing_name_address-section">
+          {foreach from=$billingDetailsFields item=billingField}
+            <div class="crm-section {$form.$billingField.name}-section">
+              <div class="label">{$form.$billingField.label}</div>
+              {if $form.$billingField.type == 'text'}
+                <div class="content">{$form.$billingField.html}</div>
+              {else}
+                <div class="content">{$form.$billingField.html|crmAddClass:big}</div>
+              {/if}
+              <div class="clear"></div>
+            </div>
+          {/foreach}
         </div>
-      </div>
-    </fieldset>
-
+      </fieldset>
+    {/if}
   </div>
 {if $profileAddressFields}
   <script type="text/javascript">
index d189c81aeb97635c6c5a814842d48a1d67ca50e4..b5ae1e2b303edae1b3080f7ab1d28dc382a17294 100644 (file)
@@ -25,7 +25,7 @@
 *}
 {* Callback snippet: Load payment processor *}
 {if $snippet}
-  {include file="CRM/Core/BillingBlock.tpl" context="front-end"}
+  {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'}