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