Build 584177stable
Module 447952
4,861 characters · in 4d2a8f4300617f0d.jsDependencies
Source Raw
function(e,t,n){n.d(t,{Ky:()=>_,_i:()=>v,eR:()=>x,wD:()=>R});var l=n(627968),i=n(64700),r=n(342393),a=n(503698),s=n.n(a),o=n(289873),u=n(228366),c=n(942340),d=n(550238),p=n(648335),m=n(211528),C=n(316915),h=n(783327),E=n(166532),f=n(38405),A=n(240248),S=n(891640),y=n(818348),P=n(426125);let I=[E.pn.PAYMENT_ELEMENT],_=[E.pn.PAYPAL_INFORMATION,E.pn.VENMO_INFORMATION,E.pn.CASH_APP_INFORMATION,E.pn.EPS_INFORMATION,E.pn.PRZELEWY24_INFORMATION,E.pn.IDEAL_INFORMATION],T=new Set([E.pn.PAYMENT_ELEMENT,..._]);function g(e){let{step:t,billingAddressInfo:n,customPaymentMethodIdsToSourceTypes:a,stripePaymentElementProps:o,stripeAddressElementProps:u,stripeElementsRef:c,paymentElementSelectedType:d,paymentMethodOrder:p,addressElementKey:C,analyticsContext:h,paymentElementFooter:f}=e,A=(0,r.useElements)();i.useEffect(()=>{c.current=A},[A,c]);let{shouldShowPaymentElement:T,shouldShowAddressElement:g,excludeBodySpacing:x}=i.useMemo(()=>({shouldShowPaymentElement:I.includes(t),shouldShowAddressElement:t===E.pn.ADDRESS,excludeBodySpacing:_.includes(t)}),[t]),v=i.useMemo(()=>{if(null==d)return!1;if((0,S.i)(d)){let{renderAddressElementInStandaloneMode:e}=S.F[d];return e??!1}},[d]);return(0,l.jsxs)("div",{className:s()(P.kL,{[P.rf]:!x}),children:[(0,l.jsxs)("div",{className:s()(T?P.RK:[P.R,P.$u],{[P.df]:null==d,[P._m]:d===y.he.CARD,[P.JD]:d===y.he.PAYPAL}),children:[(0,l.jsx)(m.Wf,{...o,paymentMethodOrder:p,customPaymentMethodIdsToSourceTypes:a,step:t,analyticsContext:h}),T&&f]}),(0,l.jsx)("div",{className:s()(P.K_,g?P.RK:[P.R,P.vg]),children:(0,l.jsx)(m.KS,{...u,internalKey:C,renderAsStandaloneElement:v,billingAddressInfo:n})})]})}function x(){return(0,l.jsx)("div",{className:s()(P.kL,P.rf,P.g4),children:(0,l.jsx)(o.y,{type:o.y.Type.PULSING_ELLIPSIS})})}function v(e){let{onSetupError:t,...n}=e,{elementsOptions:i,isLoading:a,setupError:s,customPaymentMethodIdsToSourceTypes:o,paymentMethodOrder:u}=(0,c.p)({onSetupError:t}),d=(0,h.S)();return a||null!=s||null==d?(0,l.jsx)(x,{}):(0,l.jsx)(r.Elements,{stripe:d,options:i,children:(0,l.jsx)(g,{...n,customPaymentMethodIdsToSourceTypes:o,paymentMethodOrder:u})})}let N=["applePay","googlePay","link"];function R(e){let{step:t,handleStepChange:n,paymentElementsEnabled:l,logger:a,onBillingAddressChange:s,shouldLogOnChangeEvents:o,continueSessionToInitialStep:c}=e,h=i.useRef(null),S=i.useRef(null),[P,I]=i.useState(!1),[_,g]=i.useState(!1),[x,v]=i.useState(c===E.pn.CREDIT_CARD_INFORMATION?y.he.CARD:null),[R,M]=i.useState(!1),[b,j]=i.useState(void 0),O=function(e){let{step:t,paymentElementsEnabled:n,paymentElementSelectedType:l}=e;return!!n&&(T.has(t)||t===E.pn.ADDRESS&&null!=l)}({step:t,paymentElementsEnabled:l,paymentElementSelectedType:x}),L=i.useCallback(()=>{j(Date.now().toString())},[]);i.useEffect(()=>{t===E.pn.PAYMENT_ELEMENT&&(S.current=null)},[t]);let k=(0,C.t4)(e=>e.linkWalletEnabled),w=i.useMemo(()=>k?N:N.filter(e=>"link"!==e),[k]),D=i.useMemo(()=>({onChange:(e,t)=>{o&&null!=a&&a.log("PaymentElements onChange event:",e),I(e.complete),v(t)},onReady:()=>{g(!0)},wallets:w}),[a,o,w]),U=i.useMemo(()=>({addressElementOnChangeFired:R,onChange:e=>{let{complete:t,value:{address:n,name:l}}=e,i=(0,m.ZB)(n);o&&null!=a&&a.log("AddressElement onChange event:",{complete:t,address:n,name:l,addressElementOnChangeFired:R,isAddressSubstantial:i}),M(!0);let r={name:l,country:n.country,city:n.city,line1:n.line1,line2:n.line2??"",state:n.state,postalCode:n.postal_code},u=(0,d.Qd)(r);!t||u||d.im.has(n.country)||f.A.captureMessage("Unexpected AddressElement validity mismatch: Stripe complete but address was computed invalid",{tags:{app_context:"billing",billing_context:"payment_element"},extra:{isValidComputed:u,stripeComplete:t,country:n.country,emptyFields:Object.entries(r).filter(e=>{let[,t]=e;return(0,A.uJ)(t)}).map(e=>{let[t]=e;return t})}}),s(r,u&&t)}}),[s,o,a,R,M]),G=i.useCallback(()=>{let e;s({name:"",country:"",city:"",line1:"",line2:"",state:"",postalCode:""},!1),null!=(e=function(e){if(null==e)return;let t=e.getElement(r.AddressElement);if(null!=t)return t}(h.current))&&e.clear()},[h,s]),F=i.useCallback(function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];void 0!==e&&v(e),n(E.pn.PAYMENT_ELEMENT,t),M(!1),null!=x&&(0,p.R8)(x)&&G()},[n,G,x]);i.useEffect(()=>{if(l)return u.h.subscribe("BRAINTREE_TOKENIZE_PAYPAL_FAIL_WINDOW_CLOSED",e),()=>{u.h.unsubscribe("BRAINTREE_TOKENIZE_PAYPAL_FAIL_WINDOW_CLOSED",e)};function e(){F(void 0)}},[F,l]);let H=i.useCallback(()=>{v(null)},[]);return{shouldRenderPaymentElement:O,stripePaymentElementProps:D,stripeAddressElementProps:U,stripeElementsRef:h,lastConfirmedSetupIntentRef:S,paymentElementReady:P,paymentElementLoaded:_,paymentElementSelectedType:x,setPaymentElementSelectedType:v,returnToPaymentElementStep:F,onBackFromPaymentElement:H,addressElementKey:b,remountAddressElement:L,clearAddressElement:G}}}