diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index c7e79bf..6cf657a 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -5,8 +5,8 @@ name: Prerelease on: push: branches: - - beta - - alpha + # - beta + # - alpha jobs: calculate-next-version: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37471ba..f72fa5c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,7 @@ name: Release to WordPress plugin repository on: push: branches: - - main + # - main pause for now jobs: calculate-next-version: runs-on: ubuntu-latest @@ -80,4 +80,4 @@ jobs: tag_name: v${{ needs.calculate-next-version.outputs.new-release-version }} files: ./${{ github.event.repository.name }}.zip env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index cb7df56..6d06199 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # macOS crap .DS_Store +# ignore minified output +build + # ignore everything in the root except the "wp-content" directory. !wp-content/ diff --git a/assets/scss/ledyer-checkout-for-woocommerce.scss b/assets/scss/ledyer-checkout-for-woocommerce.scss new file mode 100644 index 0000000..6ca4063 --- /dev/null +++ b/assets/scss/ledyer-checkout-for-woocommerce.scss @@ -0,0 +1,15 @@ +#lco-wrapper { + display: flex; + flex-direction: column; + align-items: center; + + #lco-order-review, + #lco-iframe { + width: 100%; + } + + #lco-iframe { + display: flex; + justify-content: center; + } +} diff --git a/build/ledyer-checkout-for-woocommerce.asset.php b/build/ledyer-checkout-for-woocommerce.asset.php deleted file mode 100644 index 18a82fe..0000000 --- a/build/ledyer-checkout-for-woocommerce.asset.php +++ /dev/null @@ -1 +0,0 @@ - array('wp-polyfill'), 'version' => 'c69ba218ff4aa2bc4342d0e94e81c920'); \ No newline at end of file diff --git a/build/ledyer-checkout-for-woocommerce.css b/build/ledyer-checkout-for-woocommerce.css deleted file mode 100644 index 34b19b1..0000000 --- a/build/ledyer-checkout-for-woocommerce.css +++ /dev/null @@ -1 +0,0 @@ -#lco-wrapper{display:flex;flex-direction:column;align-items:center}#lco-order-review,#lco-iframe{width:100%}#lco-iframe{display:flex;justify-content:center} diff --git a/build/ledyer-checkout-for-woocommerce.css.map b/build/ledyer-checkout-for-woocommerce.css.map deleted file mode 100644 index d14c010..0000000 --- a/build/ledyer-checkout-for-woocommerce.css.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["webpack:///ledyer-checkout-for-woocommerce.scss"],"names":[],"mappings":"AAAA;EACE,aAAa;EACb,sBAAsB;EACtB,mBAAmB;AACrB;;AAEA;;EAEE,WAAW;AACb;;AAEA;EACE,aAAa;EACb,uBAAuB;AACzB,C","file":"ledyer-checkout-for-woocommerce.css","sourcesContent":["#lco-wrapper {\n display: flex;\n flex-direction: column;\n align-items: center;\n}\n\n#lco-order-review,\n#lco-iframe {\n width: 100%;\n}\n\n#lco-iframe {\n display: flex;\n justify-content: center;\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/build/ledyer-checkout-for-woocommerce.js b/build/ledyer-checkout-for-woocommerce.js deleted file mode 100644 index cacedaa..0000000 --- a/build/ledyer-checkout-for-woocommerce.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){var i={};function n(o){if(i[o])return i[o].exports;var r=i[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=i,n.d=function(e,i,o){n.o(e,i)||Object.defineProperty(e,i,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,i){if(1&i&&(e=n(e)),8&i)return e;if(4&i&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&i&&"string"!=typeof e)for(var r in e)n.d(o,r,function(i){return e[i]}.bind(null,r));return o},n.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(i,"a",i),i},n.o=function(e,i){return Object.prototype.hasOwnProperty.call(e,i)},n.p="/content/plugins/ledyer-checkout-for-woocommerce/build/",n(n.s=0)}([function(e,n){jQuery((function(e){if("undefined"==typeof lco_params)return!1;var n={bodyEl:e("body"),checkoutFormSelector:e("form.checkout"),paymentMethodEl:e('input[name="payment_method"]'),paymentMethod:"",selectAnotherSelector:"#ledyer-checkout-select-other",shippingUpdated:!1,blocked:!1,preventPaymentMethodChange:!1,timeout:null,interval:null,ledyerUpdateNeeded:!1,shippingEmailExists:!1,shippingPhoneExists:!1,shippingFirstNameExists:!1,shippingLastNameExists:!1,documentReady:function(){01&&document.querySelector("#order_comments_field").remove(),e(".woocommerce-additional-fields").appendTo("#lco-extra-checkout-fields");var o=e('form[name="checkout"] input, form[name="checkout"] select, textarea'),r=!1;for(i=0;i0&&void 0!==arguments[0]?arguments[0]:"Kunde inte slutföra ordern. Var god försök igen. Om problemet kvarstår, vänligen kontakta kundsupport.",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;window.ledyer.api.clientValidation({shouldProceed:!1,message:{title:null,body:i}});var o=lco_params.pay_for_order?"div.woocommerce-notices-wrapper":"form.checkout";e("body").trigger("update_checkout");var r=null!=n?n:i,t='
'.concat(r,"
");e(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),e(o).prepend('
'.concat(t,"
")),e(o).removeClass("processing").unblock(),e(o).find(".input-text, select, input:checkbox").trigger("validate").blur(),e(document.body).trigger("checkout_error",[r]),e("html, body").animate({scrollTop:e(o).offset().top-100},1e3)},cleanupForm:function(i){return i.find("input, select, textarea").filter((function(){return""!==e(this).val()})).serialize()},placeLedyerOrder:function(){var i=arguments.length>0&&void 0!==arguments[0]&&arguments[0];n.blocked=!0,n.getLedyerOrder().done((function(o){o.success?(e(".woocommerce-checkout-review-order-table").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),sessionStorage.removeItem("ledyerWooRedirectUrl"),e.ajax({type:"POST",url:lco_params.submit_order,data:n.cleanupForm(e("form.checkout")),dataType:"json",success:function(e){try{if("success"!==e.result)throw"Result failed";n.logToFile("Successfully created order in WooCommerce.");var o=new URL(e.redirect);if(sessionStorage.setItem("ledyerWooRedirectUrl",o),i)return void window.ledyer.api.clientValidation({shouldProceed:!0});window.location.href=o.toString()}catch(i){e.messages?(n.logToFile("Checkout error | "+e.messages),n.failOrder("Vänligen kontrollera att alla uppgifter är korrekt ifyllda.",e.messages)):(n.logToFile("Checkout error | No message"+i),n.failOrder())}},error:function(e){try{n.logToFile("AJAX error | "+JSON.stringify(e))}catch(e){n.logToFile("AJAX error | Failed to parse error message.")}n.failOrder()}})):(n.logToFile("Failed to get the order from Ledyer."),n.failOrder())}))},init:function(){e(document).ready(n.documentReady),0 1) {\n document.querySelector(\"#order_comments_field\").remove();\n }\n\n\n // Move order comments.\n $('.woocommerce-additional-fields').appendTo('#lco-extra-checkout-fields');\n var form = $('form[name=\"checkout\"] input, form[name=\"checkout\"] select, textarea');\n var checkout_add_ons_moved = false;\n for (i = 0; i < form.length; i++) {\n var name = form[i].name.replace('[]', '\\\\[\\\\]'); // Escape any empty \"array\" keys to prevent errors.\n // Check if field is inside the order review.\n if ($('table.woocommerce-checkout-review-order-table').find(form[i]).length) {\n continue;\n }\n\n // Check if this is a standard field.\n if (-1 === $.inArray(name, lco_params.standard_woo_checkout_fields)) {\n // This is not a standard Woo field, move to our div.\n if ('wc_checkout_add_ons' === $('p#' + name + '_field').parent().attr('id')) { // Check if this is an add on field.\n if (!checkout_add_ons_moved) {\n checkout_add_ons_moved = true;\n $('div#wc_checkout_add_ons').appendTo('#lco-extra-checkout-fields');\n }\n } else if (0 < $('p#' + name + '_field').length) {\n if (name === 'shipping_phone') {\n lco_wc.shippingPhoneExists = true;\n }\n if (name === 'shipping_email') {\n lco_wc.shippingEmailExists = true;\n }\n if (name === 'shipping_first_name') {\n lco_wc.shippingFirstNameExists = true;\n }\n if (name === 'shipping_last_name') {\n lco_wc.shippingLastNameExists = true;\n }\n $('p#' + name + '_field').appendTo('#lco-extra-checkout-fields');\n } else {\n $('input[name=\"' + name + '\"]').closest('p').appendTo('#lco-extra-checkout-fields');\n }\n }\n }\n },\n\n /**\n * Updates the cart in case of a change in product quantity.\n */\n updateCart: function () {\n lco_wc.lcoSuspend(true);\n $.ajax({\n type: 'POST',\n url: lco_params.update_cart_url,\n data: {\n checkout: lco_wc.cleanupForm($('form.checkout')),\n nonce: lco_params.update_cart_nonce\n },\n dataType: 'json',\n success: function (data) {\n },\n error: function (data) {\n },\n complete: function (data) {\n $('body').trigger('update_checkout');\n lco_wc.lcoResume();\n }\n });\n },\n\n /**\n * Gets the Ledyer order and starts the order submission\n */\n getLedyerOrder: function () {\n lco_wc.preventPaymentMethodChange = true;\n $('.woocommerce-checkout-review-order-table').block({\n message: null,\n overlayCSS: {\n background: '#fff',\n opacity: 0.6\n }\n });\n\n var ajax = $.ajax({\n type: 'POST',\n url: lco_params.get_ledyer_order_url,\n data: {\n nonce: lco_params.get_ledyer_order_nonce\n },\n dataType: 'json',\n success: function (data) {\n lco_wc.setCustomerData(data.data);\n\n // Check Terms checkbox, if it exists.\n if (0 < $('form.checkout #terms').length) {\n $('form.checkout #terms').prop('checked', true);\n }\n },\n error: function (data) {\n\n },\n complete: function (data) {\n }\n });\n\n return ajax;\n },\n\n\n /**\n * Sets the customer data.\n * @param {array} data\n */\n setCustomerData: function (data) {\n if ('billing_address' in data && data.billing_address !== null) {\n // Billing fields.\n 'billing_first_name' in data.billing_address ? $('#billing_first_name').val(data.billing_address.billing_first_name) : '';\n 'billing_last_name' in data.billing_address ? $('#billing_last_name').val(data.billing_address.billing_last_name) : '';\n 'billing_company' in data.billing_address ? $('#billing_company').val(data.billing_address.billing_company) : '';\n 'billing_address_1' in data.billing_address ? $('#billing_address_1').val(data.billing_address.billing_address_1) : '';\n 'billing_address_2' in data.billing_address ? $('#billing_address_2').val(data.billing_address.billing_address_2) : '';\n 'billing_city' in data.billing_address ? $('#billing_city').val(data.billing_address.billing_city) : '';\n 'billing_postcode' in data.billing_address ? $('#billing_postcode').val(data.billing_address.billing_postcode) : '';\n 'billing_phone' in data.billing_address ? $('#billing_phone').val(data.billing_address.billing_phone) : '';\n 'billing_email' in data.billing_address ? $('#billing_email').val(data.billing_address.billing_email) : '';\n 'billing_country' in data.billing_address ? $('#billing_country').val(data.billing_address.billing_country.toUpperCase()) : '';\n 'billing_state' in data.billing_address ? $('#billing_state').val(data.billing_address.billing_state) : '';\n // Trigger changes\n $('#billing_email').change();\n $('#billing_email').blur();\n }\n\n if ('shipping_address' in data && data.shipping_address !== null) {\n $('#ship-to-different-address-checkbox').prop('checked', true);\n\n // Shipping fields.\n 'shipping_first_name' in data.shipping_address ? $('#shipping_first_name').val(data.shipping_address.shipping_first_name) : '';\n 'shipping_last_name' in data.shipping_address ? $('#shipping_last_name').val(data.shipping_address.shipping_last_name) : '';\n 'shipping_company' in data.shipping_address ? $('#shipping_company').val(data.shipping_address.shipping_company) : '';\n 'shipping_address_1' in data.shipping_address ? $('#shipping_address_1').val(data.shipping_address.shipping_address_1) : '';\n 'shipping_address_2' in data.shipping_address ? $('#shipping_address_2').val(data.shipping_address.shipping_address_2) : '';\n 'shipping_city' in data.shipping_address ? $('#shipping_city').val(data.shipping_address.shipping_city) : '';\n 'shipping_postcode' in data.shipping_address ? $('#shipping_postcode').val(data.shipping_address.shipping_postcode) : '';\n 'shipping_country' in data.shipping_address ? $('#shipping_country').val(data.shipping_address.shipping_country.toUpperCase()) : '';\n 'shipping_state' in data.shipping_address ? $('#shipping_state').val(data.shipping_address.shipping_state) : '';\n\n // extra shipping fields (email, phone, name).\n if (lco_wc.shippingEmailExists === true && $('#shipping_email')) {\n $('#shipping_email').val((('shipping_email' in data.shipping_address) ? data.shipping_address.shipping_email : ''));\n }\n if (lco_wc.shippingPhoneExists === true && $('#shipping_phone')) {\n $('#shipping_phone').val((('shipping_phone' in data.shipping_address) ? data.shipping_address.shipping_phone : ''));\n }\n if (lco_wc.shippingFirstNameExists === true && $('#shipping_first_name')) {\n $('#shipping_first_name').val((('shipping_first_name' in data.shipping_address) ? data.shipping_address.shipping_first_name : ''));\n }\n if (lco_wc.shippingLastNameExists === true && $('#shipping_last_name')) {\n $('#shipping_last_name').val((('shipping_last_name' in data.shipping_address) ? data.shipping_address.shipping_last_name : ''));\n }\n }\n },\n\n /**\n * Logs the message to the ledyer checkout log in WooCommerce.\n * @param {string} message\n */\n logToFile: function (message) {\n $.ajax(\n {\n url: lco_params.log_to_file_url,\n type: 'POST',\n dataType: 'json',\n data: {\n message: message,\n nonce: lco_params.log_to_file_nonce\n }\n }\n );\n },\n\n /**\n * Logs messages to the console.\n * @param {string} message\n */\n log: function (message) {\n if (lco_params.logging) {\n console.log(message);\n }\n },\n\n /**\n * Fails the Ledyer order.\n * @param {string} error_message\n */\n failOrder: function (error_message = \"Kunde inte slutföra ordern. Var god försök igen. Om problemet kvarstår, vänligen kontakta kundsupport.\", alert = null) {\n window.ledyer.api.clientValidation({\n shouldProceed: false,\n message: {\n title: null, // Use default title in Ledyer checkout\n body: error_message\n }\n })\n\n const className = lco_params.pay_for_order ? 'div.woocommerce-notices-wrapper' : 'form.checkout';\n\n // Update the checkout and reenable the form.\n $('body').trigger('update_checkout');\n\n const alert_message = alert ?? error_message;\n const error_div = `
${alert_message}
`;\n\n // Print error messages, and trigger checkout_error, and scroll to notices.\n $('.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message').remove();\n $(className).prepend(`
${error_div}
`);\n $(className).removeClass('processing').unblock();\n $(className).find('.input-text, select, input:checkbox').trigger('validate').blur();\n $(document.body).trigger('checkout_error', [alert_message]);\n $('html, body').animate({\n scrollTop: ($(className).offset().top - 100)\n }, 1000);\n },\n\n cleanupForm: function (formElement) {\n const $inputs = formElement.find('input, select, textarea');\n // remove inputs with empty values\n const $inputsWithValue = $inputs.filter(function() {\n return $(this).val() !== \"\";\n });\n const serializedData = $inputsWithValue.serialize();\n\n return serializedData;\n },\n\n /**\n * Places the Ledyer order\n * @param {string} should_validate\n */\n placeLedyerOrder: function (should_validate = false) {\n lco_wc.blocked = true;\n lco_wc.getLedyerOrder().done(function (response) {\n if (response.success) {\n $('.woocommerce-checkout-review-order-table').block({\n message: null,\n overlayCSS: {\n background: '#fff',\n opacity: 0.6\n }\n });\n\n sessionStorage.removeItem('ledyerWooRedirectUrl');\n\n $.ajax({\n type: 'POST',\n url: lco_params.submit_order,\n data: lco_wc.cleanupForm($('form.checkout')),\n dataType: 'json',\n success: function (data) {\n // data is an object with the following properties:\n // { result: \"success\" | \"failure\"; refresh: \"boolean\", reload: boolean, messages: string; }\n try {\n if ('success' === data.result) {\n lco_wc.logToFile('Successfully created order in WooCommerce.');\n const url = new URL(data.redirect);\n sessionStorage.setItem('ledyerWooRedirectUrl', url);\n\n if (should_validate) {\n window.ledyer.api.clientValidation({\n shouldProceed: true\n })\n // Ledyer will respond with a new event when order is complete\n // So don't redirect just yet,\n // eventually redirection will happen in ledyerCheckoutOrderComplete\n return;\n }\n window.location.href = url.toString();\n } else {\n throw 'Result failed';\n }\n } catch (err) {\n if (data.messages) {\n lco_wc.logToFile('Checkout error | ' + data.messages);\n lco_wc.failOrder(\"Vänligen kontrollera att alla uppgifter är korrekt ifyllda.\", data.messages);\n } else {\n lco_wc.logToFile('Checkout error | No message' + err);\n lco_wc.failOrder();\n }\n }\n },\n error: function (data) {\n try {\n lco_wc.logToFile('AJAX error | ' + JSON.stringify(data));\n } catch (e) {\n lco_wc.logToFile('AJAX error | Failed to parse error message.');\n }\n lco_wc.failOrder();\n }\n });\n } else {\n lco_wc.logToFile('Failed to get the order from Ledyer.');\n lco_wc.failOrder();\n }\n });\n },\n\n /**\n * Initiates the script.\n */\n init: function () {\n $(document).ready(lco_wc.documentReady);\n\n if (0 < $('form.checkout #terms').length) {\n $('form.checkout #terms').prop('checked', true);\n }\n\n lco_wc.bodyEl.on('update_checkout', lco_wc.lcoSuspend);\n lco_wc.bodyEl.on('updated_checkout', lco_wc.lcoResume);\n lco_wc.bodyEl.on('change', 'input.qty', lco_wc.updateCart);\n lco_wc.bodyEl.on('change', 'input[name=\"payment_method\"]', lco_wc.maybeChangeToLco);\n lco_wc.bodyEl.on('click', lco_wc.selectAnotherSelector, lco_wc.changeFromLco);\n\n $(document).on('ledyerCheckoutOrderComplete', function (event) {\n lco_wc.logToFile('ledyerCheckoutOrderComplete from Ledyer triggered');\n if (!lco_params.pay_for_order) {\n const redirectUrl = sessionStorage.getItem( 'ledyerWooRedirectUrl' );\n if (redirectUrl) {\n // This means that placeLedyerOrder was called successfully already\n // (Due to an earlier call caused by client validation)\n window.location.href = redirectUrl;\n }\n }\n });\n\n $(document).on('ledyerCheckoutOrderPending', function (event) {\n lco_wc.logToFile('ledyerCheckoutOrderPending from Ledyer triggered');\n if (!lco_params.pay_for_order) {\n lco_wc.placeLedyerOrder();\n }\n });\n\n $(document).on('ledyerCheckoutWaitingForClientValidation', function (event) {\n lco_wc.logToFile('ledyerCheckoutWaitingForClientValidation from Ledyer triggered');\n\n if (lco_params.pay_for_order) {\n window.ledyer.api.clientValidation({\n shouldProceed: true\n })\n } else {\n lco_wc.placeLedyerOrder(true);\n }\n });\n },\n }\n\n lco_wc.init();\n});\n"],"sourceRoot":""} \ No newline at end of file