1(()=>{"use strict";const e=(e,t)=>{let o;return function(...n){const i=this;clearTimeout(o),t&&!o&&e.apply(i,n),o=setTimeout(()=>{o=null,t||e.apply(i,n)},250)}},t=e=>Math.round(100*e)/100;function o(e,t){return e&&e.responseJSON&&"string"==typeof e.responseJSON.message?e.responseJSON.message:t}class n{constructor(){this.api_namespace="WC_Gateway_Buckaroo_googlepay",this.url=buckaroo_global.ajax_url,void 0===this.url&&(this.url="/")}getItems(e){if(jQuery(".googlepay-button-container").hasClass("is-detail-page")){const n=this.getCurrentShownProduct(),i={"wc-api":`${this.api_namespace}-get-items-from-detail-page`,...n,country_code:e};let r=[],a=null;if(jQuery.ajax({url:this.url,data:i,async:!1,dataType:"json"}).done(e=>{r=e.map(e=>({id:e.id,name:e.name,price:t(e.price),quantity:e.quantity,type:e.type,attributes:e.attributes}))}).fail(e=>{a=o(e,"Unable to calculate Google Pay cart.")}),a)throw new Error(a);return r}let n=[],i=null;if(jQuery.ajax({url:this.url,data:{"wc-api":`${this.api_namespace}-get-items-from-cart`},async:!1,dataType:"json"}).done(e=>{n=e.map(e=>({id:e.id,name:e.name,price:t(e.price),quantity:e.quantity,type:e.type,attributes:e.attributes}))}).fail(e=>{i=o(e,"Unable to load the WooCommerce cart.")}),i)throw new Error(i);return n}getShippingMethods(e){const t=(()=>jQuery(".googlepay-button-container").hasClass("is-detail-page")?this.getCurrentShownProduct():{})(),n={"wc-api":`${this.api_namespace}-get-shipping-methods`,country_code:e};let i,r=null;if(jQuery.ajax({url:this.url,data:Object.assign(n,t),dataType:"json",async:!1}).done(e=>{i=e}).fail(e=>{r=o(e,"Unable to calculate Google Pay shipping.")}),r)throw new Error(r);return i}getCartTotal(){let e=null,t=null;if(jQuery.ajax({url:this.url,data:{"wc-api":`${this.api_namespace}-get-cart-total`},async:!1,dataType:"json"}).done(t=>{e=t}).fail(e=>{t=o(e,"Unable to calculate Google Pay cart.")}),t)throw new Error(t);return e}getStoreInformation(){let e=[];return jQuery.ajax({url:this.url,data:{"wc-api":`${this.api_namespace}-get-shop-information`},async:!1,dataType:"json"}).done(t=>{e=t}),e}getCurrentShownProduct(){return function(e){const t=e('[name="add-to-cart"]').val(),o=e('[name="variation_id"]'),n=o.length?o.val():0,i=n&&0!=n?n:t,r={};return e('form.cart [name^="attribute_"]').each(function(){const t=e(this),o=t.attr("name"),n=t.val();o&&null!=n&&""!==n&&(r[o]=n)}),{product_id:t,variation_id:i,quantity:e(".cart .quantity input").val()||1,attributes:r}}(jQuery)}displayErrorMessage(e){jQuery(".buckaroo-googlepay-error").remove();const t=`\n <div class="woocommerce-error buckaroo-googlepay-error" role="alert">\n ${e}\n </div>\n `;jQuery(".woocommerce-notices-wrapper").first().prepend(t),jQuery("html, body").scrollTop(0)}canOrderAmount(){if(jQuery(".checkout.woocommerce-checkout").length)return!0;const e=parseInt(jQuery(".cart .quantity input.qty").val()),t=parseInt(jQuery(".cart .quantity input.qty").attr("max"));return isNaN(t)?e>0:e>0&&e<=t}}class i{constructor(){this.woocommerce=new n}createTransaction(e,t,o,n){jQuery.ajax({url:"/?wc-api=WC_Gateway_Buckaroo_googlepay-create-transaction",method:"post",data:{selected_shipping_method:o,paymentData:e,amount:t,items:n},dataType:"json",async:!1}).done(e=>{if("success"==e.result)window.location.replace(e.redirect);else{let t="Something went wrong while processing your payment.";e.message&&(t=e.message),this.woocommerce.displayErrorMessage(t)}}).fail(()=>{this.woocommerce.displayErrorMessage("Something went wrong while processing your payment.")})}}
1class r{constructor(e={}){this.buckaroo=new i,this.woocommerce=new n,this.store_info=this.woocommerce.getStoreInformation(),this.selected_shipping_method=null,this.selected_shipping_amount=null,this.total_price=null,this.country_code=this.store_info.country_code,this.isOnCheckout=!0===e.isOnCheckout,this.onAuthorized="function"==typeof e.onAuthorized?e.onAuthorized:null,this.containerSelector=e.containerSelector||".googlepay-button-container",this.buttonElementId=e.buttonElementId||"googlepay-button-element",this.payment=null,this.googlePayScriptLoading=!1,this.selectionRequired=!1,this.selectionGuardBound=!1}rebuild(){const e=document.getElementById(this.buttonElementId);if(e)for(;e.firstChild;)e.removeChild(e.firstChild);else jQuery(`${this.containerSelector} div`).remove(),jQuery(this.containerSelector).append(`<div id="${this.buttonElementId}">`);this.isOnCheckout&&jQuery(`#${this.buttonElementId}`).hide()}init(){try{this.setupPayment()}catch(e){return this.woocommerce.displayErrorMessage(e.message||"Unable to initialize Google Pay."),!1}return this.initiatePayment(),!0}setupPayment(){const e=this.getItems(),o=this.isOnCheckout?[]:this.woocommerce.getShippingMethods(this.country_code);let n,i=e;if(this.isOnCheckout){const e=this.woocommerce.getCartTotal();n=e&&"number"==typeof e.total&&e.total>0?t(e.total):this.sumTotalAmount(i)}else{const t=this.getFirstShippingItem(o);i=null!==t?[].concat(e,t):e,n=this.sumTotalAmount(i)}o.length>0&&(this.selected_shipping_method=o[0].identifier,this.selected_shipping_amount=o[0].amount),this.total_price=n,this.selectionRequired=!1,jQuery(".buckaroo-googlepay-error").remove(),this.createPayment(n,o)}initForIncompleteProduct(){return this.total_price=0,this.selectionRequired=!0,this.bindSelectionGuard(),this.createPayment("0.00",[]),this.initiatePayment(),!0}createPayment(e,t){const o=this.createPaymentOptions(e,t),n=new BuckarooSdk.GooglePay.GooglePayPayment(o);this.payment=n,this.isOnCheckout||this.requireContactDetails(this.payment)}initiatePayment(){if(window.google?.payments?.api&&"function"==typeof this.payment.onGooglePayLoaded)return void this.payment.onGooglePayLoaded();if(this.googlePayScriptLoading)return;this.googlePayScriptLoading=!0;const e=this.payment,t=e.onGooglePayLoaded.bind(e);e.onGooglePayLoaded=()=>{this.googlePayScriptLoading=!1,this.payment===e?t():this.payment.onGooglePayLoaded()},e.initiate()}createPaymentOptions(e,t){const o=t&&t.length>0,n=o?t.map(e=>({id:e.identifier,label:e.label,description:""})):[],i={environment:"live"===this.store_info.mode?"PRODUCTION":"TEST",buttonColor:"white"===(this.store_info.button_style||"black")?"white":"black",buttonType:"pay",buttonSizeMode:"fill",buttonContainerId:this.buttonElementId,buttonLocale:this.store_info.locale||"en",totalPriceStatus:this.isOnCheckout?"FINAL":"ESTIMATED",totalPrice:String(e),currencyCode:this.store_info.currency_code,countryCode:this.store_info.country_code,merchantName:this.store_info.store_name,merchantId:this.store_info.google_merchant_id||"",merchantOrigin:window.location.hostname,gatewayMerchantId:this.store_info.merchant_id,shippingAddressRequired:!this.isOnCheckout,shippingOptionRequired:o,onGooglePayLoadError:e=>{console.error("Error loading GooglePay:",e)},processPayment:e=>this.processGooglepayCallback(e)};return o&&(i.shippingOptionParameters={shippingOptions:n,defaultSelectedOptionId:n[0].id}),(i.shippingAddressRequired||i.shippingOptionRequired)&&(i.onPaymentDataChanged=e=>this.onPaymentDataChanged(e)),i}bindSelectionGuard(){if(this.selectionGuardBound)return;const e=document.querySelector(this.containerSelector);e&&(e.addEventListener("click",e=>{if(!this.selectionRequired||!e.target.closest("button"))return;e.preventDefault(),e.stopImmediatePropagation();const t=window.wc_add_to_cart_variation_params?.i18n_make_a_selection_text||"Please choose product options before using Google Pay.";this.woocommerce.displayErrorMessage(t)},!0),this.selectionGuardBound=!0)}requireContactDetails(e){if(!e||"function"!=typeof e.getBaseRequest)return;const t=e.getBaseRequest.bind(e);e.getBaseRequest=()=>{const e=t();return{...e,emailRequired:!0,allowedPaymentMethods:(e.allowedPaymentMethods||[]).map(e=>({...e,parameters:{...e.parameters,billingAddressRequired:!0,billingAddressParameters:{format:"FULL",phoneNumberRequired:!0}}}))}}}triggerPayment(){try{this.setupPayment()}catch(e){return!1}if(!this.payment||"function"!=typeof this.payment.onGooglePaymentButtonClicked)return!1;try{this.payment.onGooglePaymentButtonClicked()}catch(e){return!1}return!0}onPaymentDataChanged(e){try{const o=e.shippingAddress?.countryCode||this.country_code;this.country_code=o;const n=this.woocommerce.getShippingMethods(o),i=this.getItems();if(!n||!Array.isArray(n)||0===n.length)return Promise.resolve({newTransactionInfo:{totalPriceStatus:"FINAL",totalPrice:String(this.total_price),currencyCode:this.store_info.currency_code,countryCode:this.store_info.country_code},error:{reason:"SHIPPING_ADDRESS_UNSERVICEABLE",message:"Cannot ship to this address",intent:"SHIPPING_ADDRESS"}});const r=n.map(e=>({id:e.identifier,label:e.label,description:""}));if(e.shippingOptionData?.id){const t=n.find(t=>
1t.identifier===e.shippingOptionData.id);t&&(this.selected_shipping_method=t.identifier,this.selected_shipping_amount=t.amount)}else n.length>0&&(this.selected_shipping_method=n[0].identifier,this.selected_shipping_amount=n[0].amount);const a=this.selected_shipping_amount||0,s=i.reduce((e,t)=>e+t.amount,0),c=t(s+a);return this.total_price=c,Promise.resolve({newTransactionInfo:{totalPriceStatus:"FINAL",totalPrice:String(c),currencyCode:this.store_info.currency_code,countryCode:this.store_info.country_code},newShippingOptionParameters:{shippingOptions:r,defaultSelectedOptionId:this.selected_shipping_method||r[0].id}})}catch(e){return console.error("Error in onPaymentDataChanged:",e),Promise.resolve({newTransactionInfo:{totalPriceStatus:"FINAL",totalPrice:String(this.total_price),currencyCode:this.store_info.currency_code,countryCode:this.store_info.country_code},error:{reason:"SHIPPING_ADDRESS_UNSERVICEABLE",message:"Cannot ship to this address",intent:"SHIPPING_ADDRESS"}})}}processGooglepayCallback(e){const t=e.email||"",o=e.paymentMethodData.info?.billingAddress||{},n=e.shippingAddress||{},i=Object.keys(o).length>0?o:n,r=Object.keys(n).length>0?n:o,a={token:e.paymentMethodData.tokenizationData.token,billingContact:this.mapGoogleContact(i,t),shippingContact:this.mapGoogleContact(r,t)};return this.isOnCheckout?(this.onAuthorized&&this.onAuthorized(a),Promise.resolve({success:!0})):(this.buckaroo.createTransaction(a,this.total_price,this.selected_shipping_method,this.woocommerce.getItems(this.country_code)),Promise.resolve({}))}mapGoogleContact(e,t){const o=[e.address1||"",e.address2||"",e.address3||""].filter(Boolean);return{givenName:e.name?e.name.split(" ")[0]:"",familyName:e.name?e.name.split(" ").slice(1).join(" "):"",emailAddress:t||"",phoneNumber:e.phoneNumber||"",addressLines:o.length>0?o:[""],locality:e.locality||"",administrativeArea:e.administrativeArea||"",postalCode:e.postalCode||"",countryCode:e.countryCode||""}}sumTotalAmount(e){const o=e.reduce((e,t)=>e+t.amount,0);return t(o)}getFirstShippingItem(e){return e.length>0?{type:"final",label:e[0].label,amount:e[0].amount||0,qty:1}:null}getItems(){return this.woocommerce.getItems(this.country_code).map(e=>{return{type:"final",label:(o=`${e.quantity} x ${e.name}`,o.length>25?`${o.slice(0,25)}...`:o),amount:t(e.price),qty:e.quantity};var o})}}window.BuckarooGooglePay={create:e=>new r(e)},window.BuckarooInitGooglePay=function(){if("undefined"==typeof jQuery)return void console.error("Cannot initialize GooglePay missing jquery");const e=new r,t=function(e){if(void 0!==e)return function(){e.rebuild(),e.init()}}(e);t&&(e.rebuild(),e.init(),document.removeEventListener("googlepayRefresh",t),document.addEventListener("googlepayRefresh",t))},jQuery(()=>{if(!document.querySelector(".wc-block-checkout")&&!document.querySelector(".wp-block-woocommerce-checkout")&&jQuery(".googlepay-button-container")[0]){const t=new r,o=new n,i=e(()=>{t.rebuild(),o.canOrderAmount()&&t.init()});0===jQuery(".variations_form").length?(i(),jQuery(".cart .quantity input").change(()=>{i()})):(t.rebuild(),t.initForIncompleteProduct()),jQuery(".variations_form").on("show_variation",()=>{i(),jQuery(".cart .quantity input").change(()=>{i()})}),jQuery(".variations_form").on("hide_variation",()=>{t.rebuild(),t.initForIncompleteProduct()}),jQuery(document.body).on("wc_fragments_refreshed",()=>{i()}),jQuery(document.body).on("updated_shipping_method",()=>{t.rebuild(),t.init()})}})})();
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.