1jQuery(function($) { 2 3 Paddle.Setup({ 4 vendor: parseInt(paddle_data.vendor), 5 // debug:true //uncomment for debug mode 6 }); 7 8 // Can submit from either checkout or order review forms 9 var form = jQuery('form.checkout, form#order_review'); 10 11 // Intercept form button (Bind to click instead of WC trigger to avoid popup) 12 jQuery('form.checkout').on('click', ':submit', function(event) { 13 return !invokeOverlayCheckout(); 14 }); 15 // Intercept submit for order review 16 jQuery('form#order_review').on('submit', function(event) { 17 return !invokeOverlayCheckout(); 18 }); 19 20 // Some customers (Inky) have themes where the button is outside the form 21 jQuery('#checkout_buttons button').on('click', function(event) { 22 jQuery('form#order_review').submit(); 23 return false; // Don't fire the submit event twice if the buttons ARE in the form 24 }); 25 26 // Starts the overlay checkout process (returns false if we can't) 27 function invokeOverlayCheckout() { 28 // Check payment method etc 29 if(isPaddlePaymentMethodSelected()) { 30 // Need to show spinner before standard checkout as we have to spend time getting the pay URL 31 Paddle.Spinner.show(); 32 33 getSignedCheckoutUrlViaAjax(); 34 35 // Make sure we don't submit the form normally 36 return true; 37 } 38 39 // We didn't fire 40 return false; 41 } 42 43 // Gets if the payment method is set to Paddle (in case multiple methods are available) 44 function isPaddlePaymentMethodSelected () { 45 if ($('#payment_method_paddle').is(':checked')) { 46 return true; 47 } 48 } 49 50 // Requests the signed checkout link via the Paddle WC plugin 51 function getSignedCheckoutUrlViaAjax() { 52 jQuery.ajax({ 53 dataType: "json", 54 method: "POST", 55 url: paddle_data.order_url, 56 data: form.serializeArray(), 57 success: function (response) { 58 // WC will send the error contents in a normal request 59 if(response.result == "success") { 60 startPaddleCheckoutOverlay(response.checkout_url, response.email, response.country, response.postcode); 61 } else { 62 handleErrorResponse(response); 63 } 64 }, 65 error: function (jqxhr, status) { 66 // We got a 500 or something if we hit here. Shouldn't normally happen 67 alert("We were unable to process your order, please try again in a few minutes."); 68 } 69 }); 70 }; 71 72 // Starts the Paddle.js overlay once we have the checkout url. 73 function startPaddleCheckoutOverlay(checkoutUrl, emailAddress, country, postCode) { 74 Paddle.Checkout.open({ 75 email: emailAddress, 76 country: country, 77 postcode: postCode, 78 override: checkoutUrl 79 }); 80 }; 81 82 // Shows any errors we encountered 83 function handleErrorResponse(response) { 84 // Note: This error handling code is copied from the woocommerce checkout.js file 85 if (response.reload === 'true') { 86 window.location.reload(); 87 return; 88 } 89 90 // Remove old errors 91 jQuery( '.woocommerce-error, .woocommerce-message' ).remove(); 92 // Add new errors 93 if (response.messages) { 94 form.prepend(response.messages); 95 } 96 97 // Cancel processing 98 form.removeClass('processing').unblock(); 99 100 // Lose focus for all fields 101 form.find('.input-text, select').blur(); 102 103 // Scroll to top 104 jQuery('html, body').animate({ 105 scrollTop: (form.offset().top - 100) 106 }, 1000 ); 107 108 if (response.nonce) { 109 form.find('#_wpnonce').val(response.nonce); 110 } 111 112 // Trigger update in case we need a fresh nonce 113 if (response.refresh === 'true') { 114 jQuery('body').trigger('update_checkout'); 115 } 116 117 // Clear the Paddle spinner manually as we didn't start checkout 118 Paddle.Spinner.hide(); 119 }; 120 121});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.