From 92ec1d7fd0fb2a78fe4415787a40a3dc62de1004 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 28 Oct 2014 10:02:49 +1300 Subject: [PATCH] CRM-15509 remove hard-coded billing & card blocks in the tpl in favour of assigned fields (note that a next step will be to allow processors to interact with the defined fields --- CRM/Core/Payment/Form.php | 25 +++ CRM/Core/Payment/ProcessorForm.php | 4 +- .../CRM/Contribute/Form/Contribution/Main.tpl | 18 +-- templates/CRM/Core/BillingBlock.tpl | 149 ++++-------------- .../CRM/Event/Form/Registration/Register.tpl | 2 +- 5 files changed, 71 insertions(+), 127 deletions(-) diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index af79441885..dacf7c583f 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -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', + )); } /** diff --git a/CRM/Core/Payment/ProcessorForm.php b/CRM/Core/Payment/ProcessorForm.php index 5ac1f8c8a4..b0591b3062 100644 --- a/CRM/Core/Payment/ProcessorForm.php +++ b/CRM/Core/Payment/ProcessorForm.php @@ -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); } } } diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 4a64c72409..0c2d706647 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -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'} @@ -356,9 +356,9 @@ 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(); } @@ -372,7 +372,7 @@ }); 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(); } @@ -380,7 +380,7 @@ cj('#recurHelp').hide(); } } - + function pcpAnonymous( ) { // clear nickname field if anonymous is true if (document.getElementsByName("pcp_is_anonymous")[1].checked) { @@ -460,15 +460,15 @@ 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(); } } diff --git a/templates/CRM/Core/BillingBlock.tpl b/templates/CRM/Core/BillingBlock.tpl index eb40dd9ff3..8d6b04d4d5 100644 --- a/templates/CRM/Core/BillingBlock.tpl +++ b/templates/CRM/Core/BillingBlock.tpl @@ -24,14 +24,8 @@ +--------------------------------------------------------------------+ *} {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=' *'} -{else} - {assign var=reqMark value=''} -{/if} -{if $form.credit_card_number or $form.bank_account_number} +{if $paymentFields}
@@ -52,120 +46,45 @@
{/if} - - {if $paymentProcessor.billing_mode & 1} -
- {if $paymentProcessor.payment_type & 2} -
-
{$form.account_holder.label}
-
{$form.account_holder.html}
-
-
- -
-
{$form.bank_identification_number.label}
-
{$form.bank_identification_number.html}
-
-
-
-
{$form.bank_name.label}
-
{$form.bank_name.html}
-
-
- {else} -
-
{$form.credit_card_type.label} {$reqMark}
-
- {$form.credit_card_type.html} -
-
-
-
-
-
{$form.credit_card_number.label} {$reqMark}
-
{$form.credit_card_number.html|crmAddClass:creditcard}
-
-
-
-
{$form.cvv2.label} {$reqMark}
-
- {$form.cvv2.html} - +
+ {foreach from=$paymentFields item=paymentField} +
+
{$form.$paymentField.label}
+
{$form.$paymentField.html} + {if $paymentField == 'cvv2'}{* @todo move to form assignment*} + + {/if} + {if $paymentField == 'credit_card_type'} +
+ {/if}
-
-
{$form.credit_card_exp_date.label} {$reqMark}
-
{$form.credit_card_exp_date.html}
-
-
- {/if} + {/foreach}
- - {else} - - {/if} {/if} - {if $profileAddressFields} - - - {/if} -
- {ts}Billing Name and Address{/ts} -
-
-
{$form.billing_first_name.label} {$reqMark}
-
{$form.billing_first_name.html}
-
-
-
-
{$form.billing_middle_name.label}
-
{$form.billing_middle_name.html}
-
-
-
-
{$form.billing_last_name.label} {$reqMark}
-
{$form.billing_last_name.html}
-
-
- {assign var=n value=billing_street_address-$bltID} -
-
{$form.$n.label} {$reqMark}
-
{$form.$n.html}
-
-
- {assign var=n value=billing_city-$bltID} -
-
{$form.$n.label} {$reqMark}
-
{$form.$n.html}
-
-
- {assign var=n value=billing_country_id-$bltID} -
-
{$form.$n.label} {$reqMark}
-
{$form.$n.html|crmAddClass:big}
-
-
- {assign var=n value=billing_state_province_id-$bltID} -
-
{$form.$n.label} {$reqMark}
-
{$form.$n.html|crmAddClass:big}
-
-
- {assign var=n value=billing_postal_code-$bltID} -
-
{$form.$n.label} {$reqMark}
-
{$form.$n.html}
-
+ {if $billingDetailsFields} + {if $profileAddressFields} + + + {/if} +
+ {ts}Billing Name and Address{/ts} +
+ {foreach from=$billingDetailsFields item=billingField} +
+
{$form.$billingField.label}
+ {if $form.$billingField.type == 'text'} +
{$form.$billingField.html}
+ {else} +
{$form.$billingField.html|crmAddClass:big}
+ {/if} +
+
+ {/foreach}
-
-
- + + {/if}
{if $profileAddressFields}