VAT-645 Display billing address fields on pay later option.
authordpradeep <pradeep.dorugade@webaccess.co.in>
Wed, 6 Aug 2014 16:55:36 +0000 (22:25 +0530)
committerdpradeep <pradeep.dorugade@webaccess.co.in>
Wed, 6 Aug 2014 16:55:36 +0000 (22:25 +0530)
16 files changed:
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php
CRM/Core/Payment/Form.php
CRM/Core/Payment/ProcessorForm.php
CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/Confirm.php
CRM/Event/Form/Registration/Register.php
templates/CRM/Contribute/Form/Contribution/Confirm.tpl
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Contribute/Form/Contribution/ThankYou.tpl
templates/CRM/Core/BillingBlock.tpl
templates/CRM/Event/Form/Registration/Confirm.tpl
templates/CRM/Event/Form/Registration/Register.tpl
templates/CRM/Event/Form/Registration/ThankYou.tpl
templates/CRM/common/paymentBlock.tpl

index 7c04eb6b49276d1d19a6f8fe868d4e1e0ed7f15c..694aadd9f058fa2832fc2b751500a6a11e6a0689 100644 (file)
@@ -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',
index b2bf095d5db460d6a47fa459a10ce62bfcbd9584..3dc88db15efc44d9f1b26a458c2f25d7fb7909f9 100644 (file)
@@ -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;
     }
 
index ef6fcae79aaa02a4d1d46db2e22629ee3f76fca8..d209eabff51328ba337f8686a0b752a87b09194b 100644 (file)
@@ -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);
+    }
   }
 
   /**
index 73b4b8b41b8066357f326ccc512dfde28c2b88b8..e54150e77d244ab4ad990816afa0625b73afd962 100644 (file)
@@ -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
index 3fa23d7e1c5fdc19fa3bf86390f926b38cb27e10..2975e1959d9490027116dda71d849e7fc2723a15 100644 (file)
@@ -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'))) {
index 1072a9efec5a5ded1ba40cb887db9390c6d31fdc..e2493088b606c3dc89b15fe2ad850e3650653c0f 100644 (file)
@@ -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);
+    }
   }
 
   /**
index 92b0175ce3cdd21caf76f2447406438c520501c7..ba9aace19d1d0e6b71ff0c991ae01a0bc14febcf 100644 (file)
@@ -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',
index 97355050cc5dc22c27370a763a021c2ff07bb4e5..1661b0af056902a7dc491320164eb90eb980adc4 100644 (file)
@@ -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 {
index 435fcc0ac6d2b1b5eb865092488d5b5933154954..aafeb18090cc77e2f7a20b6cc06525e55ac62d6b 100644 (file)
       </div>
     {/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}
             <div class="crm-group billing_name_address-group">
                 <div class="header-dark">
index dfd3d1909903179cd22a9f8864e5dab74b9d5671..ea79486c8ee2737c1300c928961b47ea0ccc7e78 100644 (file)
 
   <div id="billing-payment-block">
     {* 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}
   </div>
index fa39cf4f9bfac8cbebbd90b84700e845057a8e75..d07a32b056d0fc857ad9266fe6f89465a0a47269 100644 (file)
       </div>
     {/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}
             <div class="crm-group billing_name_address-group">
                 <div class="header-dark">
index 85a4efe456234221f0262fe4d7b9c11caf711bc3..4fcd5d90690f81367cdc05d7e3f2eaf450950d11 100644 (file)
                     {/if}
                 </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}
                         </div>
                     </div>
                 </fieldset>
-            {else}
-                </fieldset>
-            {/if}
+
     </div>
 
      {if $profileAddressFields}
@@ -292,5 +293,5 @@ CRM.$(function($) {
 {/literal}
 </script>
 {/if}
-{/if}
+
 {/crmRegion}
index 435a508d7b854553e54d1f9f51d472341ef8d7d8..8b3a8ebcaaadf9a7ec2ce97a4c372101a6a6b686 100644 (file)
 
     {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}
       <div class="crm-group billing_name_address-group">
             <div class="header-dark">
                 {ts}Billing Name and Address{/ts}
index fffb3fb22f576ae5387693f9755091385318b616..33c00cfe65fb103ae99497fd32241bf8ee133bce 100644 (file)
 
     <div id="billing-payment-block">
       {* 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}
     </div>
index e55d507ac6cfff0fe504a6aeb794686702503031..7d10854e060aeba8e6f063370f011a1aa981a2fc 100644 (file)
     {/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}
         <div class="crm-group billing_name_address-group">
             <div class="header-dark">
                 {ts}Billing Name and Address{/ts}
index 8cb3c8a32b7c987bcada71a9dade6adff2c7786a..f3ad083fa8189e84d3ad152b877128ba2dc41ab2 100644 (file)
 <script type="text/javascript">
 
 function buildPaymentBlock( type ) {
-    if ( type == 0 ) {
-     if (cj("#billing-payment-block").length) {
-           cj("#billing-payment-block").html('');
-   }
-        return;
+  {/literal}{if !$isBillingAddressRequiredForPayLater}{literal}
+  if (type == 0) {
+    if (cj("#billing-payment-block").length) {
+      cj("#billing-payment-block").html('');
     }
+    return;
+  }
+  {/literal}{/if}{literal}
 
   var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&type='}"{literal} + type;