PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
← All changes | assets/js/payplug-checkout.js +106 -120 1.0.7 → 3.1.0 View file →
@@ -1,124 +1,110 @@
1 -/* global payplug_checkout_params */
2 -
1 +/* global window, payplug_checkout_params */
3 2 (function ($) {
4 -
5 - /**
6 - * For now we need to redefine the `_closeIframe` from the Payplug object
7 - * to trigger an event when it run. This allow us to redirect the user to
8 - * the cancelURL manually.
9 - */
10 - if (typeof Payplug != 'undefined') {
11 - Payplug._closeIframe = function (callback) {
12 - var node = document.getElementById("payplug-spinner");
13 - if (node) {
14 - node.style.display = "none";
15 - node.parentNode.removeChild(node);
3 + var payplug_checkout = {
4 + order_review: false,
5 + init: function () {
6 + if ($('form.woocommerce-checkout').length) {
7 + this.$form = $('form.woocommerce-checkout');
8 + this.$form.on(
9 + 'submit',
10 + this.onSubmit
11 + )
12 + }
13 + if ($('form#order_review').length) {
14 + this.order_review = true;
15 + this.$form = $('form#order_review');
16 + this.$form.on(
17 + 'submit',
18 + this.onSubmit
19 + )
20 + }
21 + },
22 + onSubmit: function (e) {
23 + request_url = payplug_checkout_params.ajax_url;
24 + if(payplug_checkout.order_review) {
25 + request_url = payplug_checkout_params.order_review_url;
16 26 }
17 - node = document.getElementById("wrapper-payplug-iframe");
18 - if (node) {
19 - this._fadeOut(node, function () {
20 - if (callback) {
21 - callback();
22 - }
23 - });
24 - }
25 - // Hard Remove iframe
26 - node.parentNode.removeChild(node);
27 - node = document.getElementById("iframe-payplug-close");
28 - if (node && node.parentNode) {
29 - node.parentNode.removeChild(node);
30 - }
31 27
32 - $(document).trigger('payplugIframeClosed');
33 - }
34 - }
28 + if (!payplug_checkout.isPayplugChosen()) {
29 + return;
30 + }
31 + // Use standard checkout process if a payment token has been
32 + // choose by a user.
33 + if (payplug_checkout.isPaymentTokenSelected()) {
34 + payplug_checkout.$form.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } });
35 + //Prevent submit and stop all other listeners from being triggered.
36 + e.preventDefault();
37 + e.stopImmediatePropagation();
38 + $.post(
39 + request_url,
40 + payplug_checkout.$form.serialize() + "&payplug_non_blocks=true"
41 + ).done(function (response) {
42 + if (response.result === "failure") {
43 + payplug_checkout.$form.unblock();
44 + var error_messages = response.messages || '';
45 + payplug_checkout.submit_error(error_messages);
46 + return;
47 + }
35 48
36 - var payplug_checkout = {
37 - init: function () {
38 - if ($('form.woocommerce-checkout').length) {
39 - this.$form = $('form.woocommerce-checkout');
40 - this.$form.on(
41 - 'submit',
42 - this.onSubmit
43 - )
44 - }
45 -
46 - if ($('form#order_review').length) {
47 - this.$form = $('form#order_review');
48 - this.$form.on(
49 - 'submit',
50 - this.onSubmit
51 - )
52 - }
53 -
54 - $(document).on('payplugIframeClosed', this.handleClosedIframe);
55 - },
56 - onSubmit: function (e) {
57 - if (!payplug_checkout.isPayplugChosen()) {
58 - return;
59 - }
60 -
61 - // Use standard checkout process if a payment token has been
62 - // choose by a user.
63 - if (payplug_checkout.isPaymentTokenSelected()) {
64 - return;
65 - }
66 -
67 - //Prevent submit and stop all other listeners from being triggered.
68 - e.preventDefault();
69 - e.stopImmediatePropagation();
70 -
71 - payplug_checkout.$form.block({message: null, overlayCSS: {background: '#fff', opacity: 0.6}});
72 -
73 - $.post(
74 - payplug_checkout_params.ajax_url,
75 - payplug_checkout.$form.serialize()
76 - ).done(payplug_checkout.openModal);
77 - },
78 - openModal: function (response) {
79 - payplug_checkout.$form.unblock();
80 -
81 - if ('success' !== response.result) {
82 - var error_messages = response.messages || '';
83 - payplug_checkout.submit_error(error_messages);
84 - return;
85 - }
86 -
87 - payplug_checkout.cancelUrl = response.cancel || false;
88 - Payplug.showPayment(response.redirect);
89 - },
90 - handleClosedIframe: function () {
91 - if (payplug_checkout.cancelUrl) {
92 - window.location.href = payplug_checkout.cancelUrl;
93 - }
94 - },
95 - isPayplugChosen: function () {
96 - return $('#payment_method_payplug').is(':checked');
97 - },
98 - isPaymentTokenSelected: function () {
99 - var token = $('input[name=wc-payplug-payment-token]:checked');
100 - return token.length > 0 && 'new' !== token.val();
101 - },
102 - submit_error: function (error_message) {
103 - $('.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message').remove();
104 - payplug_checkout.$form.prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">' + error_message + '</div>');
105 - payplug_checkout.$form.removeClass('processing').unblock();
106 - payplug_checkout.$form.find('.input-text, select, input:checkbox').trigger('validate').blur();
107 - payplug_checkout.scroll_to_notices();
108 - $(document.body).trigger('checkout_error');
109 - },
110 - scroll_to_notices: function () {
111 - var scrollElement = $('.woocommerce-NoticeGroup-updateOrderReview, .woocommerce-NoticeGroup-checkout');
112 -
113 - if (!scrollElement.length) {
114 - scrollElement = $('.form.checkout');
115 - }
116 -
117 - $('html, body').animate({
118 - scrollTop: (scrollElement.offset().top - 100)
119 - }, 500);
120 - }
121 - };
122 -
123 - payplug_checkout.init();
124 -})(jQuery);
49 + if(response.is_paid) {
50 + document.location.href = response.redirect;
51 + return;
52 + }
53 + Payplug.showPayment(response.redirect, true);
54 + });
55 + return;
56 + }
57 + if (!payplug_checkout_params.is_embedded) {
58 + return
59 + }
60 + //Prevent submit and stop all other listeners from being triggered.
61 + e.preventDefault();
62 + e.stopImmediatePropagation();
63 + payplug_checkout.$form.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } });
64 + $.post(
65 + request_url,
66 + payplug_checkout.$form.serialize() + "&payplug_non_blocks=true"
67 + ).done(payplug_checkout.openModal);
68 + },
69 + openModal: function (response) {
70 + payplug_checkout.$form.unblock();
71 + if ('success' !== response.result) {
72 + var error_messages = response.messages || '';
73 + payplug_checkout.submit_error(error_messages);
74 + return;
75 + }
76 + // Set the cancel URL use by PayPlug js when the user close the embedded payment form.
77 + window.redirection_url = response.cancel || false;
78 + Payplug.showPayment(response.redirect);
79 + },
80 + isPayplugChosen: function () {
81 + return ($('#payment_method_payplug').is(':checked') || $('#payment_method_american_express').is(':checked'));
82 + },
83 + isPaymentTokenSelected: function () {
84 + var token = $('input[name=wc-payplug-payment-token]:checked');
85 + return token.length > 0 && 'new' !== token.val();
86 + },
87 + submit_error: function (error_message) {
88 + var parsedHtml = $.parseHTML(error_message, document, false);
89 + $('.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message').remove();
90 + $('<div></div>')
91 + .addClass('woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout')
92 + .html(parsedHtml)
93 + .prependTo(payplug_checkout.$form);
94 + payplug_checkout.$form.removeClass('processing').unblock();
95 + payplug_checkout.$form.find('.input-text, select, input:checkbox').trigger('validate').blur();
96 + payplug_checkout.scroll_to_notices();
97 + $(document.body).trigger('checkout_error');
98 + },
99 + scroll_to_notices: function () {
100 + var scrollElement = $('.woocommerce-NoticeGroup-updateOrderReview, .woocommerce-NoticeGroup-checkout');
101 + if (!scrollElement.length) {
102 + scrollElement = $('.form.checkout');
103 + }
104 + $('html, body').animate({
105 + scrollTop: (scrollElement.offset().top - 100)
106 + }, 500);
107 + }
108 + };
109 + payplug_checkout.init();
110 +})(jQuery);