1import{A as j,q,h as v,l as I,a8 as be,T as B,a9 as Ae,u as L,g as me}from"./2c1ab0fe.BqEHHmaW.js";import{h as Re,eN as X,bm as pe,eO as Me,bg as Ee,cS as Te,eP as Se,B as Oe,c as Ne,H as Le,P as De,bv as ke,eQ as ie}from"./164ad2e3.BA-GikTU.js";import{O as D,d5 as le,bi as ce,e7 as fe,A as we,aR as xe,bt as ge,P as Z,d7 as _e,e8 as $e,e9 as ze,ao as Ue,bb as Fe,ea as Ve,eb as He,ec as je,bp as he,ed as qe,n as Be,ee as Ye,ef as We,ce as Ge}from"./4c290a1e.FJVsH4yi.js";import{g as Je}from"./f1968089.DErP3-mp.js";import{O as Ke}from"./7a8217fd.CAuGvD85.js";import{I as Qe}from"./fc21c11a.BL45iHKA.js";import"./app.D2gvVyTR.js";import"./65f3d4da.BdKZt11Z.js";import"./60a453ce.BClq-svk.js";import"./0a7dffce.BHf0S_6c.js";import"./bb728e1c.uhKc-SJ5.js";import"./0e9ee714.CUvblzuU.js";import"./39921a74.BrTHyyCQ.js";import"./e3e348f2.CzOvkbpO.js";import"./ca5e9c49.COugV1Xp.js";import"./5587f402.CiejVPa1.js";import"./ccdf3592.B7Ukng27.js";import"./e477f96c.CCUKKy0S.js";import"./8599b02a.DjDpxYLZ.js";import"./0c0ad074.RgO7-3qK.js";import"./53bbdad9.6B8LHIua.js";import"./945a08d6.CbBX260S.js";import"./ec391382.K2o3oZbF.js";import"./31cc568e.Dti0cJak.js";import"./4ea44c06.B-5F-oiB.js";import"./f78726c8.D1GQbjRB.js";import"./ed9f2238.ChGZ5py3.js";import"./1ed8f5e3.CDOIq-vC.js";import"./7ee73f43.DtdhcMpw.js";import"./cb5cf153.Cw_O6Mr1.js";import"./bff2ff9b.BZBliUVS.js";import"./aea3fb03.BDHlih-c.js";import"./87bfafec.a5jzmgqb.js";import"./55098bf1.CRzNngQq.js";const K=["PAYMENTS_UNACCEPTABLE_PAYMENT_AMOUNT","DELIVERY_DELIVERY_LINE_DETAIL_CHANGED","CARD_DECLINED","NAME_MISMATCH","INCORRECT_CVC",X.InvalidShippingAddress,ce.InvalidExtensionState,ce.InvalidCaptcha];function Xe(){const{source:e,checkout:t,shop:s,shopPay:r,observability:n,userEvents:i,embed:p}=D(),{installments:a,session:l}=r,g=r.user.installments,c=a.payment.value,f=t.latestReceipt.value,{progress:d}=Re(),u=j(c),o=q(m=>{const C=Ze(m);let _;et(m)?(_=le.InstallmentsRetryError,g.unstable_setRetryable(!0),a.unstable_setModalCloseForRetry(!0)):(_=le.InstallmentsPermanentRejection,g.unstable_setRetryable(!1)),tt(m)&&a.unstable_setAgreementError(X.InvalidShippingAddress);const h=g.isRetryable.value,R=g.isRejected.value,$=a.agreementError.value;n.log("shop_pay_installments_error_occurred","[Installments] An error has occurred",{errors:C,eventType:_,installmentsRetryableSignal:h,installmentsRejectedSignal:R,installmentsAgreementErrorSignal:$}),i.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{...Je(e,t,s,{embedPlatform:p?.platform,shopAppSurface:r.app.config.surface}),eventType:_,success:!1,errorMessage:C}}),g.unstable_setRejected(!0),l.unstable_setInternalProgressing(!1)},[n,i,a,g,e,t,s,l,p?.platform,r.app.config.surface]);return v(()=>{!c||u.current===c||(d("shop-pay-installments-error-handler",m=>{m.status!=="success"&&m.status!=="alreadyCompleted"&&(o(m),a.unstable_updatePayment(void 0))}),u.current=c)},[c,o,d,a]),v(()=>{f?.status==="failed"&&c&&(o(f),a.unstable_updatePayment(void 0))},[f]),{onInstallmentsError:o}}function Ze(e){if(!e)return"no_result";if("errors"in e&&e.errors.length>0){const t=e.errors.map(s=>s.code).join(", ");if(t)return t}if("failure"in e&&e.failure)return`failed_receipt_${e.failure.type}`;if("status"in e&&e.status)return e.status==="invalid"?`error_result_invalid__${e.reasons.join("__")}`:`error_result_${e.status}`}function et(e){if(!e)return!1;if("reasons"in e&&e.reasons)return e.reasons.some(t=>K.includes(t));if("failure"in e&&e.failure){const t=e.failure;return t.type==="payment"&&K.includes(t.code)}return"violations"in e?e.violations.some(({code:t})=>K.includes(t)):!1}function tt(e){return e?.status==="agreement_invalid"&&e.violations.some(({code:t})=>t===X.InvalidShippingAddress)}var Q=(e=>(e.CheckoutOne="C1",e.Pay="PAY",e))(Q||{});const nt=["initializePay","pingPay","updateAuthorization","updateCheckout","updateCard","setInitialUserState"];class st extends Error{constructor(t,s){super(t),this.name="RPCConnectionTimeoutError",this.diagnostics=s}}const at=1e3,ot=100,x={CONNECTION_INITIATED:"installments_rpc_connection_initiated",CONNECTION_ATTEMPT:"installments_rpc_connection_attempt",NOT_READY:"installments_rpc_not_ready",CONNECTED:"installments_rpc_connected",CONNECTION_ERROR:"installments_rpc_connection_error",CONNECTION_TIMEOUT:"installments_rpc_connection_timeout"};function rt({rpcEndpoint:e,initializer:t,connectionOptions:{timeout:s=at,attemptDelay:r=ot}={},inAppRPCSessionCount:n}){const[i,p]=I(!1),a=fe(n),[l,g]=I(),c=j({attemptCount:0,initializerCalled:!1,startedAt:0}),f=e&&t&&!i&&!l;return v(()=>{a!==n&&p(!1)},[n,a]),v(()=>{let d=!1;c.current={attemptCount:0,initializerCalled:!1,startedAt:Date.now()};async function u(){if(!e||!t||!f)return;const{call:o,log:m,observabilityLog:C}=e;for(;;){c.current.attemptCount++;const _=c.current.attemptCount;try{m(`RPC channel ${n} opening...`),C(x.CONNECTION_ATTEMPT,`RPC channel ${n} opening (attempt ${_})`,{sessionCount:n,attemptNumber:_,elapsedMs:Date.now()-c.current.startedAt}),c.current.initializerCalled=!0;const h=await t(o);if(!h){if(m("RPC channel not ready yet"),C(x.NOT_READY,"RPC channel not ready yet, retrying",{sessionCount:n,attemptNumber:_,elapsedMs:Date.now()-c.current.startedAt}),await new Promise(R=>setTimeout(R,r)),d)break;continue}m("RPC channel opened",h),C(x.CONNECTED,"RPC channel opened successfully",{sessionCount:n,attemptNumber:_,elapsedMs:Date.now()-c.current.startedAt}),d||p(!0);break}catch(h){m("RPC connection failed",h),C(x.CONNECTION_ERROR,`RPC connection failed on attempt ${_}`,{sessionCount:n,attemptNumber:_,elapsedMs:Date.now()-c.current.startedAt,errorMessage:h instanceof Error?h.message:String(h),errorName:h instanceof Error?h.name:"unknown"}),d||g(h);break}}}return e&&t&&f&&(e.log("connection initiated"),e.observabilityLog(x.CONNECTION_INITIATED,"RPC connection initiated",{sessionCount:n,timeoutMs:s,attemptDelayMs:r}),u()),()=>{d=!0}},[r,f,t,e,n,s]),v(()=>{if(!e||!f)return;let d=!1;const{log:u,observabilityLog:o}=e,m=setTimeout(()=>{if(f){const C=c.current,_={attemptCount:C.attemptCount,elapsedMs:Date.now()-C.startedAt,timeoutMs:s,initializerCalled:C.initializerCalled,sessionCount:n},h=new st("RPC channel open timeout",_);u("RPC connection failed",h),o(x.CONNECTION_TIMEOUT,`RPC channel open timeout after ${_.attemptCount} attempt(s) over ${_.elapsedMs}ms`,_),d||g(h)}},s);return()=>{clearTimeout(m),d=!0}},[f,e,s,n]),v(()=>(e||p(!1),()=>{e&&e.terminate()}),[e]),{connected:i,error:l}}function it(e,{logging:t,messenger:s,observability:r,...n}){return{...be(s,n),id:n.uuid(),log(i,...p){},observabilityLog(i,p,a){r&&r.log(i,`[${e}-RPC] ${p}`,a)}}}function lt(e,t,s){const[r,n]=I(!1),[i,p]=I(0),{observability:a}=D(),l=B(()=>
1{if(!t)return;const d=it(Q.CheckoutOne,{callable:nt,logging:!1,messenger:Ae(t,{terminate:!1}),uuid:we,observability:a});return d.log(`expose initializeC1 ${i}`),d.expose({initializeC1(){}}),d},[t,i,a]);v(()=>{if(!l){n(!1);return}const d={reset(){n(!1),p(o=>o+1)},closeModal(o,m){u("closeModal",arguments),e.onClose(o,m)},initializeC1(){return u("initializeC1",arguments),n(!0),{id:l.id,metadata:{timestamp:new Date().toISOString()}}},installmentsError(o){u("installmentsError",arguments),e.onError(o)},payAnotherWay(){u("payAnotherWay",arguments),e.onPayAnotherWay()},payWithInstallments(o){u("payWithInstallments",arguments),e.onComplete(o)},pingC1(o="interrogative",m){return u("pingC1",arguments),l.log(`PING: ${o} @ ${new Date().toISOString()}`),e.onPing(o,m),`PONG: ${Q.CheckoutOne}`},resizeModal(o){return u("resizeModal",arguments),e.setHeight(o),window.innerHeight},updateProgress(o,m){u("updateProgress",arguments),e.onUpdateProgress(o,m)}};l.log("expose handlers"),l.expose({...d});function u(o,m){l?.log(o,m)}},[e,l]);const g=q(d=>d.initializePay(),[]),{connected:c,error:f}=rt({rpcEndpoint:l,initializer:r?g:void 0,connectionOptions:s,inAppRPCSessionCount:i});if(f)throw f;if(!(!l||!r||!c))return l.call}function ct(e){return{lastUsedAt:"",name:"",preferred:!1,id:String(e.id),uuid:e.uuid??"",brand:e.brand,expired:e.expired,expiring:!1,expiryMonth:e.month,expiryYear:e.year,funding:e.funding,lastDigits:e.last_digits,supportsInstallmentsInterestLoan:e.supports_installments_interest_loan,supportsInstallmentsSplitPayLoan:e.supports_installments_split_pay_loan,installmentsSplitPayLoanNotSupportedReason:e.installments_split_pay_loan_not_supported_reason,installmentsInterestLoanNotSupportedReason:e.installments_interest_loan_not_supported_reason,billingAddress:{address:{firstName:e.billing_address.first_name,lastName:e.billing_address.last_name,company:e.billing_address.company,address1:e.billing_address.address1,address2:e.billing_address.address2,city:e.billing_address.city,postalCode:e.billing_address.zip,phone:e.billing_address.phone,countryCode:e.billing_address.country_code,zoneCode:e.billing_address.zone_code}},billingAddressValid:e.address_valid,verified:!0}}function dt({open:e,lastKnownPayStepId:t,locale:s}){const{client:r,environment:{services:{shopServer:n}},shop:i,observability:p,source:a,shopPay:l}=D(),g=xe({source:a}),{config:c}=l,f=l.installments.triggerSource.value,d=l.deviceFingerprint.value,{tracking:u}=c,o=u.unique,m=u.visit,{myshopifyDomain:C,merchantPolicies:_,countryCode:h}=i,{checkoutSessionIdentifier:R}=a,$=l.session.selectedPaymentMethod.value,M=ge($),O=$e,[b,T]=I(M?.id),[k,z]=I(d),{paymentMethods:Y}=Z(),S=_e(Y.value),P=S?.availableLoanTypes.join(",")||"",U=S?.supportedCountries.join(",")||h,y=S?.creditCardEnabledCountries.join(",")||"",A=!!R,E=!!b,N=!!S,F=P.length>0,w=y.length>0,ee=!!k,te=(S?.supportedCountries.length??0)>0,ne=_.find(({handle:V})=>V==="refund-policy")?.url,W=pe().value,se=Me(),ae=Ee({include:{shopId:!0,shopClientUuid:!0}}),oe=l.isExternal;v(()=>{!e&&M&&T(M.id)},[M,e]),v(()=>{e&&!b&&M&&T(M.id)},[e,b,M]),v(()=>{!e&&d!==null&&z(d)},[d,e]);const G=B(()=>{if(!R||!b)return null;const V={checkout_version:g,checkout_token:R,locale:s,parent_page_load_id:O,selected_card_id:b,shopify_domain:C,last_known_step_i
1d:t,available_loan_types:P,refund_policy_url:ne,isPointOfSale:W,supported_countries:U,tracking_unique:o,tracking_visit:m,device_fingerprint:k??"",credit_card_enabled_countries:y,trigger_source:f},ve=Object.entries(W?{...V,...se}:V).map(([Pe,Ie=""])=>`${encodeURIComponent(Pe)}=${encodeURIComponent(Ie)}`).join("&"),re=Ue(),Ce=re?"installments_iframe_inapp":"installments_iframe",H=new URL(`/pay/transactions/${Ce}?${ve}`,n.url),ye=new URLSearchParams(r.initialRequest.url.search);return ae(H.searchParams,ye),re&&oe&&(H.searchParams.set("origin",ze.PaymentRequest),H.searchParams.set("flow","payment_request")),H.href},[R,b,g,s,O,C,t,P,U,y,ne,W,o,m,k,se,r.initialRequest.url.search,ae,n.url,oe,f]),J=j(!1);return v(()=>{if(!e){J.current=!1;return}G||J.current||(J.current=!0,p.log("installments_iframe_source_missing","[Installments] Iframe source missing while modal open",{availableLoanTypesPresent:F,creditCardEnabledCountriesPresent:w,hasCheckoutToken:A,hasDeviceFingerprint:ee,hasInitialSelectedCard:E,hasInstallmentsConfig:N,supportedCountriesPresent:te}))},[F,w,G,A,ee,E,N,p,e,te]),G}const ut="IgLVV",mt="X587H",de={ConsolidatedPlanSelectionReviewTreatmentIframe:ut,ConsolidatedPlanSelectionReviewTreatmentAnimationIframe:mt},pt="shop-pay-affirm-iframe",ft="camera; microphone; gyroscope; accelerometer";function gt({checkoutDetails:e,open:t,onClose:s,onError:r,locale:n}){const{i18n:i,observability:p,shopPay:a}=D(),{installments:l}=a,g=Fe("taxes").value,c=Te(),[f,d]=I(null),[u,o]=I(),[m,C]=I(),[_,h]=I(null),[R,$]=I(!1),M=q(y=>{c.current&&o(y)},[c]),O=j(),b=l.payment.value,T=ge(a.session.selectedPaymentMethod.value),k=a.user.creditCards,z=a.accessToken.value,Y=B(()=>({onClose(y,A){C(A),_||h(y),s()},setHeight(y){u&&(u.style.height=`${y}px`)},onComplete(y){p.log("installments_payment_created","[Installments] Installments payment created"),l.unstable_updatePayment(y)},onError:r,onPayAnotherWay(){try{a.session.unstable_updatePaymentMethodOption({type:"wallet",name:"SHOP_PAY"}),O.current=void 0,C(void 0),h(null)}catch{s();return}s()},onUpdateProgress(y,A){O.current=y;const E=A?k.value.find(w=>Number(w.id)===A?.id):null,N=E&&A?.id!==Number(T?.id),F=!E&&A;if(N)a.session.selectPaymentMethod(Ve(E));else if(F){const w=a.user.addCreditCard(ct(A));a.session.selectPaymentMethod(w)}},onPing(y,A){if(y==="installments_iframe_loaded"){const E=A?.consolidatedPlanSelectionReviewVariant,N=E==="treatment";u?.classList.toggle(de.ConsolidatedPlanSelectionReviewTreatmentIframe,E==="copy_and_visual_only"||N),u?.classList.toggle(de.ConsolidatedPlanSelectionReviewTreatmentAnimationIframe,N),d(!0)}}}),[r,_,s,u,p,l,k.value,T?.id,a.session,a.user]),S=dt({open:t,lastKnownPayStepId:m,locale:n}),P=lt(Y,u);Se({enabled:!!u,onTimeout:()=>{f||(r(),d(!1))},timeout:6e3}),v(()=>{(e||!b)&&(p.log("installments_progress_reset","[Installments] Installments progress reset",{reason:b?"checkoutDetails":"installmentsPayment"}),O.current=void 0)},[e,b,p]),v(()=>{P&&z&&P.updateAuthorization({accessToken:z})},[P,z]),v(()=>{const y=!g&&e?.installmentsProposalData?.taxAmount!==void 0;P&&t&&e&&y&&!b&&(p.log("installments_proposal_data_passed_to_iframe","[Installments] Proposal data passed to iframe"),P.updateCheckout(e,O.current))},[e,b,t,P,g,p]),v(()=>{P&&T?.id&&P.updateCard(T.id)},[P,T?.id]),v(()=>{P&&_&&P.setInitialUserState(_)},[P,_]);const U=()=>{$(!1),s()};return f===!1?L(ke,{open:R,size:"large",onHide:U,accessibilityLabel:i.translate("installments.pay_in_installments_error_title"),children:L(Oe,{blockAlignment:"center",minBlockSize:"200px",children:L(Ne,{alignItems:"center",gap:"base",children:[L(Le,{level:2,textAlign:"center",children:i.translate("installments.pay_in_installments_error_title")}),L(De,{textAlign:"center",children:i.translate("installments.pay_in_installments_error_description")})]})})}):S?L(Ke,{accessibilityLabel:i.translate("installments.pay_in_installments_title"),allow:ft,blocking:!0,iframeId:pt,iframeRef:M,open:t,source:S}):null}function _t(e){const t=Z().customAttributes;return me(()=>{if(!e.value)return;const s=He(je,t.value),r=s?JSON.parse(s.value):void 0;if(r)return{...r,zoneCode:r.provinceCode,postalCode:r.zip}})}function ue(e){if(!e)return"";const t=e.shippingAddress?{countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode}:void 0,s=e.merchandiseLines.map((n,i)=>({id:n.stableId??n.id??`__idx_${i}`,quantity:n.quantity,totalPrice:n.totalPrice})).sort((n,i)=>n.id<i.id?-1:n.id>i.id?1:0),r=e.storeAddress?{key:e.storeAddress.key,value:e.storeAddress.value}:void 0;return JSON.stringify({sellerId:e.sellerId,channel:e.channel,deliveryMethod:e.deliveryMethod,merchandiseLines:s,shippingAddress:t,shippingAmount:e.shippingAmount,storeAddress:r,taxAmount:e.taxAmount,total:e.total})}function ht(){const[e,t]=I(),[s,r]=I(!1),{value:n}=he(),i=vt().value,p=fe(e),{locale:a}=D().i18n;return v(()=>{if(!n||!i){t(void 0);return}const l={format:"${{amount}}",decimal_mark:".",thousands_separator:","};if(!e){t({currencyFormat:l,installmentsProposalData:i,paymentDue:n,locale:a});return}const g=ue(i)!==ue(e.installmentsProposalData);g&&t({currencyFormat:l,installmentsProposalData:i,paymentDue:n,locale:a}),r(g)},[e,i,n,a]),B(()=>({checkoutProposal:e,previousCheckoutProposal:p,hasChanged:s}),[e,p,s])}function vt(){const{shopPay:e,checkout:t}=D(),s=pe(),{merchandiseLines:r,taxes:n,paymentMethods:i}=Z(),p=qe("ONE_TIME_PURCHASE"),a=_t(s),l=he();return me(()=>{const g=r.value?.lines.filter(({quantity:m})=>m>0);if(!g)return;const c=s.value,f=Be(p.value),d=e.session.selectedShippingAddress.value,u=Ye(c,f),o=Ct(n.value);
1return{sellerId:_e(i.value)?.sellerId,merchandiseLines:g,shippingAddress:t.isShippingRequired.value?d?.address:void 0,shippingAmount:f?.costAfterDiscounts,taxAmount:o,total:l.value,channel:c?ie.RetailPos:ie.Online,deliveryMethod:u,storeAddress:a.value}})}function Ct(e){switch(e?.status){case"available_total":return e.totalTax;case"available_total_included":return e.totalIncludedInTarget;default:return}}function tn(){const{i18n:e,shopPay:t,observability:s}=D(),{locale:r}=e,n=ht(),i=We(n,200),{onInstallmentsError:p}=Xe(),{countryCode:a,defaultLocale:l,checkoutLocaleSupported:g}=Ge(Qe),c=t.installments,f=c.isModalOpen.value,d=c.isModalClosedForRetry.value,u=a.value?`${l.value}-${a.value}`:l.value,o=q(()=>{s.log("installments_modal_closed","[Installments] Modal closed"),c.unstable_setModalOpen(!1)},[s,c]);return v(()=>{n?.hasChanged&&f&&(s.log("installments_checkout_details_changed_while_modal_open","[Installments] Checkout details changed while modal open"),o())},[n?.hasChanged,f,o,s]),v(()=>{d&&(s.log("installments_modal_closed_for_retry","[Installments] Modal closed for retry"),c.unstable_setModalCloseForRetry(!1),o())},[d,c,o,s]),L(gt,{checkoutDetails:i?.checkoutProposal,open:f,onClose:o,onError:p,locale:g.value?r:u})}export{tn as InstallmentsModal};
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.