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-apple-pay.js +25 -13 2.18.0 → 3.1.0 View file →
@@ -3,13 +3,15 @@
3 3
4 4 var $apple_pay_button = $('apple-pay-button')
5 5 var session = null;
6 6 var is_checkout = apple_pay_params.is_checkout;
7 + var is_order_pay = apple_pay_params.is_order_pay;
8 + var $form = is_order_pay ? $('form#order_review') : $('form.woocommerce-checkout');
7 9 var apple_pay = {
8 10 load_order_total: false,
9 11 init: function () {
10 12 $apple_pay_button = $('apple-pay-button')
11 - $apple_pay_button.on(
13 + $apple_pay_button.off('click', apple_pay.ProcessCheckout).on(
12 14 'click',
13 15 apple_pay.ProcessCheckout
14 16 )
15 17 },
@@ -18,16 +20,23 @@
18 20 e.stopImmediatePropagation()
19 21 apple_pay.CreateSession()
20 22 apple_pay.CancelOrder()
21 23 apple_pay.PaymentCompleted()
22 - $('form.woocommerce-checkout').block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } })
23 - $.post(
24 - apple_pay_params.ajax_url_payplug_create_order,
25 - $('form.woocommerce-checkout').serialize()
26 - ).done(apple_pay.OrdernPaymentCreated)
24 + $form.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } })
25 + var ajaxUrl = is_order_pay
26 + ? apple_pay_params.ajax_url_payplug_apple_pay_create_order_pay
27 + : apple_pay_params.ajax_url_payplug_create_order;
28 + var postData = is_order_pay
29 + ? {
30 + order_id: apple_pay_params.order_pay_id,
31 + order_key: apple_pay_params.order_pay_key,
32 + 'woocommerce-process-checkout-nonce': apple_pay_params.wp_nonce
33 + }
34 + : $form.serialize();
35 + $.post(ajaxUrl, postData).done(apple_pay.OrdernPaymentCreated)
27 36 },
28 37 OrdernPaymentCreated: function (response) {
29 - $('form.woocommerce-checkout').unblock()
38 + $form.unblock()
30 39 if ('success' !== response.result) {
31 40 var error_messages = response.messages || ''
32 41 apple_pay.SubmitError(error_messages)
33 42 return;
@@ -40,11 +49,11 @@
40 49 $('.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message').remove()
41 50 $('<div></div>')
42 51 .addClass('woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout')
43 52 .html(parsedHtml)
44 - .prependTo($('form.woocommerce-checkout'))
45 - $('form.woocommerce-checkout').removeClass('processing').unblock()
46 - $('form.woocommerce-checkout').find('.input-text, select, input:checkbox').trigger('validate').blur()
53 + .prependTo($form)
54 + $form.removeClass('processing').unblock()
55 + $form.find('.input-text, select, input:checkbox').trigger('validate').blur()
47 56 apple_pay.ScrollToNotices()
48 57 $(document.body).trigger('checkout_error')
49 58 },
50 59 ScrollToNotices: function () {
@@ -95,9 +104,9 @@
95 104 session.onvalidatemerchant = async event => {
96 105 try {
97 106 session.completeMerchantValidation(merchant_session)
98 107 } catch (err) {
99 - alert(err)
108 + apple_pay.CancelOrder();
100 109 }
101 110 }
102 111 },
103 112 CancelOrder: function () {
@@ -155,15 +164,18 @@
155 164 }
156 165 }
157 166
158 167 var applePaycontroller = function(){
168 + // On the order-pay page, the submit button only has id="place_order" (no
169 + // name="woocommerce_checkout_place_order"), so both selectors are needed to
170 + // disable it on both the regular checkout and the order-pay page.
159 171 if(jQuery("[name=payment_method]:checked").val() === "apple_pay"){
160 - jQuery("[name=woocommerce_checkout_place_order]").prop("disabled", true);
172 + jQuery("#place_order, [name=woocommerce_checkout_place_order]").prop("disabled", true);
161 173
162 174 //enable buttons
163 175 apple_pay.init();
164 176 }else{
165 - jQuery("[name=woocommerce_checkout_place_order]").prop("disabled", false);
177 + jQuery("#place_order, [name=woocommerce_checkout_place_order]").prop("disabled", false);
166 178 }
167 179 }
168 180
169 181 if( is_checkout ){