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(); | |
31 | // also unset selected payment methods | |
32 | cj('input[name="payment_processor_id"]').removeProp('checked'); | |
33 | } | |
34 | else { | |
35 | payment_options.show(); | |
36 | payment_processor.show(); | |
37 | payment_information.show(); | |
38 | billing_block.show(); | |
e4e938ca JP |
39 | // also set selected payment methods |
40 | cj('input[name="payment_processor_id"][checked=checked]').prop('checked', true); | |
5ec4b965 | 41 | } |
42 | } | |
43 | ||
44 | /** | |
45 | * Hides or shows billing and payment options block depending on whether payment is required. | |
46 | * | |
47 | * In general incomplete orders or $0 orders do not require a payment block. | |
48 | */ | |
49 | function skipPaymentMethod() { | |
50 | var isHide = false; | |
8838f818 | 51 | var isMultiple = {/literal}{$event.is_multiple_registrations|@json_encode}{literal}; |
5ec4b965 | 52 | var alwaysShowFlag = (isMultiple && cj("#additional_participants").val()); |
53 | var alwaysHideFlag = (cj("#bypass_payment").val() == 1); | |
54 | var total_amount_tmp = cj('#pricevalue').data('raw-total'); | |
55 | // Hide billing questions if this is free | |
56 | if (!alwaysShowFlag && total_amount_tmp == 0){ | |
57 | isHide = true; | |
58 | } | |
59 | else { | |
60 | isHide = false; | |
61 | } | |
62 | if (alwaysHideFlag) { | |
63 | isHide = true; | |
64 | } | |
65 | showHidePayment(isHide); | |
66 | } | |
67 | skipPaymentMethod(); | |
6a488035 | 68 | |
bc44463a CW |
69 | CRM.$(function($) { |
70 | function buildPaymentBlock(type) { | |
79b237f9 | 71 | var $form = $('#billing-payment-block').closest('form'); |
1d1fee72 | 72 | {/literal} |
bc44463a CW |
73 | {if $contributionPageID} |
74 | {capture assign='contributionPageID'}id={$contributionPageID}&{/capture} | |
75 | {else} | |
d38c288e | 76 | {capture assign='pageID'}{/capture} |
77 | {/if} | |
78 | {if $custom_pre_id} | |
79 | {capture assign='preProfileID'}pre_profile_id={$custom_pre_id}&{/capture} | |
80 | {else} | |
81 | {capture assign='preProfileID'}{/capture} | |
bc44463a CW |
82 | {/if} |
83 | {if $urlPathVar} | |
84 | {capture assign='urlPathVar'}{$urlPathVar}&{/capture} | |
85 | {else} | |
86 | {capture assign='urlPathVar'}{/capture} | |
87 | {/if} | |
1d1fee72 | 88 | {if $billing_profile_id} |
89 | {capture assign='profilePathVar'}billing_profile_id={$billing_profile_id}&{/capture} | |
90 | {else} | |
91 | {capture assign='profilePathVar'}{/capture} | |
92 | {/if} | |
bc44463a | 93 | |
18135422 | 94 | {capture assign='isBackOfficePathVar'}&is_back_office={$isBackOffice}&{/capture} |
95 | ||
96 | var payment_instrument_id = $('#payment_instrument_id').val(); | |
97 | ||
6e22bf56 | 98 | var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="formName=`$form.formName`¤cy=`$currency`&`$urlPathVar``$isBackOfficePathVar``$profilePathVar``$contributionPageID``$preProfileID`processor_id="}" + type; |
bc44463a | 99 | {literal} |
064af727 | 100 | if (typeof(CRM.vars) != "undefined") { |
101 | if (typeof(CRM.vars.coreForm) != "undefined") { | |
102 | if (typeof(CRM.vars.coreForm.contact_id) != "undefined") { | |
103 | dataUrl = dataUrl + "&cid=" + CRM.vars.coreForm.contact_id; | |
104 | } | |
105 | ||
106 | if (typeof(CRM.vars.coreForm.checksum) != "undefined" ) { | |
107 | dataUrl = dataUrl + "&cs=" + CRM.vars.coreForm.checksum; | |
108 | } | |
109 | } | |
110 | } | |
18135422 | 111 | dataUrl = dataUrl + "&payment_instrument_id=" + payment_instrument_id; |
064af727 | 112 | |
79b237f9 CW |
113 | // Processors like pp-express will hide the form submit buttons, so re-show them when switching |
114 | $('.crm-submit-buttons', $form).show().find('input').prop('disabled', true); | |
bc44463a | 115 | CRM.loadPage(dataUrl, {target: '#billing-payment-block'}); |
6a488035 | 116 | } |
064af727 | 117 | |
bc44463a CW |
118 | $('[name=payment_processor_id]').on('change.paymentBlock', function() { |
119 | buildPaymentBlock($(this).val()); | |
6a488035 | 120 | }); |
18135422 | 121 | |
794d4fc0 | 122 | $('#payment_instrument_id').on('change.paymentBlock', function() { |
123 | buildPaymentBlock(0); | |
124 | }); | |
125 | ||
79b237f9 CW |
126 | $('#billing-payment-block').on('crmLoad', function() { |
127 | $('.crm-submit-buttons input').prop('disabled', false); | |
128 | }) | |
bc44463a | 129 | }); |
6a488035 TO |
130 | |
131 | </script> | |
132 | {/literal} |