2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
11 <script type="text/javascript">
13 * Show or hide payment options.
16 * Should the block be hidden.
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");
27 payment_options.hide();
28 payment_processor.hide();
29 payment_information.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');
37 payment_options.show();
38 payment_processor.show();
39 payment_information.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);
48 * Hides or shows billing and payment options block depending on whether payment is required.
50 * In general incomplete orders or $0 orders do not require a payment block.
52 function skipPaymentMethod() {
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){
68 showHidePayment(isHide);
73 function buildPaymentBlock(type) {
74 var $form = $('#billing-payment-block').closest('form');
76 {if $contributionPageID}
77 {capture assign='contributionPageID'}id={$contributionPageID}&{/capture}
79 {capture assign='pageID'}{/capture}
82 {capture assign='preProfileID'}pre_profile_id={$custom_pre_id}&{/capture}
84 {capture assign='preProfileID'}{/capture}
87 {capture assign='urlPathVar'}{$urlPathVar}&{/capture}
89 {capture assign='urlPathVar'}{/capture}
91 {if $billing_profile_id}
92 {capture assign='profilePathVar'}billing_profile_id={$billing_profile_id}&{/capture}
94 {capture assign='profilePathVar'}{/capture}
97 {capture assign='isBackOfficePathVar'}&is_back_office={$isBackOffice}&{/capture}
99 var payment_instrument_id = $('#payment_instrument_id').val();
101 var currency = '{$currency}';
102 currency = currency == '' ? $('#currency').val() : currency;
104 var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="formName=`$form.formName``$urlPathVar``$isBackOfficePathVar``$profilePathVar``$contributionPageID``$preProfileID`processor_id="}" + type;
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;
112 if (typeof(CRM.vars.coreForm.checksum) != "undefined" ) {
113 dataUrl = dataUrl + "&cs=" + CRM.vars.coreForm.checksum;
117 dataUrl = dataUrl + "&payment_instrument_id=" + payment_instrument_id + "¤cy=" + currency;
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);
121 CRM.loadPage(dataUrl, {target: '#billing-payment-block'});
124 $('[name=payment_processor_id], #currency').on('change.paymentBlock', function() {
125 var payment_processor_id = $('[name=payment_processor_id]:checked').val() == undefined ? $('[name=payment_processor_id]').val() : $('[name=payment_processor_id]:checked').val();
126 if (payment_processor_id != undefined) {
127 buildPaymentBlock(payment_processor_id);
131 $('#payment_instrument_id').on('change.paymentBlock', function() {
132 buildPaymentBlock(0);
135 $('#billing-payment-block').on('crmLoad', function() {
136 $('.crm-submit-buttons input').prop('disabled', false);