Merge pull request #18143 from mattwire/membertabbuttons
[civicrm-core.git] / templates / CRM / common / paymentBlock.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
8 +--------------------------------------------------------------------+
9 *}
10 {literal}
11 <script type="text/javascript">
12 /**
13 * Show or hide payment options.
14 *
15 * @param bool $isHide
16 * Should the block be hidden.
17 */
18 function showHidePayment(isHide) {
19 var payment_options = cj(".payment_options-group");
20 var payment_processor = cj("div.payment_processor-section");
21 var payment_information = cj("div#payment_information");
22 // I've added a hide for billing block. But, actually the issue
23 // might be that the unselecting of the processor should cause it
24 // to be hidden (or removed) in which case it can go from this function.
25 var billing_block = cj("div#billing-payment-block");
26 if (isHide) {
27 payment_options.hide();
28 payment_processor.hide();
29 payment_information.hide();
30 billing_block.hide();
31 // Ensure that jquery validation doesn't block submission when we don't need to fill in the billing details section
32 cj('#billing-payment-block select.crm-select2').addClass('crm-no-validate');
33 // also unset selected payment methods
34 cj('input[name="payment_processor_id"]').removeProp('checked');
35 }
36 else {
37 payment_options.show();
38 payment_processor.show();
39 payment_information.show();
40 billing_block.show();
41 cj('#billing-payment-block select.crm-select2').removeClass('crm-no-validate');
42 // also set selected payment methods
43 cj('input[name="payment_processor_id"][checked=checked]').prop('checked', true);
44 }
45 }
46
47 /**
48 * Hides or shows billing and payment options block depending on whether payment is required.
49 *
50 * In general incomplete orders or $0 orders do not require a payment block.
51 */
52 function skipPaymentMethod() {
53 var isHide = false;
54 var isMultiple = {/literal}{$event.is_multiple_registrations|@json_encode}{literal};
55 var alwaysShowFlag = (isMultiple && cj("#additional_participants").val());
56 var alwaysHideFlag = (cj("#bypass_payment").val() == 1);
57 var total_amount_tmp = cj('#pricevalue').data('raw-total');
58 // Hide billing questions if this is free
59 if (!alwaysShowFlag && total_amount_tmp == 0){
60 isHide = true;
61 }
62 else {
63 isHide = false;
64 }
65 if (alwaysHideFlag) {
66 isHide = true;
67 }
68 showHidePayment(isHide);
69 }
70 skipPaymentMethod();
71
72 CRM.$(function($) {
73 function buildPaymentBlock(type) {
74 var $form = $('#billing-payment-block').closest('form');
75 {/literal}
76 {if $contributionPageID}
77 {capture assign='contributionPageID'}id={$contributionPageID}&{/capture}
78 {else}
79 {capture assign='pageID'}{/capture}
80 {/if}
81 {if $custom_pre_id}
82 {capture assign='preProfileID'}pre_profile_id={$custom_pre_id}&{/capture}
83 {else}
84 {capture assign='preProfileID'}{/capture}
85 {/if}
86 {if $urlPathVar}
87 {capture assign='urlPathVar'}{$urlPathVar}&{/capture}
88 {else}
89 {capture assign='urlPathVar'}{/capture}
90 {/if}
91 {if $billing_profile_id}
92 {capture assign='profilePathVar'}billing_profile_id={$billing_profile_id}&{/capture}
93 {else}
94 {capture assign='profilePathVar'}{/capture}
95 {/if}
96
97 {capture assign='isBackOfficePathVar'}&is_back_office={$isBackOffice}&{/capture}
98
99 var payment_instrument_id = $('#payment_instrument_id').val();
100
101 var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="formName=`$form.formName`&currency=`$currency`&`$urlPathVar``$isBackOfficePathVar``$profilePathVar``$contributionPageID``$preProfileID`processor_id="}" + type;
102 {literal}
103 if (typeof(CRM.vars) != "undefined") {
104 if (typeof(CRM.vars.coreForm) != "undefined") {
105 if (typeof(CRM.vars.coreForm.contact_id) != "undefined") {
106 dataUrl = dataUrl + "&cid=" + CRM.vars.coreForm.contact_id;
107 }
108
109 if (typeof(CRM.vars.coreForm.checksum) != "undefined" ) {
110 dataUrl = dataUrl + "&cs=" + CRM.vars.coreForm.checksum;
111 }
112 }
113 }
114 dataUrl = dataUrl + "&payment_instrument_id=" + payment_instrument_id;
115
116 // Processors like pp-express will hide the form submit buttons, so re-show them when switching
117 $('.crm-submit-buttons', $form).show().find('input').prop('disabled', true);
118 CRM.loadPage(dataUrl, {target: '#billing-payment-block'});
119 }
120
121 $('[name=payment_processor_id]').on('change.paymentBlock', function() {
122 buildPaymentBlock($(this).val());
123 });
124
125 $('#payment_instrument_id').on('change.paymentBlock', function() {
126 buildPaymentBlock(0);
127 });
128
129 $('#billing-payment-block').on('crmLoad', function() {
130 $('.crm-submit-buttons input').prop('disabled', false);
131 })
132 });
133
134 </script>
135 {/literal}