Loading
function(e,t,n){"use strict";n.d(t,{b:()=>L});var l=n(627968),i=n(64700),s=n(284009),r=n.n(s),a=n(17928),o=n(529427),u=n(655857),c=n(480642),d=n(211159),m=n(166532),h=n(482132),p=n(97352),f=n(526151),g=n(599669),E=n(303557),A=n(753390),C=n(606267),x=n(364995),I=n(666646),_=n(566980),S=n(216641),y=n(174459),v=n(428262),T=n(20654),N=n(652215),j=n(788868),b=n(375708),R=n(327105),P=n(469633);function L(e){let{handleStepChange:t,handleClose:n,analyticsData:s}=e,{guildId:L,paymentModalArgs:M,premiumSubscriptionPaymentSourceId:O}=(0,f.Oe)(),{activeSubscription:w,paymentSourceId:k,setPaymentSourceId:D}=(0,d.t4)(e=>({activeSubscription:e.activeSubscription,paymentSourceId:e.paymentSourceId,setPaymentSourceId:e.setPaymentSourceId})),{displayCurrency:U}=(0,u.Jn)();if(null==L)throw new o.vd({message:"Missing guildId"});r()(null!=U&&""!==U,"Currency not defined");let{paymentSources:G}=M,{newAdditionalPlans:F,currentPremiumSubscriptionPlan:V}=(0,E.l)(),B=(0,a.bG)([p.A],()=>null==V?p.A.get(P.Z):V);r()(null!=B,"Missing nextPremiumSubscriptionPlan");let H=null!=k?{paymentSourceId:k,currency:U}:{currency:U},W=function(e){let{handleStepChange:t,handleClose:n,analyticsData:l}=e,{guildId:s,paymentModalArgs:a,premiumSubscriptionPaymentSourceId:o,numGuildBoostsToPurchase:c,analyticsLocation:h,analyticsSourceLocation:p,flowStartTime:g,applicationId:P,intent:L,onSubscribeComplete:M}=(0,f.Oe)(),{displayCurrency:O}=(0,u.Jn)(),{paymentSources:w,setIsSubmittingCurrentStep:k,isSubmittingCurrentStep:D}=a,{activeSubscription:U,paymentSourceId:G,setPurchaseError:F,hasAcceptedTerms:V,setPurchaseState:B}=(0,d.t4)(e=>({activeSubscription:e.activeSubscription,paymentSourceId:e.paymentSourceId,setPurchaseError:e.setPurchaseError,hasAcceptedTerms:e.hasAcceptedTerms,setPurchaseState:e.setPurchaseState})),H=(0,I.sw)(),{newAdditionalPlans:W,currentPremiumSubscriptionPlan:K,premiumGuildSubscriptionPlanId:Y}=(0,E.l)(),z=(0,C.A)({location:"GuildBoostPurchaseModal",message:b.intl.string(R.default["tK8A/8"])}),{checkoutPaymentSources:Z}=(0,x.t)(),q=(0,C.iB)({checkoutPaymentSources:Z,paymentSourceId:G,location:"GuildBoostPurchaseModal"}),$=i.useMemo(()=>({...l,location:h,source:p,subscription_plan_id:Y,sku_id:(0,v.mH)(j.pe.GUILD),quantity:c}),[l,h,p,c,Y]),J=i.useMemo(()=>{let{guild_id:e,...t}=$;return t},[$]),[X,Q]=i.useState(!1),ee=null!=G?{paymentSourceId:G,currency:O??void 0}:{currency:O??void 0},et=async()=>{r()(null!=W,"Missing newAdditionalPlans");let e=(0,S.W)(w,G);F(null);try{B(_.h.PURCHASING),k(!0),r()(null!=G,"Missing paymentSourceId"),r()(null!=H,"Missing invoicePreview");let i={amount:H.total,currency:H.currency},a=ee.currency??H.currency,u=(0,v.U8)(U,W,a.toLowerCase(),ee.paymentSourceId);if(y.default.track(N.HAw.PAYMENT_FLOW_COMPLETED,{...$,duration_ms:Date.now()-g,guild_id:s??void 0,application_id:P}),X)return;if(null==U||null==K){r()(null!=e,"Missing paymentSource");let t=await (0,A.Ky)({items:W,paymentSource:e,currency:a,expectedInvoicePrice:i,expectedRenewalPrice:u});if(t.redirectConfirmation)return void Q(null!=t.redirectURL)}else{let t={items:(0,v.aE)(U,W)};t.currency=U.currency??a,t.paymentSource=null!=o?w[o]:void 0,null==t.paymentSource&&(r()(null!=e,"Missing paymentSource"),t.paymentSource=e,t.currency=a);let n=await (0,A.nV)(U,t,i,u,l.location_stack);if(n.redirectConfirmation)return void Q(null!=n.redirectURL)}null==L&&t(m.pn.CONFIRM),B(_.h.COMPLETED),null!=s&&await (0,T.a)(s,null!=L),null!=L&&n(),M?.()}catch(t){B(_.h.FAIL),F(t),y.default.track(N.HAw.PAYMENT_FLOW_FAILED,{...J,payment_error_code:t?.code,payment_gateway:null!=e?e.type===N.hes.CARD?N.kM_.STRIPE:N.kM_.BRAINTREE:null,payment_source_id:G,duration_ms:Date.now()-g})}finally{X||k(!1)}};return{text:b.intl.string(b.t.eUEeCt),loading:D,disabled:null==G||!V||null!=z||q,onClick:et,variant:"active"}}({handleStepChange:t,handleClose:n,analyticsData:s}),K=i.useCallback(()=>{t(m.pn.ADD_PAYMENT_STEPS),D(null)},[t,D]);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(h.dZ,{children:(0,l.jsx)(g.pc,{guildId:L,paymentSources:G,priceOptions:H,currentPremiumSubscription:w,premiumSubscriptionPaymentSourceId:O,premiumSubscriptionPlan:B,newAdditionalPlans:F,paymentSourceId:k,setPaymentSourceId:D,onPaymentSourceAdd:K})}),(0,l.jsx)(h.UX,{children:(0,l.jsx)(c.lo,{onBackClick:()=>t(m.pn.PLAN_SELECT),primaryButtonProps:W})})]})}}