From 8ae4d0d3d222e35ccbedace99edf1c8390116686 Mon Sep 17 00:00:00 2001 From: dpradeep Date: Wed, 6 Aug 2014 22:25:36 +0530 Subject: [PATCH 1/1] VAT-645 Display billing address fields on pay later option. --- CRM/Contribute/Form/Contribution/Confirm.php | 2 +- CRM/Contribute/Form/Contribution/Main.php | 4 +-- CRM/Contribute/Form/ContributionBase.php | 8 +++++ CRM/Core/Payment/Form.php | 34 +++++++++++++++++++ CRM/Core/Payment/ProcessorForm.php | 6 ++++ CRM/Event/Form/Registration.php | 8 +++++ CRM/Event/Form/Registration/Confirm.php | 6 +++- CRM/Event/Form/Registration/Register.php | 5 +-- .../Contribute/Form/Contribution/Confirm.tpl | 4 +-- .../CRM/Contribute/Form/Contribution/Main.tpl | 2 +- .../Contribute/Form/Contribution/ThankYou.tpl | 4 +-- templates/CRM/Core/BillingBlock.tpl | 11 +++--- .../CRM/Event/Form/Registration/Confirm.tpl | 2 +- .../CRM/Event/Form/Registration/Register.tpl | 2 +- .../CRM/Event/Form/Registration/ThankYou.tpl | 3 +- templates/CRM/common/paymentBlock.tpl | 12 ++++--- 16 files changed, 88 insertions(+), 25 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 7c04eb6b49..694aadd9f0 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -651,7 +651,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr //unset the billing parameters if it is pay later mode //to avoid creation of billing location - if ($params['is_pay_later']) { + if ($params['is_pay_later'] && !$this->_isBillingAddressRequiredForPayLater) { $billingFields = array( 'billing_first_name', 'billing_middle_name', diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index b2bf095d5d..3dc88db15e 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -385,7 +385,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } // Build payment processor form - if ($this->_ppType && empty($_GET['onbehalf'])) { + if (($this->_ppType || $this->_isBillingAddressRequiredForPayLater) && empty($_GET['onbehalf'])) { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); // Return if we are in an ajax callback if ($this->_snippet) { @@ -1006,7 +1006,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) { + if (CRM_Utils_Array::value('payment_processor', $fields) == 0 && $self->_isBillingAddressRequiredForPayLater == 0) { return empty($errors) ? TRUE : $errors; } diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index ef6fcae79a..d209eabff5 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -206,6 +206,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { * @var boolean */ public $_useForMember; + + public $_isBillingAddressRequiredForPayLater; /** * Function to set variables up before form is built * @@ -521,6 +523,12 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { if (CRM_Utils_Request::retrieve('cancel', 'Boolean', CRM_Core_DAO::$_nullObject)) { self::cancelRecurring(); } + + // check if billing block is required for pay later + if (CRM_Utils_Array::value('is_pay_later', $this->_values)) { + $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values); + $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater); + } } /** diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 73b4b8b41b..e54150e77d 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -357,6 +357,40 @@ class CRM_Core_Payment_Form { } } + /** + * Function to add address block + * + * @param $form + * @param bool $useRequired + * + * @return void + * @access public + */ + static function buildAddressBlock(&$form, $useRequired = FALSE) { + CRM_Core_Payment_Form::_setPaymentFields($form); + foreach ($form->_paymentFields as $name => $field) { + if (isset($field['cc_field']) && + $field['cc_field'] + ) { + $form->add($field['htmlType'], + $field['name'], + $field['title'], + $field['attributes'], + $useRequired ? $field['is_required'] : FALSE + ); + } + } + + // also take care of state country widget + $stateCountryMap = array( + 1 => array( + 'country' => "billing_country_id-{$form->_bltID}", + 'state_province' => "billing_state_province_id-{$form->_bltID}", + ) + ); + CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); + } + /** * Make sure that credit card number and cvv are valid * Called within the scope of a QF formRule function diff --git a/CRM/Core/Payment/ProcessorForm.php b/CRM/Core/Payment/ProcessorForm.php index 3fa23d7e1c..2975e1959d 100644 --- a/CRM/Core/Payment/ProcessorForm.php +++ b/CRM/Core/Payment/ProcessorForm.php @@ -108,6 +108,12 @@ class CRM_Core_Payment_ProcessorForm { $form->assign('profileAddressFields', $profileAddressFields); } + // check if show billing setting is enabled + if ($form->getVar( '_ppType' ) == 0 && $form->_isBillingAddressRequiredForPayLater) { + CRM_Core_Payment_Form::buildAddressBlock($form); + return; + } + // before we do this lets see if the payment processor has implemented a buildForm method if (method_exists($form->_paymentProcessor['instance'], 'buildForm') && is_callable(array($form->_paymentProcessor['instance'], 'buildForm'))) { diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 1072a9efec..e2493088b6 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -187,6 +187,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { public $_forcePayement; + public $_isBillingAddressRequiredForPayLater; + /** * Function to set variables up before form is built * @@ -466,6 +468,12 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) { $this->_values['event']['campaign_id'] = $campID; } + + // check if billing block is required for pay later + if (CRM_Utils_Array::value('is_pay_later', $this->_values['event'])) { + $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values['event']); + $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater); + } } /** diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 92b0175ce3..ba9aace19d 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -468,7 +468,11 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this); //unset the billing parameters if it is pay later mode //to avoid creation of billing location - if ($this->_allowWaitlist || $this->_requireApproval || !empty($value['is_pay_later']) || empty($value['is_primary'])) { + if ($this->_allowWaitlist + || $this->_requireApproval + || (!empty($value['is_pay_later']) && !$this->_isBillingAddressRequiredForPayLater) + || empty($value['is_primary']) + ) { $billingFields = array( "email-{$this->_bltID}", 'billing_first_name', diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 97355050cc..1661b0af05 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -333,7 +333,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } // Build payment processor form - if ($this->_ppType) { + if ($this->_ppType || $this->_isBillingAddressRequiredForPayLater) { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); // Return if we are in an ajax callback if ($this->_snippet) { @@ -971,7 +971,8 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { //set as Primary participant $params['is_primary'] = 1; - if ($this->_values['event']['is_pay_later'] && !array_key_exists('hidden_processor', $params)) { + if ($this->_values['event']['is_pay_later'] + && (!array_key_exists('hidden_processor', $params) || $params['payment_processor'] == 0)) { $params['is_pay_later'] = 1; } else { diff --git a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl index 435fcc0ac6..aafeb18090 100644 --- a/templates/CRM/Contribute/Form/Contribution/Confirm.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Confirm.tpl @@ -182,8 +182,8 @@ {/if} - {if ( $contributeMode ne 'notify' and ! $is_pay_later and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) ) or $email } - {if $contributeMode ne 'notify' and ! $is_pay_later and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) } + {if ( $contributeMode ne 'notify' and (!$is_pay_later or $isBillingAddressRequiredForPayLater) and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) ) or $email } + {if $contributeMode ne 'notify' and (!$is_pay_later or $isBillingAddressRequiredForPayLater) and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) } {if $billingName or $address}
diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index dfd3d19099..ea79486c8e 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -279,7 +279,7 @@
{* If we have a payment processor, load it - otherwise it happens via ajax *} - {if $ppType} + {if $ppType or $isBillingAddressRequiredForPayLater} {include file="CRM/Contribute/Form/Contribution/Main.tpl" snippet=4} {/if}
diff --git a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl index fa39cf4f9b..d07a32b056 100644 --- a/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl +++ b/templates/CRM/Contribute/Form/Contribution/ThankYou.tpl @@ -233,8 +233,8 @@
{/if} - {if ( $contributeMode ne 'notify' and ! $is_pay_later and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) ) or $email } - {if $contributeMode ne 'notify' and ! $is_pay_later and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) } + {if ( $contributeMode ne 'notify' and (!$is_pay_later or $isBillingAddressRequiredForPayLater) and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) ) or $email } + {if $contributeMode ne 'notify' and (!$is_pay_later or $isBillingAddressRequiredForPayLater) and $is_monetary and ( $amount GT 0 OR $minimum_fee GT 0 ) } {if $billingName or $address}
diff --git a/templates/CRM/Core/BillingBlock.tpl b/templates/CRM/Core/BillingBlock.tpl index 85a4efe456..4fcd5d9069 100644 --- a/templates/CRM/Core/BillingBlock.tpl +++ b/templates/CRM/Core/BillingBlock.tpl @@ -108,7 +108,10 @@ {/if}
- + {else} + + {/if} +{/if} {if $profileAddressFields} {/if} @@ -162,9 +165,7 @@
- {else} - - {/if} + {if $profileAddressFields} @@ -292,5 +293,5 @@ CRM.$(function($) { {/literal} {/if} -{/if} + {/crmRegion} diff --git a/templates/CRM/Event/Form/Registration/Confirm.tpl b/templates/CRM/Event/Form/Registration/Confirm.tpl index 435a508d7b..8b3a8ebcaa 100644 --- a/templates/CRM/Event/Form/Registration/Confirm.tpl +++ b/templates/CRM/Event/Form/Registration/Confirm.tpl @@ -155,7 +155,7 @@ {include file="CRM/Event/Form/Registration/DisplayProfile.tpl"} - {if $contributeMode ne 'notify' and !$is_pay_later and $paidEvent and !$isAmountzero and !$isOnWaitlist and !$isRequireApproval} + {if $contributeMode ne 'notify' and (!$is_pay_later or $isBillingAddressRequiredForPayLater) and $paidEvent and !$isAmountzero and !$isOnWaitlist and !$isRequireApproval}
{ts}Billing Name and Address{/ts} diff --git a/templates/CRM/Event/Form/Registration/Register.tpl b/templates/CRM/Event/Form/Registration/Register.tpl index fffb3fb22f..33c00cfe65 100644 --- a/templates/CRM/Event/Form/Registration/Register.tpl +++ b/templates/CRM/Event/Form/Registration/Register.tpl @@ -154,7 +154,7 @@
{* If we have a payment processor, load it - otherwise it happens via ajax *} - {if $ppType} + {if $ppType or $isBillingAddressRequiredForPayLater} {include file="CRM/Event/Form/Registration/Register.tpl" snippet=4} {/if}
diff --git a/templates/CRM/Event/Form/Registration/ThankYou.tpl b/templates/CRM/Event/Form/Registration/ThankYou.tpl index e55d507ac6..7d10854e06 100644 --- a/templates/CRM/Event/Form/Registration/ThankYou.tpl +++ b/templates/CRM/Event/Form/Registration/ThankYou.tpl @@ -172,8 +172,7 @@ {/if} {include file="CRM/Event/Form/Registration/DisplayProfile.tpl"} - - {if $contributeMode ne 'notify' and $paidEvent and ! $is_pay_later and ! $isAmountzero and !$isOnWaitlist and !$isRequireApproval} + {if $contributeMode ne 'notify' and (!$is_pay_later or $isBillingAddressRequiredForPayLater) and $paidEvent and !$isAmountzero and !$isOnWaitlist and !$isRequireApproval}
{ts}Billing Name and Address{/ts} diff --git a/templates/CRM/common/paymentBlock.tpl b/templates/CRM/common/paymentBlock.tpl index 8cb3c8a32b..f3ad083fa8 100644 --- a/templates/CRM/common/paymentBlock.tpl +++ b/templates/CRM/common/paymentBlock.tpl @@ -27,12 +27,14 @@