Module 211528

6,986 characters · in 6c84c70b226fa2cf.js
Dependencies
Source Raw
function(e,t,n){n.d(t,{KS:()=>b,Ky:()=>v,Wf:()=>x,e4:()=>O,eR:()=>j,wD:()=>D});var l=n(627968),r=n(64700),i=n(342393),a=n(503698),s=n.n(a),o=n(17928),u=n(289873),c=n(228366),d=n(424297),p=n(166532),m=n(287809),h=n(174459),A=n(38405),C=n(240248),E=n(71532),y=n(116673),P=n(942340),S=n(550238),_=n(648335),f=n(652215),I=n(818348),T=n(235301);let N=[p.pn.PAYMENT_ELEMENT],v=[p.pn.PAYPAL_INFORMATION,p.pn.VENMO_INFORMATION,p.pn.CASH_APP_INFORMATION,p.pn.EPS_INFORMATION,p.pn.PRZELEWY24_INFORMATION,p.pn.IDEAL_INFORMATION],g=new Set([p.pn.PAYMENT_ELEMENT,...v]),x=r.memo(function(e){let{paymentMethodOrder:t,wallets:n=[],customPaymentMethodIdsToSourceTypes:a,analyticsContext:s,options:u,onChange:c,step:d,...A}=e,C=(0,o.bG)([m.default],()=>{let e=m.default.getCurrentUser();return null!=e?e.email:null}),E=(0,o.bG)([m.default],()=>{let e=m.default.getCurrentUser();return null!=e?e.globalName:null}),y=r.useCallback(e=>{if(d!==p.pn.PAYMENT_ELEMENT)return;let t=(0,_.Wn)(e.value.type,a);if(null!=c&&c(e,t),null!=s){let{contextMetadata:n,activitySessionId:l,analyticsData:r}=s,i=null!=t&&t!==I.he.PAYMENT_REQUEST?_.mr[t]:e.value.type;h.default.track(f.HAw.PAYMENT_ELEMENT_CHANGED,{load_id:n.loadId,activity_session_id:l,payment_element_selected_method:i,payment_source_type:t,complete:e.complete,empty:e.empty,..."string"==typeof r.location?{location:r.location}:void 0})}},[c,s,d,a]),P=r.useMemo(()=>({applePay:n.includes("applePay")?"auto":"never",googlePay:n.includes("googlePay")?"auto":"never",link:n.includes("link")?"auto":"never"}),[n]),S=r.useMemo(()=>({billingDetails:{...null!=C&&{email:C},...null!=E&&{name:E}}}),[C,E]),T=r.useMemo(()=>({id:"stripe-payment-element",options:{layout:{type:"tabs"},wallets:P,defaultValues:S,paymentMethodOrder:t,...u},onChange:y,...A}),[P,S,u,A,y,t]);return(0,l.jsx)(i.PaymentElement,{...T})}),R=e=>{let{children:t}=e,{stripe:n}=(0,d.P5)(),{elementsAppearance:r}=(0,P.E)(),a=(0,E.PU)();return(0,l.jsx)(i.Elements,{stripe:n,options:{appearance:r,locale:a,mode:"setup",currency:"usd"},children:t})},M=e=>null!=e&&null!=e&&(!(0,C.uJ)(e.line1)||!(0,C.uJ)(e.city)),b=r.memo(function(e){let{options:t,renderAsStandaloneElement:n,addressElementOnChangeFired:a,billingAddressInfo:s,internalKey:o,...u}=e,c=(0,y.z)(),d=null!=c&&c.length>0?c[0]:(0,C.uJ)(s.country)?"":s.country,p=r.useMemo(()=>{let{name:e,address:t}=(0,E._Z)({...s,country:d});return null!=t&&M(t)?{...null!=e&&""!==e&&{name:e},address:Object.fromEntries(Object.entries(t).filter(e=>{let[t,n]=e;return void 0!==n}))}:null!=e&&""!==e?{name:e}:null!=t&&null!=t.country&&a?{address:{country:d}}:void 0},[s,a,d]),m=r.useMemo(()=>null!=c&&c.length>0?c:void 0,[c]),h=r.useMemo(()=>(0,l.jsx)(i.AddressElement,{options:{mode:"billing",defaultValues:p,allowedCountries:m,...t},...u},o),[p,m,t,u,o]);return n?(0,l.jsxs)(R,{children:[(0,l.jsx)("div",{className:T.R,children:(0,l.jsx)(i.PaymentElement,{id:"stripe-payment-element"})}),h]}):h}),L=e=>{let{step:t,billingAddressInfo:n,customPaymentMethodIdsToSourceTypes:a,stripePaymentElementProps:o,stripeAddressElementProps:u,elementsRef:c,paymentElementSelectedType:d,paymentMethodOrder:m,addressElementKey:h,analyticsContext:A,paymentElementFooter:C}=e,E=(0,i.useElements)();r.useEffect(()=>{c.current=E},[E,c]);let{shouldShowPaymentElement:y,shouldShowAddressElement:P,excludeBodySpacing:S}=r.useMemo(()=>({shouldShowPaymentElement:N.includes(t),shouldShowAddressElement:t===p.pn.ADDRESS,excludeBodySpacing:v.includes(t)}),[t]);return(0,l.jsxs)("div",{className:s()(T.kL,{[T.rf]:!S}),children:[(0,l.jsxs)("div",{className:s()(y?T.RK:[T.R,T.$u],{[T.df]:null==d,[T._m]:d===I.he.CARD,[T.JD]:d===I.he.PAYPAL}),children:[(0,l.jsx)(x,{...o,paymentMethodOrder:m,customPaymentMethodIdsToSourceTypes:a,step:t,analyticsContext:A}),y&&C]}),(0,l.jsx)("div",{className:s()(T.K_,P?T.RK:[T.R,T.vg]),children:(0,l.jsx)(b,{...u,internalKey:h,renderAsStandaloneElement:d===I.he.PAYMENT_REQUEST,billingAddressInfo:n})})]})},j=()=>(0,l.jsx)("div",{className:s()(T.kL,T.rf,T.g4),children:(0,l.jsx)(u.y,{type:u.y.Type.PULSING_ELLIPSIS})}),O=e=>{let{onSetupError:t,...n}=e,{elementsOptions:r,isLoading:a,setupError:s,customPaymentMethodIdsToSourceTypes:o,paymentMethodOrder:u}=(0,P.p)({onSetupError:t}),{stripe:c}=(0,d.P5)();return a||null!=s||null==c?(0,l.jsx)(j,{}):(0,l.jsx)(i.Elements,{stripe:c,options:r,children:(0,l.jsx)(L,{...n,customPaymentMethodIdsToSourceTypes:o,paymentMethodOrder:u})})},w=["applePay","googlePay","link"],D=e=>{let{step:t,handleStepChange:n,paymentElementsEnabled:l,logger:a,onBillingAddressChange:s,shouldLogOnChangeEvents:o,continueSessionToInitialStep:u}=e,d=r.useRef(null),m=r.useRef(null),[h,E]=r.useState(!1),[y,P]=r.useState(u===p.pn.CREDIT_CARD_INFORMATION?I.he.CARD:null),[f,T]=r.useState(!1),[N,v]=r.useState(void 0),x=(e=>{let{step:t,paymentElementsEnabled:n,paymentElementSelectedType:l}=e;return!!n&&(g.has(t)||t===p.pn.ADDRESS&&null!=l)})({step:t,paymentElementsEnabled:l,paymentElementSelectedType:y}),R=r.useCallback(()=>{v(Date.now().toString())},[]);r.useEffect(()=>{t===p.pn.PAYMENT_ELEMENT&&(m.current=null)},[t]);let b=r.useMemo(()=>({onChange:(e,t)=>{o&&null!=a&&a.log("PaymentElements onChange event:",e),E(e.complete),P(t)},wallets:w}),[a,o]),L=r.useMemo(()=>({addressElementOnChangeFired:f,onChange:e=>{let{complete:t,value:{address:n,name:l}}=e,r=M(n);o&&null!=a&&a.log("AddressElement onChange event:",{complete:t,address:n,name:l,addressElementOnChangeFired:f,isAddressSubstantial:r}),T(!0);let i={name:l,country:n.country,city:n.city,line1:n.line1,line2:n.line2??"",state:n.state,postalCode:n.postal_code},u=(0,S.Qd)(i);!t||u||S.im.has(n.country)||A.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(i).filter(e=>{let[,t]=e;return(0,C.uJ)(t)}).map(e=>{let[t]=e;return t})}}),s(i,u&&t)}}),[s,o,a,f,T]),j=r.useCallback(()=>{let e;s({name:"",country:"",city:"",line1:"",line2:"",state:"",postalCode:""},!1),null!=(e=(e=>{if(null==e)return;let t=e.getElement(i.AddressElement);if(null!=t)return t})(d.current))&&e.clear()},[d,s]),O=r.useCallback(function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];void 0!==e&&P(e),n(p.pn.PAYMENT_ELEMENT,t),T(!1),null!=y&&(0,_.R8)(y)&&j()},[n,j,y]);r.useEffect(()=>{if(!l)return;let e=()=>{O(void 0)};return c.h.subscribe("BRAINTREE_TOKENIZE_PAYPAL_FAIL_WINDOW_CLOSED",e),()=>{c.h.unsubscribe("BRAINTREE_TOKENIZE_PAYPAL_FAIL_WINDOW_CLOSED",e)}},[O,l]);let D=r.useCallback(()=>{P(null)},[]);return{shouldRenderPaymentElement:x,stripePaymentElementProps:b,stripeAddressElementProps:L,combinedStripeElementsRef:d,lastConfirmedSetupIntentRef:m,paymentElementReady:h,paymentElementSelectedType:y,setPaymentElementSelectedType:P,returnToPaymentElementStep:O,onBackFromPaymentElement:D,addressElementKey:N,remountAddressElement:R,clearAddressElement:j}}}