| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | /* global window, payplug_checkout_params */ |
| 2 | 2 | (function ($) { |
| 3 | 3 | var payplug_checkout = { |
| 4 | + order_review: false, | |
| 4 | 5 | init: function () { |
| 5 | 6 | if ($('form.woocommerce-checkout').length) { |
| 6 | 7 | this.$form = $('form.woocommerce-checkout'); |
| 7 | 8 | this.$form.on( |
| @@ -9,8 +10,9 @@ | ||
| 9 | 10 | this.onSubmit |
| 10 | 11 | ) |
| 11 | 12 | } |
| 12 | 13 | if ($('form#order_review').length) { |
| 14 | + this.order_review = true; | |
| 13 | 15 | this.$form = $('form#order_review'); |
| 14 | 16 | this.$form.on( |
| 15 | 17 | 'submit', |
| 16 | 18 | this.onSubmit |
| @@ -17,8 +19,13 @@ | ||
| 17 | 19 | ) |
| 18 | 20 | } |
| 19 | 21 | }, |
| 20 | 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; | |
| 26 | + } | |
| 27 | + | |
| 21 | 28 | if (!payplug_checkout.isPayplugChosen()) { |
| 22 | 29 | return; |
| 23 | 30 | } |
| 24 | 31 | // Use standard checkout process if a payment token has been |
| @@ -28,10 +35,10 @@ | ||
| 28 | 35 | //Prevent submit and stop all other listeners from being triggered. |
| 29 | 36 | e.preventDefault(); |
| 30 | 37 | e.stopImmediatePropagation(); |
| 31 | 38 | $.post( |
| 32 | - payplug_checkout_params.ajax_url, | |
| 33 | - payplug_checkout.$form.serialize() | |
| 39 | + request_url, | |
| 40 | + payplug_checkout.$form.serialize() + "&payplug_non_blocks=true" | |
| 34 | 41 | ).done(function (response) { |
| 35 | 42 | if (response.result === "failure") { |
| 36 | 43 | payplug_checkout.$form.unblock(); |
| 37 | 44 | var error_messages = response.messages || ''; |
| @@ -36,10 +43,10 @@ | ||
| 36 | 43 | payplug_checkout.$form.unblock(); |
| 37 | 44 | var error_messages = response.messages || ''; |
| 38 | 45 | payplug_checkout.submit_error(error_messages); |
| 39 | 46 | return; |
| 40 | - } | |
| 41 | - | |
| 47 | + } | |
| 48 | + | |
| 42 | 49 | if(response.is_paid) { |
| 43 | 50 | document.location.href = response.redirect; |
| 44 | 51 | return; |
| 45 | 52 | } |
| @@ -54,10 +61,10 @@ | ||
| 54 | 61 | e.preventDefault(); |
| 55 | 62 | e.stopImmediatePropagation(); |
| 56 | 63 | payplug_checkout.$form.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } }); |
| 57 | 64 | $.post( |
| 58 | - payplug_checkout_params.ajax_url, | |
| 59 | - payplug_checkout.$form.serialize() | |
| 65 | + request_url, | |
| 66 | + payplug_checkout.$form.serialize() + "&payplug_non_blocks=true" | |
| 60 | 67 | ).done(payplug_checkout.openModal); |
| 61 | 68 | }, |
| 62 | 69 | openModal: function (response) { |
| 63 | 70 | payplug_checkout.$form.unblock(); |
| @@ -70,9 +77,9 @@ | ||
| 70 | 77 | window.redirection_url = response.cancel || false; |
| 71 | 78 | Payplug.showPayment(response.redirect); |
| 72 | 79 | }, |
| 73 | 80 | isPayplugChosen: function () { |
| 74 | - return $('#payment_method_payplug').is(':checked'); | |
| 81 | + return ($('#payment_method_payplug').is(':checked') || $('#payment_method_american_express').is(':checked')); | |
| 75 | 82 | }, |
| 76 | 83 | isPaymentTokenSelected: function () { |
| 77 | 84 | var token = $('input[name=wc-payplug-payment-token]:checked'); |
| 78 | 85 | return token.length > 0 && 'new' !== token.val(); |