Merge pull request #14781 from civicrm/5.16
[civicrm-core.git] / templates / CRM / common / paymentBlock.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
fee14197 3 | CiviCRM version 5 |
6a488035 4 +--------------------------------------------------------------------+
6b83d5bd 5 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
26{literal}
27<script type="text/javascript">
5ec4b965 28 /**
29 * Show or hide payment options.
30 *
31 * @param bool $isHide
32 * Should the block be hidden.
33 */
34 function showHidePayment(isHide) {
35 var payment_options = cj(".payment_options-group");
36 var payment_processor = cj("div.payment_processor-section");
37 var payment_information = cj("div#payment_information");
38 // I've added a hide for billing block. But, actually the issue
39 // might be that the unselecting of the processor should cause it
40 // to be hidden (or removed) in which case it can go from this function.
41 var billing_block = cj("div#billing-payment-block");
42 if (isHide) {
43 payment_options.hide();
44 payment_processor.hide();
45 payment_information.hide();
46 billing_block.hide();
47 // also unset selected payment methods
48 cj('input[name="payment_processor_id"]').removeProp('checked');
49 }
50 else {
51 payment_options.show();
52 payment_processor.show();
53 payment_information.show();
54 billing_block.show();
e4e938ca
JP
55 // also set selected payment methods
56 cj('input[name="payment_processor_id"][checked=checked]').prop('checked', true);
5ec4b965 57 }
58 }
59
60 /**
61 * Hides or shows billing and payment options block depending on whether payment is required.
62 *
63 * In general incomplete orders or $0 orders do not require a payment block.
64 */
65 function skipPaymentMethod() {
66 var isHide = false;
8838f818 67 var isMultiple = {/literal}{$event.is_multiple_registrations|@json_encode}{literal};
5ec4b965 68 var alwaysShowFlag = (isMultiple && cj("#additional_participants").val());
69 var alwaysHideFlag = (cj("#bypass_payment").val() == 1);
70 var total_amount_tmp = cj('#pricevalue').data('raw-total');
71 // Hide billing questions if this is free
72 if (!alwaysShowFlag && total_amount_tmp == 0){
73 isHide = true;
74 }
75 else {
76 isHide = false;
77 }
78 if (alwaysHideFlag) {
79 isHide = true;
80 }
81 showHidePayment(isHide);
82 }
83 skipPaymentMethod();
6a488035 84
bc44463a
CW
85 CRM.$(function($) {
86 function buildPaymentBlock(type) {
79b237f9 87 var $form = $('#billing-payment-block').closest('form');
1d1fee72 88 {/literal}
bc44463a
CW
89 {if $contributionPageID}
90 {capture assign='contributionPageID'}id={$contributionPageID}&{/capture}
91 {else}
d38c288e 92 {capture assign='pageID'}{/capture}
93 {/if}
94 {if $custom_pre_id}
95 {capture assign='preProfileID'}pre_profile_id={$custom_pre_id}&{/capture}
96 {else}
97 {capture assign='preProfileID'}{/capture}
bc44463a
CW
98 {/if}
99 {if $urlPathVar}
100 {capture assign='urlPathVar'}{$urlPathVar}&{/capture}
101 {else}
102 {capture assign='urlPathVar'}{/capture}
103 {/if}
1d1fee72 104 {if $billing_profile_id}
105 {capture assign='profilePathVar'}billing_profile_id={$billing_profile_id}&{/capture}
106 {else}
107 {capture assign='profilePathVar'}{/capture}
108 {/if}
bc44463a 109
18135422 110 {capture assign='isBackOfficePathVar'}&is_back_office={$isBackOffice}&{/capture}
111
112 var payment_instrument_id = $('#payment_instrument_id').val();
113
6e22bf56 114 var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="formName=`$form.formName`&currency=`$currency`&`$urlPathVar``$isBackOfficePathVar``$profilePathVar``$contributionPageID``$preProfileID`processor_id="}" + type;
bc44463a 115 {literal}
064af727 116 if (typeof(CRM.vars) != "undefined") {
117 if (typeof(CRM.vars.coreForm) != "undefined") {
118 if (typeof(CRM.vars.coreForm.contact_id) != "undefined") {
119 dataUrl = dataUrl + "&cid=" + CRM.vars.coreForm.contact_id;
120 }
121
122 if (typeof(CRM.vars.coreForm.checksum) != "undefined" ) {
123 dataUrl = dataUrl + "&cs=" + CRM.vars.coreForm.checksum;
124 }
125 }
126 }
18135422 127 dataUrl = dataUrl + "&payment_instrument_id=" + payment_instrument_id;
064af727 128
79b237f9
CW
129 // Processors like pp-express will hide the form submit buttons, so re-show them when switching
130 $('.crm-submit-buttons', $form).show().find('input').prop('disabled', true);
bc44463a 131 CRM.loadPage(dataUrl, {target: '#billing-payment-block'});
6a488035 132 }
064af727 133
bc44463a
CW
134 $('[name=payment_processor_id]').on('change.paymentBlock', function() {
135 buildPaymentBlock($(this).val());
6a488035 136 });
18135422 137
794d4fc0 138 $('#payment_instrument_id').on('change.paymentBlock', function() {
139 buildPaymentBlock(0);
140 });
141
79b237f9
CW
142 $('#billing-payment-block').on('crmLoad', function() {
143 $('.crm-submit-buttons input').prop('disabled', false);
144 })
bc44463a 145 });
6a488035
TO
146
147</script>
148{/literal}