1var te=n=>{throw TypeError(n)};var F=(n,e,t)=>e.has(n)||te("Cannot "+t);var c=(n,e,t)=>(F(n,e,"read from private field"),t?t.call(n):e.get(n)),g=(n,e,t)=>e.has(n)?te("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),v=(n,e,t,s)=>(F(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),p=(n,e,t)=>(F(n,e,"access private method"),t);import{E as ne,c as we,j as se}from"./esnext-vendor.BDPAaZdq.js";import{fu as D,g as De,G as Oe,fv as x,fw as q,fx as Te,fy as Le,fz as k}from"./hooks-useReplaceShopPayInHistory.C8UL-mAH.js";import{U as Me,E as xe,D as Ne,b as je,O as Ue,a as Fe,R as qe,c as Ve,d as He,i as Be,e as Ye,f as ze,I as Ge,g as We,h as Ke,j as $e,k as Je,l as Qe}from"./ucp-shared.ChHkNq5H.js";import{E as Ze,a as Xe,b as ie,c as et,d as tt,e as nt}from"./embed-deferred.BpEUhGVz.js";import{i as st,a as it}from"./utilities-stable-ref.Dvd2X3ul.js";import{i as rt}from"./helpers-getNormalizedPaymentMethodName.B-mE5wnL.js";import{b as ot,a as at,c as O,s as ut,P as ct}from"./embed-browser.790EZfnB.js";import{B as dt}from"./legacy-client.DBCy-qpv.js";import{g as lt}from"./shared-embed-client-shared.Cdh2Jybq.js";import"./app.D1P6yWfp.js";import"./redemption-promotions.CgqGtCd-.js";import"./graphql-PaymentSessionMutation.BhOnX3QJ.js";import"./checkout-updaters-helpers.BAeH3ddd.js";import"./hooks-useShopPayExternalAppContext.DyGXtar4.js";var m,y,b,A,E,S,u,ce,de,le,C,pe,he,me,fe,ye,H,ge;const N=class N{constructor(e,t){g(this,u);g(this,m);g(this,y);g(this,b);g(this,A);g(this,E);g(this,S);this.version=N.version,v(this,m,e),v(this,S,t),v(this,y,new Me({context:e,toMinorUnits:h,findSelectedInstrument:s=>p(this,u,C).call(this,s)})),v(this,b,new xe({extensions:[c(this,y)],getCheckout:()=>c(this,E).peek()})),v(this,A,ne(()=>{const s=bt(c(this,m),c(this,y));return s?c(this,b).decorateCheckout(s):void 0})),v(this,E,ne(()=>{const s=c(this,A).value;return s&&re(s,c(this,u,ce))}))}get ucpCheckout(){return c(this,E)}get shopCash(){return c(this,y).shopCash}get shopDiscountOffer(){return c(this,y).shopDiscountOffer}isShopDiscountOfferUnsettled(){return c(this,y).isShopDiscountOfferUnsettled()}mapEvent(e){return c(this,b).mapEvent(e,()=>p(this,u,le).call(this,e))}mapResponse(e,t){switch(e){case"ec.ready":return Nt(t)?p(this,u,me).call(this,t):void 0;case"ec.fulfillment.address_change_request":return Ut(t)?Ft(t,c(this,m)):void 0;case"ec.payment.instruments_change_request":return Mt(t)?p(this,u,pe).call(this,t):void 0;case"ec.payment.credential_request":return xt(t)?p(this,u,he).call(this,t):void 0;case"ec.window.open_request":return jt(t)?!0:void 0;default:return}}parseIncomingRequest(e){const t=c(this,b).parseIncomingRequest(e);if(t)return t;switch(e.method){case"ec.submit":return p(this,u,fe).call(this,e);case"ec.update":return p(this,u,ye).call(this,e);default:return{errorResponse:{jsonrpc:"2.0",id:e.id,error:{code:-32601,message:`Unknown method: ${e.method}`}}}}}buildSubmitResponse(e){const t=p(this,u,H).call(this);if(t?.order)return{jsonrpc:"2.0",id:e,result:{checkout:t,...p(this,u,ge).call(this)}}}buildErrorResponse(e,t){if(t instanceof Ze)return{jsonrpc:"2.0",id:e,error:{code:D.INVALID_PARAMS,message:"Checkout not initialized"}};if(t instanceof Xe)return{jsonrpc:"2.0",id:e,error:{code:D.INVALID_PARAMS,message:"Invalid payment instrument credential"}};const s=c(this,b).mapError(t);return s?{jsonrpc:"2.0",id:e,error:{code:s.severity==="recoverable"?s.code:D.INTERNAL,message:s.content,data:{severity:s.severity,...s.code==="submit_blocked"?{reason:s.content}:{}}}}:{jsonrpc:"2.0",id:e,error:{code:D.INTERNAL,message:"Internal error"}}}};m=new WeakMap,y=new WeakMap,b=new WeakMap,A=new WeakMap,E=new WeakMap,S=new WeakMap,u=new WeakSet,ce=function(){return ot({context:c(this,m),targetType:c(this,S)})},de=function(){return at({context:c(this,m),targetType:c(this,S)})},le=function(e){const t=c(this,E).peek();switch(e.type){case"checkout.ready":return t?{jsonrpc:"2.0",method:"ec.ready",id:O(),params:{delegate:Array.from(c(this,m).embed.delegations.allowed)}}:void 0;case"checkout.start":return t?{jsonrpc:"2.0",method:"ec.start",params:{checkout:t}}:void 0;case"checkout.error":{if(!t)return;const s={type:"error",code:e.code?.toLowerCase()??"unknown_error",content:e.message??"",content_type:"plain",severity:e.severity??"requires_buyer_input",path:e.path};return{jsonrpc:"2.0",method:"ec.messages.change",params:{checkout:{...t,messages:[...t.messages??[],s]}}}}case"checkout.addressChangeStart":return t?{jsonrpc:"2.0",id:O(),method:"ec.fulfillment.address_change_request",params:{checkout:t}}:void 0;case"checkout.paymentMethodChangeStart":return t?{jsonrpc:"2.0",id:O(),method:"ec.payment.instruments_change_request",params:{checkout:t}}:void 0;case"checkout.submitStart":return t?{jsonrpc:"2.0",id:O(),method:"ec.payment.credential_request",params:{checkout:t}}:void 0;case"checkout.windowOpen":return{jsonrpc:"2.0",id:O(),method:"ec.window.open_request",params:{url:e.url}};case"checkout.messagesChange":return t?{jsonrpc:"2.0",method:"ec.messages.change",params:{checkout:t}}:void 0;case"checkout.paymentChange":return t?{jsonrpc:"2.0",method:"ec.payment.change",params:{checkout:t}}:void 0;case"checkout.lineItemsChange":return t?{jsonrpc:"2.0",method:"ec.line_items.change",params:{checkout:t}}:void 0;case"checkout.buyerChange":return t?{jsonrpc:"2.0",method:"ec.buyer.change",params:{checkout:t}}:void 0;case"checkout.fulfillmentChange":return t?{jsonrpc:"2.0",method:"ec.fulfillment.change",params:{checkout:t}}:void 0;case"checkout.totalsChange":return t?{jsonrpc:"2.0",method:"ec.totals.change",params:{checkout:t}}:void 0;case"checkout.complete":{const s=p(this,u,H).call(this);return s?.order?{jsonrpc:"2.0",method:"ec.complete",params:{checkout:s}}:void 0}default:return}},C=function({instruments:e,hasCredential:t}){if(!e?.length)return;const s=c(this,m).checkout.proposal.negotiated.fields.ucp.value?.paymentHandlers?.map(i=>i.id)??[];return e.find(i=>typeof i.id!="string"||typeof i.handler_id!="string"||i.selected!==!0||typeof i.display?.last_digits!="str
1ing"||typeof i.display?.brand!="string"||i.billing_address==null?(s.includes(i.handler_id)||c(this,m).observability.log("InvalidHandlerId","Payment instrument has an invalid handler ID",{handler_id:i.handler_id}),!1):t?i.credential!=null&&typeof i.credential.token=="string":!0)},pe=function(e){const{instruments:t}=e.checkout?.payment??{};return{ucpPaymentInstrument:p(this,u,C).call(this,{instruments:t})}},he=function(e){return{ucpPaymentInstrument:p(this,u,C).call(this,{instruments:e.checkout?.payment?.instruments,hasCredential:!0})}},me=function(e){if(e.upgrade!=null&&e.upgrade.port!=null&&e.upgrade.port instanceof MessagePort)return{upgrade:{port:e.upgrade.port}};const{instruments:t}=e.checkout?.payment??{};return{upgrade:void 0,ucpPaymentInstrument:p(this,u,C).call(this,{instruments:t})}},fe=function(e){const s=e.params?.checkout?.payment?.instruments,i=p(this,u,C).call(this,{instruments:s,hasCredential:!0});return i?{type:"submit",instrument:i}:{errorResponse:{jsonrpc:"2.0",id:e.id,error:{code:D.INVALID_PARAMS,message:"Missing payment instrument with credential"}}}},ye=function(e){const s=e.params?.checkout;if(!s||Object.keys(s).length!==1)return{errorResponse:{jsonrpc:"2.0",id:e.id,error:{code:-32602,message:"ec.update requires exactly one field"}}};const i=Object.keys(s)[0];switch(i){case"fulfillment":{const r=s.fulfillment,o=r?z(r):void 0;return o?{type:"addressUpdate",address:o}:{errorResponse:{jsonrpc:"2.0",id:e.id,error:{code:-32602,message:"Invalid delivery address"}}}}case"payment":{const r=s.payment,o=p(this,u,C).call(this,{instruments:r?.instruments});return o?{type:"instrumentUpdate",instrument:o}:{errorResponse:{jsonrpc:"2.0",id:e.id,error:{code:-32602,message:"Invalid payment instrument"}}}}case"buyer":{const r=_t(s.buyer);return r?{type:"buyerUpdate",buyer:r}:{errorResponse:{jsonrpc:"2.0",id:e.id,error:{code:-32602,message:"Invalid buyer identity"}}}}default:return{errorResponse:{jsonrpc:"2.0",id:e.id,error:{code:-32602,message:`Unknown ec.update field: ${i}`}}}}},H=function(){const e=c(this,A).peek();return e&&re(e,c(this,u,de))},ge=function(){if(!c(this,y).enabled)return{};const e=this.shopCash.peek(),t=this.shopDiscountOffer.peek();return{...e?{shop_cash:e}:{},...t?{shop_discount_offer:t}:{}}},N.version="2026-01-23";let T=N;const pt=new Map([["terms-of-service","terms_of_service"],["privacy-policy","privacy_policy"],["refund-policy","refund_policy"],["shipping-policy","shipping_policy"]]);function ht({embed:n,ucpPaymentHandlers:e,discountExtensionEnabled:t}){const s={};for(const i of e??[]){const{name:r}=i;r&&(s[r]??=[],s[r].push(i))}return{version:T.version,transports:{embedded:{schema:"https://ucp.dev/2026-01-23/services/shopping/embedded.json",delegations:Array.from(n.delegations.allowed)}},capabilities:t?{"dev.ucp.shopping.discount":[{version:T.version,extends:"dev.ucp.shopping.checkout",spec:"https://ucp.dev/2026-01-23/specification/discount",schema:"https://ucp.dev/2026-01-23/schemas/shopping/discount.json"}]}:{},payment_handlers:s}}function mt({checkout:n,violationMessageMap:e}){const{shippingAddress:t,isShippingRequired:s}=n.proposal.negotiated.fields,i=n.latestReceipt.value?.status;if(i==="processed")return"completed";if(i==="processing"||i==="processing_remote_checkouts"||i==="action_required")return"complete_in_progress";if(Array.from(e.entries()).some(([d,f])=>d.type==="error"&&!Ye.has(f.code)))return"incomplete";const o=!!s?.value,a=!!t?.value;return o&&!a?"incomplete":"ready_for_complete"}function re(n,{redactPII:e,redactIdKey:t}){const s=e?ft(n):n;return t?{...s,id:ut(s.id)}:s}function ft(n){const{buyer:e,payment:t,...s}=n;return{...s,...n.fulfillment&&{fulfillment:yt(n.fulfillment)},...n.order&&{order:gt(n.order)}}}function yt(n){return{...n,methods:n.methods.map(e=>{const{destinations:t,selected_destination_id:s,...i}=e;return i})}}function gt(n){return{...n,permalink_url:"about:blank"}}function bt({checkout:n,shop:e,i18n:t,embed:s,negotiationContext:i},r){const{merchandiseLines:o,runningTotal:a,subtotal:l,discountLines:d,contactInfo:f,taxes:_,ucp:L}=n.proposal.negotiated.fields,{id:I,paymentHandlers:ve}=L.value??{};if(I==null)return;const Ce=vt({contactInfo:f?.value}),G=n.latestReceipt.value,Ee=G?.status==="processed"?G.purchaseOrder.paymentLines:void 0,j=Bt(Ee),W=i?.delegatedPaymentInstrument?.value,Ie=Y(n.proposal.proposed.billingAddress.value),Re=Yt(W,Ie,j,r),K=[];for(const P of e.merchantPolicies){const ee=pt.get(P.handle);
1ee&&K.push({type:ee,url:P.url,title:t.translate("shop_policies",{scope:P.handle.replace(/-/g,"_")})})}const w=s.embedder!=="microsoft",{lineItems:Pe,itemsDiscountAmount:ke}=Kt({lines:o.value?.lines,specCompliantDiscounts:w}),R=[],Ae=l.value,M=(w?Wt(o.value?.lines):void 0)??Ae;if(M!=null&&R.push({type:"subtotal",display_text:"Subtotal",amount:h(M)}),w&&M!=null&&R.push(...Jt({currencyCode:M.currencyCode,discountLines:d?.value,itemsDiscountAmount:ke})),w){const P=Qt({checkout:n});P!=null&&R.push({type:"fulfillment",display_text:"Shipping",amount:h(P)})}const $=_.value,J=n.proposal.facts.tax??($?.status==="available_total"?$.totalTax:void 0);J!=null&&R.push({type:"tax",display_text:"Taxes",amount:h(J)});const Q=a.value;Q!=null&&R.push({type:"total",display_text:"Total",amount:h(Q)});const U=w,Z=Ht({checkout:n,discountExtensionEnabled:U}),Se=[...Z.keys(),..._e(W,j,r)?[Gt(j)]:[]],X=U?je({discountLines:d?.value,toMinorUnits:h,hiddenCodeTitle:t.translate("order_summary.discount_title")}):void 0;return{ucp:ht({embed:s,ucpPaymentHandlers:ve,discountExtensionEnabled:U}),id:I,status:mt({checkout:n,violationMessageMap:Z}),buyer:Ce,line_items:Pe,links:K,messages:Se,currency:a.value?.currencyCode??"USD",totals:R,payment:{instruments:Re},fulfillment:{methods:Ct({checkout:n})},order:Lt({checkout:n,embed:s}),...X&&{discounts:X}}}function _t(n){if(n==null||typeof n!="object"||Array.isArray(n))return;const e=new Set(["email","phone_number"]),t=n;if(Object.keys(t).some(r=>!e.has(r)))return;const s=Object.prototype.hasOwnProperty.call(t,"email"),i=Object.prototype.hasOwnProperty.call(t,"phone_number");if(!(s&&typeof t.email!="string")&&!(i&&typeof t.phone_number!="string")&&!(!s&&!i))return{...s?{email:t.email}:{},...i?{phone_number:t.phone_number}:{}}}function vt({contactInfo:n}){const{email:e,phone:t}=n??{};return{...e?{email:e}:{},...t?{phone_number:t}:{}}}function Ct({checkout:n}){const{merchandiseLines:{value:e},deliveryNext:{value:t},shippingAddress:{value:s}}=n.proposal.negotiated.fields;if(t?.status!=="filled"||!t.lines)return Et(e);const r=t.lines.filter(Dt).filter(l=>l.methods.some(d=>Rt(d.methodType))&&l.targetMerchandiseLines?.some(d=>d.requiresShipping));if(!r.length)return[];const o=It(r),a=[];for(const l of o){const d=r.filter(I=>be(I)===l),f=d.map(St),_=[...new Set(f.flatMap(I=>I.line_item_ids))],L=kt(l,d,s);a.push({id:l,type:l,line_item_ids:_,...L&&{destinations:[L]},groups:f})}return a}function Et(n){const e=n?.lines?.filter(t=>t.requiresShipping)?.map(t=>B(t))??[];return e.length===0?[]:[{id:"shipping",type:"shipping",line_item_ids:e,destinations:[],groups:[]}]}function It(n){const e=new Set;for(const t of n){const s=be(t);s&&e.add(s)}return Array.from(e)}function be(n){const e=n.methods[0];if(e)return Pt(e.methodType)?"pickup":"shipping"}function Rt(n){return n==="SHIPPING"||n==="LOCAL"||n==="PICK_UP"||n==="PICKUP_POINT"}function Pt(n){return n==="PICK_UP"||n==="PICKUP_POINT"}function kt(n,e,t){if(n==="shipping")return t?Tt(t):void 0;for(const s of e)if(s.selectedDeliveryMethodHandle){const i=s.methods.find(r=>r.handle===s.selectedDeliveryMethodHandle);if(i)return At(i)}}function At(n){const e=n.pickupLocation;if(e)return{id:n.handle,name:e.name??"",address:Y(e.address)}}function St(n){return{id:n.id??"",line_item_ids:Ot(n),options:n.methods.map(wt),...n.selectedDeliveryMethodHandle&&{selected_option_id:n.selectedDeliveryMethodHandle}}}function wt(n){return{id:n.handle,title:n.title,...n.description&&{description:n.description},...n.carrierName&&{carrier:n.carrierName},...n.minDeliveryDateTime&&{earliest_fulfillment_time:n.minDeliveryDateTime},...n.maxDeliveryDateTime&&{latest_fulfillment_time:n.maxDeliveryDateTime},totals:[{type:"fulfillment",amount:h(n.costAfterDiscounts)}]}}function B(n){return n.id??`gid://shopify/CartLine/${n.variantId}`}function Dt(n){return n.status==="available"}function Ot(n){return n.targetMerchandiseLines?.filter(e=>e.requiresShipping).map(e=>B(e))??[]}function Y(n){return{first_name:n.firstName,last_name:n.lastName,phone_number:n.phone,street_address:n.address1,extended_address:n.address2,address_locality:n.city,address_regi
1on:n.zoneCode,address_country:n.countryCode,postal_code:n.postalCode}}function Tt(n){return{...Y(n),id:`shipping-${n.countryCode}-${n.postalCode}`.replace(/\s+/g,"")}}function Lt({checkout:n,embed:e}){const t=n.latestReceipt.value;return t?.status!=="processed"?void 0:{id:e.embedder==="microsoft"?t.orderIdentity.id:De("Order",Oe(t.orderIdentity.id)),permalink_url:t.confirmationPage.url}}function Mt(n){return!n||typeof n!="object"?!1:Array.isArray(n.checkout?.payment?.instruments)}function xt(n){return!n||typeof n!="object"?!1:n.checkout?.payment?.instruments?.find(s=>s.credential!=null)!=null}function Nt(n){return n!=null&&typeof n=="object"}function jt(n){return n!=null&&typeof n=="object"}function Ut(n){if(!n||typeof n!="object")return!1;const t=n.checkout?.fulfillment;return t?z(t)!=null:!1}function Ft(n,e){const t=n.checkout?.fulfillment,s=t?z(t):void 0;return s?{cart:{delivery:{addresses:[{address:qt(s),oneTimeUse:!1,selected:!0}]}}}:{cart:void 0,errors:void 0}}function z(n){if(Array.isArray(n.methods))for(const e of n.methods){if(!e||typeof e!="object")continue;const{type:t,destinations:s,selected_destination_id:i}=e;if(t!=="shipping"||!Array.isArray(s))continue;const r=typeof i=="string"?i:null;if(r){const o=s.find(a=>V(a)&&typeof a.id=="string"&&a.id===r);if(o&&V(o))return o}for(const o of s){if(!V(o))continue;const a=typeof o.id=="string"?o.id:void 0;if(r==null||a&&r===a||s.length===1)return o}}}function V(n){if(!n||typeof n!="object")return!1;const e=n;return typeof e.street_address=="string"||typeof e.address_locality=="string"||typeof e.address_region=="string"||typeof e.address_country=="string"||typeof e.postal_code=="string"||typeof e.first_name=="string"||typeof e.last_name=="string"}function qt(n,e){return{firstName:n.first_name,lastName:n.last_name,phone:n.phone_number,address1:n.street_address,address2:n.extended_address,city:n.address_locality,countryCode:n.address_country,provinceCode:n.address_region,zip:n.postal_code}}const Vt=new Map(Ne);function Ht({checkout:n,discountExtensionEnabled:e}){const t=new Map,s=n.proposal.negotiated.fields.allViolations.value??[];for(const i of s){if(Ue.has(i.__typename)||Fe.has(i.code))continue;let r,o;qe.has(i.__typename)?(r="requires_buyer_review",o=i.code.toLowerCase()):Ve.has(i.code)?(r="recoverable",o=i.code.toLowerCase()):(r="requires_buyer_input",o=He.has(i.code)?i.code.toLowerCase():"requires_buyer_input");const a="target"in i?i.target:void 0,l=i.localizedMessage||i.nonLocalizedMessage;if(e&&Be(i.code)){const d=Vt.get(i.code);t.set({type:"warning",content_type:"plain",code:d??i.code.toLowerCase(),content:l,path:a},i);continue}t.set({type:"error",severity:r,content_type:"plain",code:o,content:l,path:a},i)}return t}function _e(n,e,t){return e?n?!(t.shouldSuppressReceiptWalletAsExpressCheckout()||st(n)&&n.handler_id==="gpay"&&e==="google_pay"):!0:!1}const oe={APPLE_PAY:"apple_pay",GOOGLE_PAY:"google_pay",SHOP_PAY:"shop_pay",SHOPIFY_INSTALLMENTS:"shop_pay",PAYPAL_EXPRESS:"paypal",VENMO:"venmo",AMAZON_PAY:"amazon_pay",AMAZON_PAY_CLASSIC:"amazon_pay",FACEBOOK_PAY:"facebook_pay",amazon_pay:"amazon_pay",buy_with_prime:"buy_with_prime"};function Bt(n){const e=n?.find(s=>s.method.type==="wallet"||s.method.type==="walletsPlatformPaymentMethod"&&s.method.name in oe);if(e)return oe[e.method.name];if(n?.some(s=>s.method.type==="redeemable"&&s.method.redemptionSource==="SHOP_CASH"))return"shop_pay"}function Yt(n,e,t,s){return n?_e(n,t,s)?[]:it(n)?zt({instrument:n,proposalBillingAddress:e}):[{...n,selected:!0,billing_address:e}]:[]}function zt({instrument:n,proposalBillingAddress:e}){return[{id:n.externalReferenceId,handler_id:"shopify.card",type:"card",selected:!0,display:{last_digits:n.lastDigits,brand:n.brand?.toLowerCase()},cardholder_name:n.cardHolderName,expiry_month:n.month,expiry_year:n.year,billing_address:e}]}function Gt(n){return{type:"info",path:"$.payment",code:"express_checkout",content_type:"plain",content:n}}const ae=new Map;function Wt(n){if(n)return n.reduce((e,t)=>{const s=t.itemPrice;if(!s)return e;const i=s.amount*t.quantity;return e?{...e,amount:e.amount+i}:{...s,amount:i}},void 0)}function Kt({lines:n,specCompliantDiscounts:e}){if(!n?.length)return{lineItems:[],itemsDiscountAmount:0};let t=0;return{lineItems:n.map(i=>{const r=i.itemPrice,o=r?{...r,amount:r.amount*i.quantity}:void 0,a=$t(i.lineAllocations,e),l=[];o&&l.push({type:"subtotal",amount:h(o)}),a!==0&&o&&(e&&(t+=a),l.push({type:e?"items_discount":"discount",amount:h({...o,amount:e?a:-a})}));const d=e&&o&&a!==0?{...o,amount:o.amount-a}:i.totalPrice;return l.push({type:"total",amount:h(d)}),{id:B(i),parent_id:i.parentRelationship?.parent?.id??void 0,quantity:i.quantity,item:{id:i.variantId,title:i.title,price:h(r),...i.image?.url?{image_url:i.image.url}:{}},totals:l}}),itemsDiscountAmount:t}}function $t(n,e){return n.reduce((t,s)=>{const i=s.allocations.reduce((r,{discountDetails:{discount:o},amount:a})=>!e&&o.type==="discountCodeTrigger"?r:r+a.amount,0);return t+i},0)}function Jt({currencyCode:n,discountLines:e,itemsDiscountAmount:t}){let s=0;if(e?.lines?.length){for(const r of e.lines)if(rt(r))for(const o of r.allocations)o.target.type==="DELIVERYLINE"&&(s+=o.target.amount.amount)}const i=[];return t>0&&i.push({type:"items_discount",display_text:"Discounts",amount:h({amount:t,currencyCode:n})}),s>0&&i.push({type:"discount",display_text:"Discount",amount:h({amount:s,currencyCode:n})}),i}function Qt({checkout:n}){const{deliveryNext:e}=n.proposal.negotiated.fields,t=e.value;if(t?.status!=="filled"||!t.lines)return;let s=0,i;for(const r of t.lines){if(r.status!=="available")continue;const o=r.selectedDeliveryMethodHandle;if(!o)continue;const a=r.methods.find(l=>l.handle===o);a?.costAfterDiscounts&&(s+=a.costAfterDiscounts.amount,i??=a.costAfterDiscounts.currencyCode)}if(i!=null)return{amount:s,currencyCode:i}}function h(n){if(!n)return 0;let e=ae.get(n.currencyCode);e||(e=new Intl.NumberFormat("en",{style:"decimal",currency:n.currencyCode,useGrouping:!1}),ae.set(n.currencyCode,e));const t=we(n.currencyCode),[s,i=""]=e.format(n.amount).split(".");return Number(s+i.padEnd(t,"0"))}const ue=1e4;class gn extends dt{constructor(e){super(e),this.version="2026-01-23",this.#n=new ze,this.#r=!1,this.#o=!1,this.#i=null,this.#c=!1,this.#p=new Ge({observability:e.observability}),this.#e=new ct({observability:e.observability}
1),this.#t=new T(e,this.#e.targetType),this.#s=new We([new Ke({context:this.context,mapper:this.#t,transport:this.#e,resizeObserver:this.#p,incomingRequests:{submitShopPay:t=>this.#n.submitShopPay(t),applyRedemption:t=>this.#n.applyRedemption(t)},waitForPendingNegotiations:()=>this.waitForPendingNegotiations(),waitForSkeletonRemoved:()=>this.waitForSkeletonRemoved()})]),this.#e.onRequest(t=>this.#_(t)),this.observability.bridgeInitialized()}get embedderHostname(){const e=this.#e.embedderOrigin;if(e)try{return new URL(e).hostname}catch{return}}#e;#t;#n;#r;#o;#i;#d;#l;#a;#u;#c;#p;#s;unstable_providePreactContext(e){super.unstable_providePreactContext(e),this.#n.initialize({...this.context,...e,addPaymentError:s=>this.addPaymentError(s),removePaymentError:s=>this.removePaymentError(s)}).catch(s=>{this.observability.enqueuedApplyPaymentInstrumentError(s)});const t=this.context.checkout.proposal.negotiated.fields.ucp;t.value={...t.peek()}}async ready(){if(this.#e.isLoopback){if(this.context.environment.debug.logging&&this.context.client.initialRequest.url.searchParams.has("skip_ec_ready")){this.observability.skipEcReady();return}if(!await this.#y())return}this.#g();let e=this.#t.mapEvent({type:"checkout.ready"});if(!e)return;const t=await this.#e.request(e,{timeoutMs:ue});let s=this.#t.mapResponse(e.method,t);if(s?.upgrade?.port instanceof MessagePort){if(this.observability.readyMessagePortUpgrade(),this.#e.upgrade(s.upgrade.port),e=this.#t.mapEvent({type:"checkout.ready"}),!e)return;const r=await this.#e.request(e,{timeoutMs:ue});s=this.#t.mapResponse(e.method,r)}const i=s?.ucpPaymentInstrument;i&&(this.observability.readyPaymentInstrument(),await this.#n.applyInstrument(i)),$e(s)&&(this.observability.readyCartUpdate(Object.keys(s.cart).join(",")),this.applyCart(s.cart))}async start(){const e=this.#t.mapEvent({type:"checkout.start"});e&&(this.#e.notify(e),this.#m(),this.#s.start(),this.observability.checkoutStarted({embedder:this.context.embed.embedder,buyerEmail:this.context.checkout.proposal.proposed.email.peek(),hasPaymentInstrument:this.hasDelegatedPaymentInstrument()}),this.#f())}async resumeFromReceipt(){await this.#y()&&(this.#g(),this.#m(),this.#f())}async complete(){if(this.#b()){const t=new ie;this.observability.unauthenticatedIframe(t.message);return}if(this.#r){this.observability.completedEventSkipped();return}if(this.#r=!0,this.observability.checkoutCompleted(),this.#i){const t=this.#t.buildSubmitResponse(this.#i);this.#i=null,t&&(this.observability.submitResponseSent(t.id),this.#e.send(t));return}const e=this.#t.mapEvent({type:"checkout.complete"});e&&(this.observability.completedEventEmitted(),this.#e.notify(e))}error(e){const t=this.#t.mapEvent({type:"checkout.error",code:e.code,message:e.message,severity:e.severity,path:e.path});t&&this.#e.notify(t)}async addressChangeStart(e){const t=this.#t.mapEvent({type:"checkout.addressChangeStart",addressType:e});if(!t)return;const s=await this.#e.request(t);return this.#t.mapResponse(t.method,s)}async paymentMethodChangeStart(){this.removePaymentError(x.PaymentDelegationError);try{const e=this.#t.mapEvent({type:"checkout.paymentMethodChangeStart"});if(!e)return;const t=await this.#e.request(e),s=this.#t.mapResponse(e.method,t);return s?.ucpPaymentInstrument&&await this.#n.applyInstrument(s.ucpPaymentInstrument),s}catch(e){return this.#h(e,"payment.instruments_change")}}async submitStart(){this.removePaymentError(x.PaymentDelegationError);try{await this.waitForPendingNegotiations();const e=this.#t.mapEvent({type:"checkout.submitStart"});if(!e)return;const t=await this.#e.request(e,{timeoutMs:lt(this.context.embed.embedder)}),s=this.#t.mapResponse(e.method,t);return s?.ucpPaymentInstrument&&await this.#n.submit(s.ucpPaymentInstrument),s}catch(e){return this.#h(e,"payment.credential")}}async windowOpenRequest(e){const t=this.#t.mapEvent({type:"checkout.windowOpen",url:e});if(t)try{await this.#e.request(t)}catch(s){if(s instanceof q&&s.errorCode===Te.WINDOW_OPEN_REJECTED){this.observability.windowOpenRejected(e,s.errorMessage);return}this.observability.windowOpenError(e,s)}}beforeunload(){this.#s.beforeunload()}dialogChange(e){this.#s.dialogChange(e)}showToast(e){return this.#s.showToast(e)}async requestShopPaySessionRevalidation(){return await this.#s.requestShopPaySessionRevalidation()??!0}shopPaySessionRevalidationChange(e){this.#s.shopPaySessionRevalidationChange(e)}cleanup(){this.#s.cleanup(),this.#e.cleanup(),this.#n.cleanup(),this.#d?.(),this.#l?.(),this.#c=!0}#h(e,t){if(e instanceof q&&e.isUserCancelledError){this.observability.paymentDelegationCancelled();return}if(e instanceof Le){this.observability.paymentDelegationTimeout(t,e.message),this.addPaymentError(x.PaymentDelegationError);return}if(e instanceof q&&e.isInternalError){this.observability.paymentDelegationError(t,e.message),this.addPaymentError(x.PaymentDelegationError);return}this.observability.paymentDelegationUnexpectedError(t,e instanceof Error?e.message:String(e))}async#_(e){const{embed:t}=this.context;try{const s=this.#t.parseIncomingRequest(e);
1if("errorResponse"in s){this.observability.incomingRequestValidationFailed(e.id),this.#e.send(s.errorResponse);return}if(await this.#s.handleIncomingRequest(s,{requestId:e.id,markSubmitPending:()=>{this.#i=e.id},onSubmitAttempt:()=>{},sendAckResponse:()=>{this.#e.send({jsonrpc:"2.0",id:e.id,result:{}})}}))return;if(s.type!=="submit"&&!this.#s.canHandleIncomingRequest(s.type))throw new et(t.embedder);switch(s.type){case"submit":this.#i=e.id,await this.#n.submit(s.instrument);break;case"addressUpdate":await this.#n.applyAddress(s.address),this.#e.send({jsonrpc:"2.0",id:e.id,result:{}});break;case"buyerUpdate":await this.#n.applyBuyer(s.buyer),this.#e.send({jsonrpc:"2.0",id:e.id,result:{}});break;case"instrumentUpdate":await this.#n.applyInstrument(s.instrument),this.#e.send({jsonrpc:"2.0",id:e.id,result:{}});break}}catch(s){this.#i=null,this.observability.incomingRequestError(e.id,s);try{this.#e.send(this.#t.buildErrorResponse(e.id,s))}catch{}}}#m(){let e;this.#l=se(()=>{const t=this.#t.ucpCheckout.value;if(!e){e=t,this.#u=t?.totals;return}if(t){if(!Zt(e.line_items,t.line_items)){const s=this.#t.mapEvent({type:"checkout.lineItemsChange"});s&&this.#e.notify(s)}if(!k(e.buyer,t.buyer)){const s=this.#t.mapEvent({type:"checkout.buyerChange"});s&&this.#e.notify(s)}if(!k(e.fulfillment,t.fulfillment)){const s=this.#t.mapEvent({type:"checkout.fulfillmentChange"});s&&this.#e.notify(s)}if(!Xt(e.payment,t.payment)){const s=this.#t.mapEvent({type:"checkout.paymentChange"});s&&this.#e.notify(s)}if(this.#s.checkoutChange(e,t),!k(e.messages,t.messages)){const s=this.context.checkout.proposal.negotiated.fields.allViolations.value??[],i=!!this.context.negotiationContext?.delegatedPaymentInstrument?.peek();if(s.some(o=>Je.has(o.code)||i&&Qe.has(o.code))){const o=this.#t.mapEvent({type:"checkout.messagesChange"});o&&this.#e.notify(o)}}k(e.totals,t.totals)||this.#v(),t.status==="ready_for_complete"&&!this.#o&&(this.#o=!0,this.observability.readyForComplete()),e=t}})}#v(){this.#a||(this.#a=this.#C())}async#C(){try{await this.waitForPendingNegotiations()}finally{this.#a=void 0}if(this.#c)return;const e=this.#t.ucpCheckout.peek()?.totals;if(e&&!k(this.#u,e)){this.#u=e;const t=this.#t.mapEvent({type:"checkout.totalsChange"});t&&this.#e.notify(t)}}#f(){if(this.context.checkout.latestReceipt.peek()?.status==="processed"){this.complete(),this.cleanup();return}let e=!0;this.#d=se(()=>{const t=this.context.checkout.latestReceipt.value;if(e)e=!1;else if(t?.status==="failed"&&t.failure.type==="payment"){const i="code"in t.failure?String(t.failure.code).toLowerCase():"unknown";this.error({code:"PAYMENT_ERROR",message:i,severity:"recoverable",path:"$.payment",timestamp:Date.now()})}if(t?.status==="failed"){const i="code"in t.failure?t.failure.code:"unknown";this.observability.receiptError(t.failure.type,i)}if(t?.status==="failed"&&this.#i){const i=this.#i;this.#i=null,this.observability.submitReceiptFailed(i,t.failure.type),this.#e.send(this.#t.buildErrorResponse(i,new nt(t.failure.type)));return}t&&t.status==="processed"&&(this.complete(),this.cleanup())})}async#y(){if(!this.#e.isLoopback)return!0;const e=await this.#e.waitForTarget();if(this.#e.isDisposed)return!1;if(e==="loopback"){const t=new tt("No embedder transport detected. Checkout was loaded in embedded mode but no parent frame or native bridge was found.");throw this.observability.noTransportDetected(t.message,this.#e.environmentSnapshot),t}return!0}#g(){if(!this.#b())return;const e=new ie;throw this.observability.unauthenticatedIframe(e.message),e}#b(){return this.#e.isIframe&&!this.context.embed.isAuthenticated}}function Zt(n,e){return n===e?!0:n.length!==e.length?!1:n.every((t,s)=>{const i=e[s];return t.id===i.id&&t.quantity===i.quantity&&t.parent_id===i.parent_id&&t.item.id===i.item.id&&t.item.title===i.item.title&&t.item.image_url===i.item.image_url})}function Xt(n,e){if(n===e)return!0;if(!n||!e)return!1;const t=n.instruments??[],s=e.instruments??[];return t.length!==s.length?!1:t.every((i,r)=>{const o=s[r],a=Object.keys(i).filter(d=>d!=="credential"),l=Object.keys(o).filter(d=>d!=="credential");return a.length!==l.length?!1:a.every(d=>{if(!(d in o))return!1;const f=i[d],_=o[d];return f===_?!0:typeof f=="object"&&typeof _=="object"?k(f,_):!1})})}export{gn as Ucp2026_01_23Client};
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.