Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
1188c7a8 | 3 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 4 | | | |
1188c7a8 TO |
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 | | |
6a488035 TO |
8 | +--------------------------------------------------------------------+ |
9 | *} | |
10 | {literal} | |
11 | <script type="text/javascript"> | |
5ec4b965 | 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(); | |
f2882c11 SL |
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'); | |
5ec4b965 | 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(); | |
f2882c11 | 41 | cj('#billing-payment-block select.crm-select2').removeClass('crm-no-validate'); |
e4e938ca JP |
42 | // also set selected payment methods |
43 | cj('input[name="payment_processor_id"][checked=checked]').prop('checked', true); | |
5ec4b965 | 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; | |
8838f818 | 54 | var isMultiple = {/literal}{$event.is_multiple_registrations|@json_encode}{literal}; |
5ec4b965 | 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(); | |
6a488035 | 71 | |
bc44463a CW |
72 | CRM.$(function($) { |
73 | function buildPaymentBlock(type) { | |
79b237f9 | 74 | var $form = $('#billing-payment-block').closest('form'); |
1d1fee72 | 75 | {/literal} |
bc44463a CW |
76 | {if $contributionPageID} |
77 | {capture assign='contributionPageID'}id={$contributionPageID}&{/capture} | |
78 | {else} | |
d38c288e | 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} | |
bc44463a CW |
85 | {/if} |
86 | {if $urlPathVar} | |
87 | {capture assign='urlPathVar'}{$urlPathVar}&{/capture} | |
88 | {else} | |
89 | {capture assign='urlPathVar'}{/capture} | |
90 | {/if} | |
1d1fee72 | 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} | |
bc44463a | 96 | |
18135422 | 97 | {capture assign='isBackOfficePathVar'}&is_back_office={$isBackOffice}&{/capture} |
98 | ||
99 | var payment_instrument_id = $('#payment_instrument_id').val(); | |
100 | ||
7aacd50f MD |
101 | var currency = '{$currency}'; |
102 | currency = currency == '' ? $('#currency').val() : currency; | |
103 | ||
104 | var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="formName=`$form.formName``$urlPathVar``$isBackOfficePathVar``$profilePathVar``$contributionPageID``$preProfileID`processor_id="}" + type; | |
bc44463a | 105 | {literal} |
064af727 | 106 | if (typeof(CRM.vars) != "undefined") { |
107 | if (typeof(CRM.vars.coreForm) != "undefined") { | |
108 | if (typeof(CRM.vars.coreForm.contact_id) != "undefined") { | |
109 | dataUrl = dataUrl + "&cid=" + CRM.vars.coreForm.contact_id; | |
110 | } | |
111 | ||
112 | if (typeof(CRM.vars.coreForm.checksum) != "undefined" ) { | |
113 | dataUrl = dataUrl + "&cs=" + CRM.vars.coreForm.checksum; | |
114 | } | |
115 | } | |
116 | } | |
7aacd50f | 117 | dataUrl = dataUrl + "&payment_instrument_id=" + payment_instrument_id + "¤cy=" + currency; |
064af727 | 118 | |
79b237f9 CW |
119 | // Processors like pp-express will hide the form submit buttons, so re-show them when switching |
120 | $('.crm-submit-buttons', $form).show().find('input').prop('disabled', true); | |
bc44463a | 121 | CRM.loadPage(dataUrl, {target: '#billing-payment-block'}); |
6a488035 | 122 | } |
064af727 | 123 | |
7aacd50f | 124 | $('[name=payment_processor_id], #currency').on('change.paymentBlock', function() { |
b86dc53e | 125 | var payment_processor_id = $('[name=payment_processor_id]:checked').val() == undefined ? $('[name=payment_processor_id]').val() : $('[name=payment_processor_id]:checked').val(); |
10495d04 MD |
126 | if (payment_processor_id != undefined) { |
127 | buildPaymentBlock(payment_processor_id); | |
128 | } | |
6a488035 | 129 | }); |
18135422 | 130 | |
794d4fc0 | 131 | $('#payment_instrument_id').on('change.paymentBlock', function() { |
132 | buildPaymentBlock(0); | |
133 | }); | |
134 | ||
79b237f9 CW |
135 | $('#billing-payment-block').on('crmLoad', function() { |
136 | $('.crm-submit-buttons input').prop('disabled', false); | |
137 | }) | |
bc44463a | 138 | }); |
6a488035 TO |
139 | |
140 | </script> | |
141 | {/literal} |