Loading
function(e,t,n){"use strict";n.d(t,{U:()=>w});var l=n(627968),i=n(64700),s=n(284009),r=n.n(s),a=n(228366),o=n(391048),u=n(688810),c=n(11939),d=n(426398),m=n(558620),h=n(427675),p=n(169797),f=n(211159),g=n(380619),E=n(155984),A=n(344159),C=n(367921),x=n(174459),I=n(45938),_=n(428262),S=n(937008),y=n(158032),v=n(830382),T=n(753390),N=n(243217),j=n(652215),b=n(788868);async function R(e){let{onPurchaseAttempt:t,onPurchaseError:n,onPurchaseComplete:l,onPurchaseFinalize:i,hasRedirectURL:s,isGift:a,analyticsLocation:o,analyticsLocations:u,subscriptionPlan:c,planGroup:d,trialId:m,priceOptions:h,paymentSource:p,isPrepaidPaymentPastDue:f,openInvoiceId:g,premiumSubscription:E,onNext:A,metadata:C,sku:x,purchaseType:I,referralCode:S,loadId:R,giftInfoOptions:P,invoicePreview:L,order:M}=e;try{let e,n,i,O;if(t(),s)return;if(I===j.VVm.ONE_TIME)r()(null!=x,"SKU must exist and be fetched."),r()(null!=L,"invoicePreview must exist."),e=await (0,v.XU)(x.applicationId,x.id,{expectedAmount:L.total,expectedCurrency:L.currency,isGift:a,paymentSource:p,loadId:R,giftInfoOptions:P,orderId:M?.id});else{r()(null!=c,"Missing subscriptionPlan"),r()(null!=L,"Missing invoicePreview");let t={amount:L.total,currency:L.currency},n=(0,_.l6)(h,L.checkoutContext?.available_plans),l=(0,_.$Q)((0,_.y8)(c.id,!1,!1,n));if(null!=E){let e=h.currency??L.currency,t=(0,_.Pg)(E,c.id,1,new Set(d));t=(0,_.qn)(t),l=(0,_.UC)(t,e.toLowerCase(),h.paymentSourceId)}if(a){let t=L.total,n=L.currency;e=await (0,v.XU)(b.tv,c.skuId,{expectedAmount:t,expectedCurrency:n,paymentSource:p,subscriptionPlanId:c.id,isGift:!0,loadId:R,giftInfoOptions:P,orderId:M?.id})}else if(f&&null!=g&&null!=p&&null!=E){let n=h.currency??L.currency;e=j.AD1.has(p.type)?await (0,T.LD)(E,g,p,n,R):await (0,T.nV)(E,{paymentSource:p,currency:n},t,l,u,o,R)}else if(null!=E){let n=(0,_.Pg)(E,c.id,1,new Set(d)),i={paymentSource:p,currency:h.currency??L.currency};E.status===j.Dmq.PAUSED&&(i.status=j.Dmq.ACTIVE),E.isPausedAllowsResumeButNotUpdates||(i.items=n),e=await (0,T.nV)(E,i,t,l,u,o,R)}else e=await (0,y.B1)({planId:c.id,currency:h.currency??L.currency,paymentSource:p,trialId:m,metadata:C,referralCode:S,loadId:R,expectedInvoicePrice:t,expectedRenewalPrice:l})}let{shouldReturnEarly:w}=l(e);if(w)return;"subscription"in e?n=null!=e.subscription?N.A.createFromServer(e.subscription):null:"entitlements"in e&&(i=null!=e.entitlements?e.entitlements:void 0),"appliedUserDiscounts"in e&&(O=null!=e.appliedUserDiscounts&&e.appliedUserDiscounts.length>0?e.appliedUserDiscounts:void 0),A(n,i,O)}catch(e){n(e)}finally{i()}}var P=n(166532),L=n(566980),M=n(216641);function O(e){let{showBackButton:t,onBackClick:n}=e,{premiumSubscription:s,isGift:r,planGroup:a,isPrepaid:o}=e,{buttonLabel:u,analyticsLocations:c,application:d,hasAcceptedTerms:m,paymentSourceId:h,activeSubscription:f,devShelfFetchState:g,hasPaymentSources:E}=(0,C.Ke)({premiumSubscription:s,isGift:r,planGroup:a,isPrepaid:o}),A=i.useMemo(()=>(0,C.X1)(e,{buttonLabel:u,analyticsLocations:c,application:d,hasAcceptedTerms:m,paymentSourceId:h,activeSubscription:f,devShelfFetchState:g,hasPaymentSources:E}),[e,u,c,d,m,h,f,g,E]);return(0,l.jsx)(p.lo,{onBackClick:t?n:void 0,primaryButtonProps:A})}function w(e){let{premiumSubscription:t,onBack:n,legalTermsNodeRef:s,flashLegalTerms:p,invoiceError:C,planError:y,baseAnalyticsData:v,flowStartTime:T,trialId:N,planGroup:b=[],analyticsLocation:w,openInvoiceId:k,metadata:D,backButtonEligible:U,disablePurchase:G,isTrial:F=!1,onPaymentSourceAdd:V,handleStepChange:B,postPurchaseStep:H=P.pn.CONFIRM}=e,{selectedSkuId:W,invoicePreview:K,setHasAcceptedTerms:Y,setPurchaseState:z,contextMetadata:Z,paymentSourceId:q,setPurchaseError:$,order:J,priceOptions:X,purchaseType:Q,referralCode:ee,setEntitlementsGranted:et,setAppliedUserDiscounts:en,setUpdatedSubscription:el}=(0,f.t4)(e=>({selectedSkuId:e.selectedSkuId,invoicePreview:e.checkoutInvoicePreview,setHasAcceptedTerms:e.setHasAcceptedTerms,setPurchaseState:e.setPurchaseState,setPurchaseError:e.setPurchaseError,contextMetadata:e.contextMetadata,order:e.order,paymentSourceId:e.paymentSourceId,priceOptions:e.checkoutPriceOptions,purchaseType:e.purchaseType,referralCode:e.referralCode,setEntitlementsGranted:e.setEntitlementsGranted,setAppliedUserDiscounts:e.setAppliedUserDiscounts,setUpdatedSubscription:e.setUpdatedSubscription})),{paymentSources:ei}=(0,d.jm)(),es=(0,m.A)(),er=(0,h.gU)(),{isGift:ea,selectedGiftStyle:eo,customGiftMessage:eu,emojiConfetti:ec,soundEffect:ed,giftRecipient:em,selectedGiftingPromotionReward:eh}=(0,S.Pv)(),ep=(0,g.Mq)(es),ef=(0,I.lo)(em),eg={};eg.gift_style=eo,eg.reward_sku_ids=ep&&null!=eh?[eh]:[],ef===I.tB.CUSTOM_MESSAGE_EMOJI_SOUNDBOARD&&(r()(null!=em,"Gift recipient must be set at purchase review step for these gift options."),eg.recipient_id=em.id,eg.custom_message=eu,eg.emoji_id=ec?.id,eg.emoji_name=ec?.id==null?ec?.surrogates:void 0,eg.sound_id=ed?.soundId);let eE=es?.id,{analyticsLocations:eA}=(0,u.Ay)(),eC=(0,M.W)(ei,q),{giftCardBalance:ex,giftCardCurrency:eI}=(0,c.h)(),[e_,eS]=i.useState(!1),[ey,ev]=i.useState(!1),{hasEntitlements:eT}=(0,A.X)(eE,ea),eN=(0,_.J$)(X.paymentSourceId),ej=(0,E.l)(),eb=null;Q===j.VVm.ONE_TIME&&(r()(null!=W,"SKU must be selected for one-time purchases"),eb=er[W]??null,r()(null!=eb,"SKU must exist and be fetched."));let eR=i.useCallback(()=>{z(L.h.PURCHASING),Y(!0),eS(!0),a.h.wait(o.ET),$(null),x.default.track(j.HAw.PAYMENT_FLOW_COMPLETED,{...v,subtotal:K?.subtotal,tax:K?.tax,expected_amount:K?.total,expected_currency:K?.currency,duration_ms:Date.now()-T,gift_card_balance:ex,gift_card_currency:eI})},[z,Y,$,v,T,K,ex,eI]),eP=i.useCallback(e=>{z(L.h.FAIL),$(e),x.default.track(j.HAw.PAYMENT_FLOW_FAILED,{...v,payment_error_code:e?.code,payment_source_id:eC?.id,payment_source_type:eC?.type,duration_ms:Date.now()-T,gift_card_balance:ex,gift_card_currency:eI})},[z,$,v,T,eC,ex,eI]),eL=i.useCallback(e=>e.redirectConfirmation?(ev(null!=e.redirectURL),{shouldReturnEarly:!0}):(z(L.h.COMPLETED),{shouldReturnEarly:!1}),[z]),eM=i.useCallback(()=>{ey||eS(!1)},[ey]),eO=i.useCallback((e,t,n)=>{let l=e??null;el(l),null!=t&&et(t),null!=n&&en(n),B(H,{fulfillment:{subscription:l,entitlements:t}})},[B,H,el,et,en]);async function ew(){await R({onPurchaseAttempt:eR,onPurchaseError:eP,onPurchaseComplete:eL,onPurchaseFinalize:eM,hasRedirectURL:ey,isGift:ea,analyticsLocation:w,analyticsLocations:eA,subscriptionPlan:es,planGroup:b,trialId:N,priceOptions:X,paymentSource:eC,isPrepaidPaymentPastDue:ej,openInvoiceId:k,premiumSubscription:t,onNext:eO,metadata:D,sku:eb,purchaseType:Q,referralCode:ee,loadId:Z.loadId,giftInfoOptions:eg,invoicePreview:K,order:J})}let ek=null!=k||Q===j.VVm.ONE_TIME&&!ea;return(0,l.jsx)(O,{legalTermsNodeRef:s,invoiceError:C,planError:y,disablePurchase:G,flashLegalTerms:p,isSubmitting:e_,premiumSubscription:t,isGift:ea,planGroup:b,isPrepaid:eN,isTrial:F,makePurchase:ew,needsPaymentSource:null==eC&&!eT,onNext:eO,onPaymentSourceAdd:V,selectedSkuId:W,showBackButton:U&&!ek,onBackClick:n})}}