woocommerce-paypal-payments/assets/ppcp-paylater-configurator-js-paylater-configurator.js

1 line
No EOL
1.7 KiB
JavaScript

document.addEventListener("DOMContentLoaded",function(){var e=document.querySelector("#mainform"),n=e.querySelector(".form-table").querySelector("#field-pay_later_messaging_heading"),t=e.querySelector(".woocommerce-save-button"),o=PcpPayLaterConfigurator.publishButtonClassName,r=document.createElement("div");r.innerHTML="<div id='messaging-configurator'></div>";var a=r.firstChild;n.parentNode.insertBefore(a,n.nextSibling);var c=!1;t.addEventListener("click",function(){c||(c=!0,e.querySelector("."+o).click(),t.click(),c=!1)}),fetch(PcpPayLaterConfigurator.ajax.get_config.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"ppc-get-message-config",nonce:PcpPayLaterConfigurator.ajax.get_config.nonce})}).then(function(e){if(!e.ok)throw new Error("HTTP error! Status: ".concat(e.status));return e.json()}).then(function(e){if(e.success){var n=e.data;merchantConfigurators.Messaging({config:n,merchantClientId:PcpPayLaterConfigurator.merchantClientId,partnerClientId:PcpPayLaterConfigurator.partnerClientId,partnerName:"WooCommerce",bnCode:PcpPayLaterConfigurator.bnCode,placements:["cart","checkout","product","shop","home","custom_placement"],styleOverrides:{button:o,header:PcpPayLaterConfigurator.headerClassName,subheader:PcpPayLaterConfigurator.subheaderClassName},onSave:function(e){fetch(PcpPayLaterConfigurator.ajax.save_config.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({nonce:PcpPayLaterConfigurator.ajax.save_config.nonce,config:e})})}})}else console.error("Failed to fetch configuration:",e)}).catch(function(e){console.error("Error fetching configuration:",e)})});