PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.16.19
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.16.19
4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / assets / js / checkout.js
wp-user-avatar / assets / js Last commit date
admin 1 month ago builder 1 month ago stripe 1 month ago admin.js 1 month ago checkout-fields-manager.js 1 month ago checkout.js 1 month ago clipboard.min.js 1 month ago content-control.js 1 month ago create-form.js 1 month ago frontend.js 1 month ago frontend.min.js 1 month ago index.php 1 month ago jcarousel.min.js 1 month ago jquery.blockUI.js 1 month ago mailoptin.js 1 month ago member-directory.js 1 month ago member-directory.min.js 1 month ago pp-wp-editor.js 1 month ago
checkout.js
412 lines
1 import $ from 'jquery';
2
3 export default function () {
4
5 let _this = this;
6
7 window.ppressCheckoutForm = this;
8
9 this.init = function () {
10
11 if (pp_ajax_form.is_checkout === '0' || $('#ppress_checkout_main_form').length === 0) return;
12
13 $(document).on('click', '.ppress-checkout-show-login-form', this.toggle_login_form);
14 $(document).on('click', '.ppress-login-submit-btn input[type="submit"]', this.process_login);
15 $(document).on('click', '.ppress-coupon-code-link', this.toggle_discount_code_reveal);
16 $(document).on('click', '.ppress-apply-discount-btn', this.apply_discount_code);
17 $(document).on('click', '#ppress-remove-applied-coupon', this.remove_applied_discount_code);
18 $(document).on('submit', '#ppress_mb_checkout_form', this.process_checkout);
19
20 $(document).on('click', '.ppress-terms-and-conditions-link', function (e) {
21 var cache = $('.ppress-checkout-form__terms_condition__content');
22 if (cache.length > 0) {
23 e.preventDefault();
24 cache.slideToggle();
25 }
26 });
27
28 $(document).on('ppress_update_checkout', this.update_checkout);
29
30 if (pp_ajax_form.is_checkout_tax_enabled === '1') {
31 $(document).on('change', '#ppress_mb_checkout_form .ppress_billing_country, #ppress_mb_checkout_form .ppress_billing_state, #ppress_mb_checkout_form .ppress_vat_number', _this.debounce(function () {
32 $(document.body).trigger('ppress_update_checkout');
33 }, 200));
34 } else {
35 $(document).on('change', '#ppress_mb_checkout_form .ppress_billing_country', _this.contextual_state_field);
36 }
37
38 // Update payment method change
39 $(document.body).on('change', '#ppress_checkout_payment_methods [name=ppress_payment_method]', function () {
40 $(document.body).trigger('ppress_update_checkout');
41 });
42
43 // Update on autorenewal checkbox check
44 $(document.body).on('change', '#ppress_mb_checkout_form #ppress-checkout-renewal', function () {
45 $(document.body).trigger('ppress_update_checkout');
46 });
47
48 // Update group selection change
49 $(document.body).on('change', '#ppress_mb_checkout_form [name=group_selector]', function () {
50 _this.update_checkout();
51 });
52
53 // Update on page load.
54 $(document.body).trigger('ppress_update_checkout');
55
56 $(document).ajaxError(function () {
57 _this.remove_spinner();
58 });
59 };
60
61 this.debounce = function (fun, mil) {
62 let timer;
63 mil = mil || 600;
64 return function () {
65 clearTimeout(timer);
66 timer = setTimeout(function () {
67 fun();
68 }, mil);
69 };
70 };
71
72 this.contextual_state_field = function () {
73
74 let state_field = $('.ppress_billing_state');
75
76 let data = {
77 'action': 'ppress_contextual_state_field',
78 'country': $(this).val(),
79 'name': state_field.prop('name'),
80 'id': state_field.prop('id'),
81 'class': state_field.prop('class'),
82 'csrf': $('#ppress_checkout_nonce').val()
83 };
84
85 $.post(pp_ajax_form.ajaxurl, data, function (response) {
86 state_field.replaceWith(response.data);
87 });
88 };
89
90 this.scroll_to_notices = function (scrollElement) {
91
92 if (pp_ajax_form.is_checkout_autoscroll_enabled === 'true') {
93
94 scrollElement = scrollElement || $('.ppress-checkout-alert');
95 if (scrollElement.length) {
96 $('html, body').animate({
97 scrollTop: (scrollElement.offset().top - 100)
98 }, 1000);
99 }
100 }
101 };
102
103 this.update_checkout = function (ignoreChangePlanRefresh) {
104
105 ignoreChangePlanRefresh = ignoreChangePlanRefresh || false;
106
107 let isChangePlanUpdate = $('#ppress_mb_checkout_form [name=group_selector]').length > 0;
108
109 _this.removeAllAlerts();
110
111 _this.add_spinner();
112
113 let data = {
114 'action': 'ppress_update_order_review',
115 'plan_id': $('#ppress-checkout-plan-id').val(),
116 'ppress_payment_method': $('#ppress_checkout_payment_methods [name=ppress_payment_method]:checked').val(),
117 'csrf': $('#ppress_checkout_nonce').val(),
118 'address': $('.ppress-checkout-form__payment_method.ppress-active .ppress_billing_address').val(),
119 'city': $('.ppress-checkout-form__payment_method.ppress-active .ppress_billing_city').val(),
120 'country': $('.ppress-checkout-form__payment_method.ppress-active .ppress_billing_country').val(),
121 'state': $('.ppress-checkout-form__payment_method.ppress-active .ppress_billing_state').val(),
122 'postcode': $('.ppress-checkout-form__payment_method.ppress-active .ppress_billing_postcode').val(),
123 'phone': $('.ppress-checkout-form__payment_method.ppress-active .ppress_billing_phone').val(),
124 'vat_number': $('#ppress_checkout_main_form .ppress_vat_number').val(),
125 'post_data': $('#ppress_mb_checkout_form').serialize()
126 };
127
128 if (isChangePlanUpdate === true) {
129 data['isChangePlanUpdate'] = 'true';
130 }
131
132 $.post(pp_ajax_form.ajaxurl, data, function (response) {
133
134 // Save payment details to a temporary object
135 let paymentDetails = {};
136
137 $('.ppress-checkout-form__payment_method :input, .ppress-checkout_account_info-wrap :input').each(function () {
138
139 let ID = $(this).attr('id');
140
141 if (ID) {
142 if ($.inArray($(this).attr('type'), ['checkbox', 'radio']) !== -1) {
143 paymentDetails[ID] = $(this).prop('checked');
144 } else {
145 paymentDetails[ID] = $(this).val();
146 }
147 }
148 });
149
150 // Always update the fragments
151 if ('data' in response && typeof response.data.fragments !== 'undefined') {
152 $.each(response.data.fragments, function (key, value) {
153 if (!_this.fragments || _this.fragments[key] !== value) {
154 $(key).replaceWith(value);
155 }
156 });
157 _this.fragments = data.fragments;
158 }
159
160 // Fill in the payment details if possible without overwriting data if set.
161 if (!$.isEmptyObject(paymentDetails)) {
162 $('.ppress-checkout-form__payment_method :input, .ppress-checkout_account_info-wrap :input').each(function () {
163 let ID = $(this).attr('id');
164 if (ID) {
165 if ($.inArray($(this).attr('type'), ['checkbox', 'radio']) !== -1) {
166 $(this).prop('checked', paymentDetails[ID]);
167 } else if ($.inArray($(this).attr('type'), ['select']) !== -1) {
168 $(this).val(paymentDetails[ID]);
169 } else {
170 $(this).val(paymentDetails[ID]);
171 }
172 }
173 });
174 }
175
176 // Check for error
177 if ('success' in response && false === response.success) {
178
179 let $checkout_form_section = $('#ppress_checkout_main_form');
180
181 if (response.data) {
182 $checkout_form_section.prepend(response.data);
183 }
184
185 // Lose focus for all fields
186 $checkout_form_section.find('.input-text, select, input:checkbox').trigger('blur');
187 }
188
189 // Fire updated_checkout event.
190 $(document.body).trigger('ppress_updated_checkout', [response]);
191
192 let scrollToSelector = $('.ppress-checkout_order_summary__bottom_details'), cache;
193
194 if ((cache = $('.ppress-checkout-alert')).length > 0) {
195 scrollToSelector = cache;
196 }
197
198 _this.scroll_to_notices(scrollToSelector);
199
200 _this.remove_spinner();
201
202 // it's important we re-init checkout to keep things working
203 if (isChangePlanUpdate === true && ignoreChangePlanRefresh !== true) {
204 _this.update_checkout(true);
205 }
206 });
207 };
208
209 this.toggle_login_form = function (e) {
210 e.preventDefault();
211 $('#ppress_checkout_account_info .ppress-main-checkout-form__login_form_wrap').slideToggle();
212 };
213
214 this.toggle_discount_code_reveal = function (e) {
215 e.preventDefault();
216 $('#ppress-checkout-coupon-code-wrap').slideToggle();
217 };
218
219 this.apply_discount_code = function (e) {
220 e.preventDefault();
221
222 _this.removeAllAlerts();
223
224 _this.add_spinner();
225
226 let data = {
227 'action': 'ppress_checkout_apply_discount',
228 'plan_id': $('#ppress-checkout-plan-id').val(),
229 'coupon_code': $('#apply-discount').val(),
230 'ppress_checkout_nonce': $('#ppress_checkout_nonce').val(),
231 };
232
233 $.post(pp_ajax_form.ajaxurl, data, function (response) {
234 if ('success' in response && response.success === true) {
235 $(document.body).trigger('ppress_update_checkout');
236 } else {
237 $('.ppress-checkout_order_summary-wrap').before(response.data);
238
239 _this.remove_spinner();
240 }
241 });
242 };
243
244 this.remove_applied_discount_code = function (e) {
245 e.preventDefault();
246
247 _this.removeAllAlerts();
248
249 _this.add_spinner();
250
251 let data = {
252 'action': 'ppress_checkout_remove_discount',
253 'plan_id': $('#ppress-checkout-plan-id').val(),
254 'ppress_checkout_nonce': $('#ppress_checkout_nonce').val(),
255 };
256
257 $.post(pp_ajax_form.ajaxurl, data, function (response) {
258 if ('success' in response && response.success === true) {
259 $(document.body).trigger('ppress_update_checkout');
260 } else {
261 $('.ppress-checkout_order_summary-wrap').before(response.data);
262
263 _this.remove_spinner();
264 }
265 });
266 };
267
268 this.process_login = function (e) {
269
270 e.preventDefault();
271
272 _this.removeAllAlerts();
273
274 _this.add_spinner();
275
276 let data = {
277 'action': 'ppress_process_checkout_login',
278 'ppmb_user_login': $('#ppress_mb_checkout_form #ppmb_user_login').val(),
279 'ppmb_user_pass': $('#ppress_mb_checkout_form #ppmb_user_pass').val(),
280 'ppress_checkout_nonce': $('#ppress_checkout_nonce').val(),
281 };
282
283 $.post(pp_ajax_form.ajaxurl, data, function (response) {
284 if ('success' in response) {
285 if (response.success === true) {
286 window.location.reload();
287 } else if ('data' in response) {
288 $('#ppress_mb_checkout_form .ppress-login-submit-btn').prepend(response.data);
289 }
290 }
291
292 _this.remove_spinner();
293 });
294 };
295
296 this.process_checkout = function (e) {
297
298 if (typeof this.checkValidity === 'function' && false === this.checkValidity()) {
299 return;
300 }
301
302 e.preventDefault();
303
304 _this.removeAllAlerts();
305
306 _this.add_spinner();
307
308 var $form = $(this), $payment_method = _this.get_payment_method();
309
310 if ($form.triggerHandler('ppress_checkout_place_order_' + $payment_method) !== false) {
311
312 let formData = new FormData(this);
313 formData.append("action", "ppress_process_checkout");
314 formData.append("ppress_checkout_nonce", $('#ppress_checkout_nonce').val());
315
316 $.post({
317 url: pp_ajax_form.ajaxurl,
318 data: formData,
319 cache: false,
320 contentType: false,
321 enctype: 'multipart/form-data',
322 processData: false,
323 dataType: 'json',
324 success: function (response) {
325
326 $(document.body).trigger('ppress_process_checkout_success_callback', [response]);
327
328 if ('success' in response) {
329
330 if (response.success === true) {
331
332 if ($form.triggerHandler('ppress_process_checkout_' + $payment_method, [response, $payment_method]) !== false) {
333
334 if ('redirect_url' in response && typeof response.redirect_url !== 'undefined' && response.redirect_url.length > 0) {
335 window.location.assign(response.redirect_url);
336 } else {
337
338 $(document.body).trigger('ppress_checkout_success', [response, $payment_method]);
339
340 window.location.assign(response.order_success_url);
341 }
342 }
343
344 return;
345
346 }
347
348 if ('error_message' in response) {
349 return _this.createAlertMessage(response.error_message);
350 }
351
352 if ('data' in response && typeof response.data == 'string') {
353 return _this.createAlertMessage(response.data);
354 }
355
356 return;
357 }
358
359 _this.remove_spinner();
360 },
361 error: function (jqXHR, textStatus, errorThrown) {
362 $(document.body).trigger('ppress_process_checkout_error_callback', [jqXHR, textStatus, errorThrown]);
363 _this.createAlertMessage(errorThrown);
364 }
365 }, 'json',);
366 }
367 };
368
369 this.get_payment_method = function () {
370 return $('#ppress_mb_checkout_form').find('input[name="ppress_payment_method"]:checked').val();
371 };
372
373 this.createAlertMessage = function (message, type) {
374 type = type || 'error';
375 var is_marked_up = typeof message.indexOf !== 'undefined' && message.indexOf('ppress-checkout-alert') !== -1,
376 msg = '';
377
378 if (!is_marked_up) msg = '<div class="ppress-checkout-alert ppress-' + type + '"><p>';
379
380 msg += message;
381
382 if (!is_marked_up) msg += '</p></div>';
383
384 $('#ppress_checkout_main_form').prepend(msg);
385
386 ppressCheckoutForm.scroll_to_notices();
387 ppressCheckoutForm.remove_spinner();
388
389 $(document.body).trigger('ppress_checkout_error', [message]);
390 };
391
392 this.removeAllAlerts = function () {
393 $('.ppress-checkout-alert').remove();
394 };
395
396 this.add_spinner = function () {
397 _this.remove_spinner();
398 $('.ppress-checkout__form').prepend('<div class="ppress-checkout__form__preloader"><div class="ppress-checkout__form__spinner"></div></div>')
399 };
400
401 this.remove_spinner = function () {
402 $('.ppress-checkout__form .ppress-checkout__form__preloader').remove()
403 };
404
405 this.is_var_defined = function (val) {
406 return typeof val !== 'undefined' && val !== null;
407 };
408
409 this.get_obj_val = function (val, $default) {
410 return this.is_var_defined(val) && val !== "" ? val : $default;
411 };
412 }