Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
2c4c49ca | 3 | | CiviCRM version 4.7 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
fa938177 | 5 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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(); | |
55 | } | |
56 | } | |
57 | ||
58 | /** | |
59 | * Hides or shows billing and payment options block depending on whether payment is required. | |
60 | * | |
61 | * In general incomplete orders or $0 orders do not require a payment block. | |
62 | */ | |
63 | function skipPaymentMethod() { | |
64 | var isHide = false; | |
65 | var isMultiple = '{/literal}{$event.is_multiple_registrations}{literal}'; | |
66 | var alwaysShowFlag = (isMultiple && cj("#additional_participants").val()); | |
67 | var alwaysHideFlag = (cj("#bypass_payment").val() == 1); | |
68 | var total_amount_tmp = cj('#pricevalue').data('raw-total'); | |
69 | // Hide billing questions if this is free | |
70 | if (!alwaysShowFlag && total_amount_tmp == 0){ | |
71 | isHide = true; | |
72 | } | |
73 | else { | |
74 | isHide = false; | |
75 | } | |
76 | if (alwaysHideFlag) { | |
77 | isHide = true; | |
78 | } | |
79 | showHidePayment(isHide); | |
80 | } | |
81 | skipPaymentMethod(); | |
6a488035 | 82 | |
bc44463a CW |
83 | CRM.$(function($) { |
84 | function buildPaymentBlock(type) { | |
79b237f9 | 85 | var $form = $('#billing-payment-block').closest('form'); |
1d1fee72 | 86 | {/literal} |
bc44463a CW |
87 | {if $contributionPageID} |
88 | {capture assign='contributionPageID'}id={$contributionPageID}&{/capture} | |
89 | {else} | |
90 | {capture assign='contributionPageID'}{/capture} | |
91 | {/if} | |
92 | {if $urlPathVar} | |
93 | {capture assign='urlPathVar'}{$urlPathVar}&{/capture} | |
94 | {else} | |
95 | {capture assign='urlPathVar'}{/capture} | |
96 | {/if} | |
1d1fee72 | 97 | {if $billing_profile_id} |
98 | {capture assign='profilePathVar'}billing_profile_id={$billing_profile_id}&{/capture} | |
99 | {else} | |
100 | {capture assign='profilePathVar'}{/capture} | |
101 | {/if} | |
bc44463a | 102 | |
f61437d3 | 103 | var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="currency=`$currency`&`$urlPathVar``$profilePathVar``$contributionPageID`processor_id="}" + type; |
bc44463a | 104 | {literal} |
064af727 | 105 | if (typeof(CRM.vars) != "undefined") { |
106 | if (typeof(CRM.vars.coreForm) != "undefined") { | |
107 | if (typeof(CRM.vars.coreForm.contact_id) != "undefined") { | |
108 | dataUrl = dataUrl + "&cid=" + CRM.vars.coreForm.contact_id; | |
109 | } | |
110 | ||
111 | if (typeof(CRM.vars.coreForm.checksum) != "undefined" ) { | |
112 | dataUrl = dataUrl + "&cs=" + CRM.vars.coreForm.checksum; | |
113 | } | |
114 | } | |
115 | } | |
116 | ||
79b237f9 CW |
117 | // Processors like pp-express will hide the form submit buttons, so re-show them when switching |
118 | $('.crm-submit-buttons', $form).show().find('input').prop('disabled', true); | |
bc44463a | 119 | CRM.loadPage(dataUrl, {target: '#billing-payment-block'}); |
6a488035 | 120 | } |
064af727 | 121 | |
ae8f569f | 122 | $('.crm-group.payment_options-group').show(); |
bc44463a CW |
123 | $('[name=payment_processor_id]').on('change.paymentBlock', function() { |
124 | buildPaymentBlock($(this).val()); | |
6a488035 | 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} |