1 | | /** |
2 | | * Give - Razorpay Popup Checkout JS |
3 | | */ |
4 | | var camptix_l10n, camptix_inr_vars; |
5 | | |
6 | | /** |
7 | | * On document ready setup Razorpay events. |
8 | | */ |
9 | | jQuery(document).ready(function ($) { |
10 | | // Cache donation button title early to reset it if razorpay checkout popup close. |
11 | | var razorpay_handler = [], |
12 | | $container = $('#tix'), |
13 | | $form = $('form', $container), |
14 | | ticket_quantity = $('.tix_tickets_table td.tix-column-quantity', $container).text(), |
15 | | order_id = $('input[name="razorpay_order_id"]', $form).val(), |
16 | | receipt_id = $('input[name="razorpay_receipt_id"]', $form).val(); |
17 | | |
18 | | /** |
19 | | * Validate extra attendee information fields. |
20 | | * |
21 | | * @returns {boolean} |
22 | | */ |
23 | | var validate_fields = function () { |
24 | | for (var i = 1; i <= ticket_quantity; i++) { |
25 | | if (!$('input[name="tix_attendee_info[' + i + '][phone]"]', $form).val()) { |
26 | | return false; |
27 | | } |
28 | | } |
29 | | return true; |
30 | | }; |
31 | | |
32 | | /** |
33 | | * Show errors. |
34 | | * |
35 | | * @param error_html |
36 | | */ |
37 | | var show_errors = function (error_html) { |
38 | | var $errors = ''; |
39 | | |
40 | | // Remove old errors html. |
41 | | $('#tix-errors', $container).remove(); |
42 | | |
43 | | // Set new error html. |
44 | | $errors = $('<div id="tix-errors"></div>').html(error_html); |
45 | | $container.prepend($errors); |
46 | | |
47 | | // Scroll to error div. |
48 | | $('html,body').animate({ |
49 | | scrollTop: $container.offset().top |
50 | | }, |
51 | | 'slow' |
52 | | ); |
53 | | }; |
54 | | |
55 | | /** |
56 | | * Show/ Hide extra attendee fields. |
57 | | * |
58 | | * @param show |
59 | | */ |
60 | | var show_custom_attendee_fields = function (show) { |
61 | | var $field_container; |
62 | | |
63 | | for (var i = 1; i <= 2; i++) { |
64 | | $field_container = $('input[name="tix_attendee_info[' + i + '][phone]"]', $form).closest('tr'); |
65 | | |
66 | | if (show) { |
67 | | $field_container.show(); |
68 | | } else { |
69 | | $field_container.hide(); |
70 | | } |
71 | | } |
72 | | }; |
73 | | |
74 | | /** |
75 | | * Show extra attendee fields only if razorpay selected |
76 | | */ |
77 | | $('select[name="tix_payment_method"]', $form).on('change', function () { |
78 | | |
79 | | }).change(); |
80 | | |
81 | | /** |
82 | | * Increase razorpay's z-index to appear above of all content. |
83 | | */ |
84 | | $('.razorpay-container').css('z-index', '2147483543'); |
85 | | |
86 | | /** |
87 | | * On form submit prevent submission for Razorpay only. |
88 | | */ |
89 | | $form.on('submit', function (e) { |
90 | | |
91 | | var phone = $('.mobile').val(); |
92 | | console.log(phone); |
93 | | phone = phone.replace(/[^0-9]/g,''); |
94 | | |
95 | | if(!($.isNumeric(phone))){ |
96 | | console.log('test'); |
97 | | $('.message').text('Please Enter Only Numbers'); |
98 | | $('.message').css('color','red'); |
99 | | $('.mobile').val(''); |
100 | | $('.mobile').focus(); |
101 | | e.preventDefault(); |
102 | | return false; |
103 | | }else |
104 | | if (phone.length < 10 ) |
105 | | { |
106 | | console.log('test'); |
107 | | //alert('Phone number must be 10 digits.'); |
108 | | $('.message').text('Please Enter correct Mobile Number Or Number with STD Code'); |
109 | | $('.message').css('color','red'); |
110 | | $('.mobile').val(''); |
111 | | $('.mobile').focus(); |
112 | | //alert(); |
113 | | e.preventDefault(); |
114 | | |
115 | | return false; |
116 | | |
117 | | } |
118 | | |
119 | | // Bailout. |
120 | | if (camptix_inr_vars.gateway_id !== $('select[name="tix_payment_method"]', $form).val()) { |
121 | | return true; |
122 | | } |
123 | | |
124 | | e.preventDefault(); |
125 | | |
126 | | return false; |
127 | | }); |
128 | | |
129 | | /** |
130 | | * When the submit button is clicked. |
131 | | */ |
132 | | $form.on('click touchend', 'input[type="submit"]', function (e) { |
133 | | // Bailout. |
134 | | if (camptix_inr_vars.gateway_id !== $('select[name="tix_payment_method"]', $form).val()) { |
135 | | return true; |
136 | | } |
137 | | |
138 | | e.preventDefault(); |
139 | | |
140 | | // Validate custom attendee information fields. |
141 | | if (!validate_fields()) { |
142 | | show_errors('<div class="tix-error">' + camptix_inr_vars.errors.phone + '</div>'); |
143 | | |
144 | | return false; |
145 | | } |
146 | | |
147 | | var $submit_button = $(this), |
148 | | $response; |
149 | | |
150 | | $.post($form.attr('action'), $form.serialize()) |
151 | | .done(function (response) { |
152 | | // Bailout. |
153 | | if (!response.success) { |
154 | | var $el = $('<div></div>').html(response); |
155 | | |
156 | | show_errors($('#tix-errors', $el).html()); |
157 | | |
158 | | return false; |
159 | | } |
160 | | |
161 | | // Cache response for internal use in Razorpay. |
162 | | $response = response; |
163 | | |
164 | | razorpay_handler = new Razorpay({ |
165 | | 'key' : camptix_inr_vars.merchant_key_id, |
166 | | 'order_id': order_id, |
167 | | 'name' : $response.data.popup_title, |
168 | | 'image' : camptix_inr_vars.popup.image, |
169 | | // 'description' : '', |
170 | | 'handler' : function (response) { |
171 | | // Remove loading animations. |
172 | | // $form.find('.give-loading-animation').hide(); |
173 | | // Disable form submit button. |
174 | | $submit_button.prop('disabled', true); |
175 | | |
176 | | // Submit form after charge token brought back from Razorpay. |
177 | | // Redirect to success page. |
178 | | window.location.assign($response.data.return_url + '&transaction_id=' + order_id + '&receipt_id=' + receipt_id); |
179 | | }, |
180 | | |
181 | | // You can add custom data here and fields limited to 15. |
182 | | // 'notes': { |
183 | | // 'extra_information' : $response.data |
184 | | // }, |
185 | | 'prefill': { |
186 | | 'name' : $response.data.fullname, |
187 | | 'email' : $response.data.email, |
188 | | 'contact': $response.data.phone |
189 | | }, |
190 | | |
191 | | 'modal': { |
192 | | 'ondismiss': function () { |
193 | | // Remove loading animations. |
194 | | $form.find('.give-loading-animation').hide(); |
195 | | |
196 | | // Re-enable submit button and add back text. |
197 | | $submit_button.prop('disabled', false); |
198 | | } |
199 | | }, |
200 | | |
201 | | 'theme': { |
202 | | 'color' : camptix_inr_vars.popup.color, |
203 | | 'image_padding': false |
204 | | } |
205 | | }); |
206 | | |
207 | | razorpay_handler.open(); |
208 | | }) |
209 | | .fail(function () { |
210 | | }) |
211 | | .always(function () { |
212 | | // Enable form submit button. |
213 | | $submit_button.prop('disabled', false); |
214 | | }); |
215 | | |
216 | | return false; |
217 | | }); |
218 | | }); |
| 1 | /** |
| 2 | * Give - Razorpay Popup Checkout JS |
| 3 | */ |
| 4 | var camptix_l10n, camptix_inr_vars; |
| 5 | |
| 6 | /** |
| 7 | * On document ready setup Razorpay events. |
| 8 | */ |
| 9 | jQuery(document).ready(function ($) { |
| 10 | // Cache donation button title early to reset it if razorpay checkout popup close. |
| 11 | var razorpay_handler = [], |
| 12 | $container = $('#tix'), |
| 13 | $form = $('form', $container), |
| 14 | ticket_quantity = $('.tix_tickets_table td.tix-column-quantity', $container).text(), |
| 15 | order_id = $('input[name="razorpay_order_id"]', $form).val(), |
| 16 | receipt_id = $('input[name="razorpay_receipt_id"]', $form).val(); |
| 17 | |
| 18 | /** |
| 19 | * Validate extra attendee information fields. |
| 20 | * |
| 21 | * @returns {boolean} |
| 22 | */ |
| 23 | var validate_fields = function () { |
| 24 | for (var i = 1; i <= ticket_quantity; i++) { |
| 25 | if (!$('input[name="tix_attendee_info[' + i + '][phone]"]', $form).val()) { |
| 26 | return false; |
| 27 | } |
| 28 | } |
| 29 | return true; |
| 30 | }; |
| 31 | |
| 32 | /** |
| 33 | * Show errors. |
| 34 | * |
| 35 | * @param error_html |
| 36 | */ |
| 37 | var show_errors = function (error_html) { |
| 38 | var $errors = ''; |
| 39 | |
| 40 | // Remove old errors html. |
| 41 | $('#tix-errors', $container).remove(); |
| 42 | |
| 43 | // Set new error html. |
| 44 | $errors = $('<div id="tix-errors"></div>').html(error_html); |
| 45 | $container.prepend($errors); |
| 46 | |
| 47 | // Scroll to error div. |
| 48 | $('html,body').animate({ |
| 49 | scrollTop: $container.offset().top |
| 50 | }, |
| 51 | 'slow' |
| 52 | ); |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * Show/ Hide extra attendee fields. |
| 57 | * |
| 58 | * @param show |
| 59 | */ |
| 60 | var show_custom_attendee_fields = function (show) { |
| 61 | var $field_container; |
| 62 | |
| 63 | for (var i = 1; i <= 2; i++) { |
| 64 | $field_container = $('input[name="tix_attendee_info[' + i + '][phone]"]', $form).closest('tr'); |
| 65 | |
| 66 | if (show) { |
| 67 | $field_container.show(); |
| 68 | } else { |
| 69 | $field_container.hide(); |
| 70 | } |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * Show extra attendee fields only if razorpay selected |
| 76 | */ |
| 77 | $('select[name="tix_payment_method"]', $form).on('change', function () { |
| 78 | |
| 79 | }).change(); |
| 80 | |
| 81 | /** |
| 82 | * Increase razorpay's z-index to appear above of all content. |
| 83 | */ |
| 84 | $('.razorpay-container').css('z-index', '2147483543'); |
| 85 | |
| 86 | /** |
| 87 | * On form submit prevent submission for Razorpay only. |
| 88 | */ |
| 89 | $form.on('submit', function (e) { |
| 90 | |
| 91 | var phone = $('.mobile').val(); |
| 92 | phone = phone.replace(/[^0-9]/g,''); |
| 93 | |
| 94 | if(!($.isNumeric(phone))){ |
| 95 | $('.message').text('Please Enter Only Numbers'); |
| 96 | $('.message').css('color','red'); |
| 97 | $('.mobile').val(''); |
| 98 | $('.mobile').focus(); |
| 99 | e.preventDefault(); |
| 100 | return false; |
| 101 | }else |
| 102 | if (phone.length < 10 ) |
| 103 | { |
| 104 | //alert('Phone number must be 10 digits.'); |
| 105 | $('.message').text('Please Enter correct Mobile Number Or Number with STD Code'); |
| 106 | $('.message').css('color','red'); |
| 107 | $('.mobile').val(''); |
| 108 | $('.mobile').focus(); |
| 109 | //alert(); |
| 110 | e.preventDefault(); |
| 111 | |
| 112 | return false; |
| 113 | |
| 114 | } |
| 115 | return true; |
| 116 | // Bailout. |
| 117 | }); |
| 118 | }); |