var ICON_ERROR="icon-cancel-circled",ICON_SPINNER="icon-down-open-mini";defer((function(){if(document.querySelector("#ppbtn")){let e=Promise.resolve();const n=function(n){return e=e.catch((function(){return null})).then((function(){return fetch("/payment/paypal/express/patch-paypal-order",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})})),e};paypal.Buttons({style:{size:"responsive",color:"white",shape:"rect",label:"checkout"},createOrder:async function(e,n){var o="";if("undefined"!=typeof BasketView){if(!await BasketView.checkoutChecks())return;if(await BasketView.saveOptions(),!BasketView.postcodeVerify())return showAlert("icon-cancel-circled",CONST_BASKET_ERROR,"PayPal not available for your postcode!","#FFFFFF",!1);showAlert(ICON_SPINNER,CONST_PAYPAL_SPINNER_CHECKOUT_TITLE,CONST_PAYPAL_SPINNER_CHECKOUT_MESSAGE,"#FFFFFF",!1);try{o="",o+="Delivery Option: "+BasketView.deliveryOption(),"NOM"==BasketView.deliveryOption()&&(o+=" - Nominated Delivery Day: "+BasketView.deliveryTime())}catch(e){console.log(e)}}var t={billing:{title:"",firstName:"PAYPAL",lastName:"EMPTY",company:"",email:"",phone:"",addressLine1:"",addressLine2:"",addressLine3:"",addressLine4:"",postalCode:"",country:"",postcoder:{PostcodeInput:""}},delivery:{id:null,title:"",firstName:"",lastName:"",company:"",email:"",phone:"",mobile:"",addressLine1:"",addressLine2:"",addressLine3:"",addressLine4:"",postalCode:"",country:""},paymentMethod:"PayPal",specialDeliveryInstructions:o};return fetch("/checkout-details",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((function(e){return e.json()})).then((function(e){return n.order.create(e)}))},onShippingAddressChange:(e,o)=>(console.log("[paypal-init] onShippingAddressChange input",e),n({orderID:e.orderID,shippingAddress:e.shippingAddress}).then((async e=>{if(console.log("[paypal-init] patch response status",e.status,e.ok),!e.ok){let n=null;try{n=await e.json()}catch(e){}throw console.log("[paypal-init] patch response error body",n),new Error("shipping_patch_failed")}let n=null;try{n=await e.json()}catch(e){}console.log("[paypal-init] patch response body",n),console.log("[paypal-init] resolve after server patch")})).catch((e=>{throw console.log("[paypal-init] onShippingAddressChange exception",e),e}))),onShippingOptionsChange:(e,n)=>(console.log("[paypal-init] onShippingOptionsChange",e),Promise.resolve()),onError:function(e,n){document.body.classList.remove("noexit")},onCancel:function(e){setTimeout((function(){document.body.classList.remove("noexit"),clicked(document.body)}),1e3)},onApprove:function(e,n){return console.log("onApprove",e),n.order.capture().then((function(n){return console.log("capture",n),showAlert(ICON_SPINNER,CONST_PAYPAL_PROCESSING_TITLE,CONST_PAYPAL_PROCESSING_MESSAGE,"#FFFFFF",!0),fetch("/paypal-transaction-complete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderID:e.orderID})}).then((function(){window.location.href="/payment/confirm?pay=PAYPAL&status=PAID&payment="+e.paymentID}))}))}}).render(document.querySelector("#ppbtn"))}}));