!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e.SENTRY_RELEASE={id:"substack@538433c"};var t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="9575deed-8554-43b8-a3b6-5186c05e3c73",e._sentryDebugIdIdentifier="sentry-dbid-9575deed-8554-43b8-a3b6-5186c05e3c73")}catch(e){}}();"use strict";(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["56787"],{34206:function(e,t,r){r.d(t,{Ay:()=>b});var s=r(99851),n=r(69277),o=r(70408),i=r(32641),a=r(4006),p=r(32485),l=r.n(p),d=r(17402),u=r(84565),c=r(86500),h=r(94729),m=r(63136),y=r(82776);class _ extends d.Component{componentDidMount(){!this.props.disabled&&(this.props.element&&this.props.element.mount(this.elementContainer),this.props.addressElement&&this.props.addressElement.mount(this.addressContainer))}componentDidUpdate(e){this.props.disabled||(this.props.element&&!e.element&&this.props.element.mount(this.elementContainer),this.props.addressElement&&!e.addressElement&&this.props.addressElement.mount(this.addressContainer))}componentWillUnmount(){try{this.props.element&&this.props.element.unmount(this.elementContainer),this.props.addressElement&&this.props.addressElement.unmount(this.addressContainer)}catch(e){}}render(){let{className:e,element:t,isPaymentElement:r,addressElement:s,disabled:n}=this.props;return t||r?(0,a.FD)("div",{className:l()("fancy-stripe",e,{"payment-element":r}),children:[s&&(0,a.Y)("div",{ref:this.assignAddressContainer,style:{paddingBottom:"24px"}}),(0,a.Y)("div",{ref:this.assignElementContainer}),n&&(0,a.Y)(m.EY.B4,{translated:!0,color:"error",children:"This type of purchase is currently unavailable in your region."})]}):null}constructor(...e){super(...e),(0,s._)(this,"elementContainer",void 0),(0,s._)(this,"addressContainer",void 0),(0,s._)(this,"assignElementContainer",e=>{this.elementContainer=e}),(0,s._)(this,"assignAddressContainer",e=>{this.addressContainer=e})}}class f extends d.Component{async componentDidMount(){let e=!1;if(this.state.paymentRequest){try{let t=await this.state.paymentRequest.canMakePayment();t&&t.applePay&&(e=!0)}catch(e){console.error(e)}(0,c.u4)(c.qY.APPLE_PAY_SETUP_FINISHED,{success:e})}if(await this.setState({canMount:e}),e){if(this.button||await new Promise(e=>setTimeout(e,0)),!this.state.stripeButton)return void console.error("stripeButton not ready");if(this.state.stripeButton.mount(this.button),!this.state.paymentRequest)return void console.error("paymentRequest not ready");this.state.paymentRequest.on("token",e=>this.onTokenReceived(e)),this.state.paymentRequest.update({currency:this.props.plan.currency,total:this.getPaymentTotal()})}else this.props.onVisibilityChanged&&this.props.onVisibilityChanged(!1)}componentDidUpdate(e){let t=!1;for(let n of["pub","plan","quantity","coupon","notRecurring","variableAmount"]){var r,s;if(e[n]!==this.props[n]||"coupon"===n&&e[n]&&(null==(r=e[n])?void 0:r.loading)&&(!this.props[n]||!(null==(s=this.props[n])?void 0:s.loading))){t=!0;break}}t&&this.state.paymentRequest&&this.state.paymentRequest.update({currency:this.props.plan.currency,total:this.getPaymentTotal()})}componentWillUnmount(){if(this.state.paymentRequest&&this.state.paymentRequest.off("token"),this.state.stripeButton)try{this.state.stripeButton.unmount(this.button)}catch(e){}}async onTokenReceived(e){(0,c.u4)(c.qY.APPLE_PAY_ATTEMPED);try{if(!this.props.onSuccess)return void console.error("No onSuccess handler for Apple Pay");await this.props.onSuccess({email:e.payerEmail,name:e.payerName,stripe_token:e.token}),e.complete("success"),(0,c.u4)(c.qY.APPLE_PAY_SUCCEEDED)}catch(t){console.error("Apple Pay submission failed:",e,t),e.complete("fail"),(0,c.u4)(c.qY.APPLE_PAY_FAILED,{reason:t.message})}}getPaymentTotal(){var e,t,r,s;let n,{pub:o,plan:i,quantity:a,coupon:p,notRecurring:l,variableAmount:d}=this.props,u=0,c=Math.max(0,("trial_period_days"in i?i.trial_period_days:null)||0,p&&!p.error&&!p.loading&&p.trial_period_days||0,o.trial_end_override&&Math.ceil((o.trial_end_override-Date.now()/1e3)/60/60/24));l&&(c=0);let h=("metadata"in i&&(null==(e=i.metadata)?void 0:e.founding)?null!=(t=d||i.amount)?t:0:null!=(r=i.amount)?r:0)*(a||1),m=h;return p&&!p.error&&!p.loading&&(p.percent_off?m=Math.round(m*(1-(p.percent_off_precise||p.percent_off)/100)):p.amount_off&&(m=Math.max(0,m-p.amount_off)),m<=0&&(m=h,"once"===p.duration?"year"===i.interval?u+=12*i.interval_count:u+=i.interval_count:"repeating"===p.duration&&(u+=null!=(s=p.duration_in_months)?s:0))),l?n="one-time":(n="".concat(this.props.plan.interval,"ly"),this.props.quantity>1&&(n+=" per person"),u?(c>15&&(u+=Math.floor(c/30)),n+=" with ".concat(u,"-month trial")):c&&(n+=" with ".concat(c,"-day trial"))),{label:n,amount:m}}render(){var e;let{children:t,className:r,error:s}=this.props,{canMount:n}=null!=(e=this.state)?e:{};return void 0===n||n||"undefined"==typeof window?(0,a.FD)("div",{className:"apple-pay-parent-container",children:[n?(0,a.Y)("div",{className:"apple-pay-element ".concat(r||""),ref:this.assignButton}):(0,a.Y)("p",{className:"apple-pay-loader ".concat(r||""),children:"Loading…"}),s&&(0,a.Y)("div",{className:"error",children:s}),t]}):null}constructor(e,t){if(super(e,t),(0,s._)(this,"button",void 0),(0,s._)(this,"assignButton",e=>{this.button=e}),e.stripe&&e.pub.stripe_country){(0,c.u4)(c.qY.APPLE_PAY_SETUP_STARTED);try{const t=e.stripe.paymentRequest({country:this.props.pub.stripe_country,currency:this.props.plan.currency,total:this.getPaymentTotal(),requestPayerName:!0,requestPayerEmail:!0}),r=e.stripe.elements().create("paymentRequestButton",{paymentRequest:t});this.state={paymentRequest:t,stripeButton:r}}catch(e){console.error(e),(0,c.u4)(c.qY.APPLE_PAY_SETUP_FINISHED,{success:!1})}}}}class E extends d.Component{render(){let e=this.props,{children:t,ref:r,defaultValue:s}=e,o=(0,i._)(e,["children","ref","defaultValue"]);return this.state,(0,a.FD)("div",{className:"fancy-input",children:[(0,a.Y)("input",(0,n._)({ref:this.assignInput,defaultValue:s},o)),t]})}blur(){this._input&&this._input.blur()}constructor(...e){super(...e),(0,s._)(this,"_input",void 0),(0,s._)(this,"assignInput",e=>{this._input=e})}}class g extends d.Component{getInputs(){let e=[];if(this.base)for(let t of Array.from(this.base.getElementsByTagName("*")))["INPUT","TEXTAREA","SELECT"].includes(t.nodeName)&&t.getAttribute("name")&&"g-recaptcha-response"!==t.id&&e.push(t);return e}resetErrors(){this.setState({_paramErrors:{},_otherErrors:[]})}clear(){for(let e of(this.resetErrors(),this.getInputs()))e.blur&&e.blur(),"checkbox"===e.type?e.checked=!1:"select"===e.type?e.selectedIndex=-1:"radio"===e.type?e.checked=!1:"target"in e&&e.target?e.target.value="":e.value=""}handleStripeChange(e){let{error:t}=e;t?this.setState({_stripeError:t.message}):this.setState({_stripeError:null})}componentDidMount(){this._mountTime=new Date,this._stripeCardOrPaymentElement&&this._stripeCardOrPaymentElement.addEventListener("change",e=>this.handleStripeChange(e))}componentDidUpdate(e){let{country:t,currency:r,email:s,name:o,pub:i,stripeClientSecret:a,stripeElementAppearance:p,themeVariables:l,useStripePaymentElement:d,enableLink:u}=this.props;if(d){var c,h;if(e.useStripePaymentElement||(null==(c=this._stripeCardOrPaymentElement)||c.destroy(),this._stripeCardOrPaymentElement=null),a!==e.stripeClientSecret)if(a){this.setState({loading:!0});let e=this.props.isPlatformCustomer?this._stripe:this._connectedStripe;if(!e)return void console.error("Stripe instance not available in componentDidUpdate");({elements:this._stripeElements,addressElement:this._stripeAddressElement,paymentElement:this._stripeCardOrPaymentElement}=function(e,t){let{withAddressElement:r=!1,currency:s,email:o,name:i,country:a,stripeElementAppearance:p={},themeVariables:{color_theme_accent:l,color_theme_bg_contrast_1:d,print_on_pop:u,print_on_web_bg_color:c,print_secondary_on_web_bg_color:h}={},enableLink:m=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},y={clientSecret:t,currency:s,appearance:(0,n._)({theme:"flat",variables:{borderRadius:"8px",colorBackground:d||void 0,colorPrimary:l||"rgb(255, 103, 25)",accessibleColorOnColorPrimary:u||void 0,colorText:c||void 0,colorTextPlaceholder:h||void 0,colorTextSecondary:h||void 0}},p),locale:window._preloads&&window._preloads.language||"auto"},_=e.elements(y);return{elements:_,addressElement:r?_.create("address",{mode:"billing",defaultValues:{name:i,address:{country:a}}}):void 0,paymentElement:_.create("payment",{layout:{type:"tabs",defaultCollapsed:!1},defaultValues:{billingDetails:{email:o,name:i,address:{country:a}}},wallets:{link:m?"auto":"never"},terms:{card:"never",applePay:"never",googlePay:"never"}})}}(e,a,{withAddressElement:(null==i?void 0:i.stripe_country)==="IN",currency:r,email:s,name:null!=o?o:void 0,country:t,stripeElementAppearance:p,themeVariables:l,enableLink:u})),this.setState({loading:!1})}else e.stripeClientSecret&&(null==(h=this._stripeCardOrPaymentElement)||h.destroy(),this._stripeCardOrPaymentElement=null)}}componentWillUnmount(){this._stripeCardOrPaymentElement&&this._stripeCardOrPaymentElement.destroy()}onInputBlur(e){this.props.analyticsName&&this._mountTime&&new Date().getTime()-this._mountTime.getTime()>1e3&&e.target&&e.target.value&&!e.target._blurTracked&&((0,c.u4)("".concat(this.props.analyticsName," Input Filled"),{name:e.target.name}),e.target._blurTracked=!0)}async onPaymentRequestAttempt(e){let t=await this.handleSubmitAsync(null,e);if(t)throw t}handleSubmit(e){e&&e.preventDefault(),this.handleSubmitAsync(e).catch(e=>{console.error(e)})}async handleSubmitAsync(e){let t,r,s,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e&&e.preventDefault(),this.props.analyticsName&&(0,c.u4)("".concat(this.props.analyticsName," Submit Pressed")),this.props.loading||this.state.loading||this.props.disableSubmit)return;this.resetErrors(),this.setState({loading:!0});let i=null;if(this.stripeElement&&!o.stripe_token&&!this.props.useStripePaymentElement){let{token:e=null,error:t}=this._stripe?await this._stripe.createToken(this._stripeCardOrPaymentElement):{error:{message:""}};if(e)i=e;else{this.setState({loading:!1,_stripeError:t&&t.message}),this.props.analyticsName&&(console.log("error",t),(0,c.u4)("".concat(this.props.analyticsName," Missing Payment"),{type:t&&t.type,code:t&&t.code,decline_code:t&&t.decline_code,reason:t&&t.message}));return}}if(this.stripeElement&&this.props.useStripePaymentElement){var a,p,l,d=this;if(t=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d.props.isPlatformCustomer?d._stripe:d._connectedStripe;return t?d._stripeElements?t.confirmSetup({elements:d._stripeElements,redirect:"if_required",confirmParams:e}):void console.error("Stripe elements not available"):void console.error("Stripe instance not available")},!this.props.performSubmit){let{setupIntent:e}=await t();if(!e)return void this.setState({loading:!1});r=e.payment_method}}let u={};for(let e of this.getInputs())if(e.blur&&e.blur(),"checkbox"==e.type)u[e.name]=!!e.checked;else if("radio"==e.type)e.checked&&(u[e.name]=e.value);else if("select"===e.type){let t=e.options[e.selectedIndex];t?u[e.name]=t.value:console.error("No selected option in select element")}else u[e.name]=e.value;if(Object.keys(o).forEach(e=>{!u[e]&&o[e]&&(u[e]=o[e])}),i?u.stripe_token=i:r&&(u.paymentMethodId=r),this.props.prepareData)try{let t=await this.props.prepareData(u,e);t&&(u=t)}catch(e){throw this.setState({loading:!1}),e}this.props.onChangeLoadingState&&this.props.onChangeLoadingState(!0);try{this.props.performSubmit?s=this.props.useStripePaymentElement?await this.props.performSubmit(u,{confirmSetup:t}):await this.props.performSubmit(u):this.props.action?s=this.props.method&&"get"===this.props.method?{body:await (0,h.x6)(this.props.action,{query:u,method:this.props.method})}:{body:await (0,h.x6)(this.props.action,{json:u,method:this.props.method||"POST"})}:this.props.onSubmit&&this.props.onSubmit(u)}catch(t){let e=t.response&&t.response.body instanceof ReadableStream;t.response&&t.body&&e?t.response={body:t.body,status:null==(p=t.response)?void 0:p.status}:t.response&&t.body&&!t.response.body&&(t.response.body=t.body),n=t}if((null==s||null==(a=s.body)?void 0:a.confirmPaymentUrl)&&s.body.clientSecret&&this._connectedStripe){(0,c.u4)(c.qY.PAYMENT_CONFIRMATION_STARTED);let e=await this._connectedStripe.confirmCardPayment(s.body.clientSecret);if(e.error){(0,c.u4)(c.qY.PAYMENT_CONFIRMATION_FAILED,{error:null==(l=e.error)?void 0:l.message});let t={error:e.error.message||"Failed to confirm payment"};n={response:{body:t,text:JSON.stringify(t)}}}else(0,c.u4)(c.qY.PAYMENT_CONFIRMATION_SUCCEEDED)}if(this.setState({loading:!1}),this.props.onChangeLoadingState&&this.props.onChangeLoadingState(!1),n){if(this.processErrors(n.response),this.props.onError&&this.props.onError(n,u),!n.response)throw n}else this.props.onSuccess&&this.props.onSuccess(s,u);return n}processErrors(e){let t={},r=[];if(e&&e.body&&e.body.errors){let s=this.getInputs();e.body.errors.forEach(e=>{!0!==this.props.noInlineErrors&&e.param&&s.filter(t=>t.getAttribute("name")===e.param).length>0?t[e.param]?(console.log("Discarding repeated error"),console.log(e)):t[e.param]=e:r.push(e)})}else e&&e.body&&"string"==typeof e.body.error?r.push({msg:e.body.error}):r.push({msg:"Something went wrong"});this.setState({_paramErrors:t,_otherErrors:r}),this.props.analyticsName&&(0,c.u4)("".concat(this.props.analyticsName," Error"),{paramErrors:JSON.stringify(t),otherErrors:JSON.stringify(r)})}render(){var e;let t=this.props,r=null!=(e=this.state)?e:{},s=t.autoLock&&r.loading||t.loading,i=!1,p=!1,u=t.getConfigFor("disable_card_element_in_europe")&&!t.useStripePaymentElement&&t.pub&&y.EEA_COUNTRIES.includes(t.pub.stripe_country)&&(!t.currency||"eur"===t.currency),c=e=>{let h=[];return d.Children.toArray(e).forEach(e=>{if(!e)return null;if("object"==typeof e&&(e.type===E||"input"===e.type||"textarea"===e.type||"select"===e.type)&&e.props&&"name"in e.props&&e.props.name){let t=e.props.name;if(h.push((0,d.cloneElement)(e,{disabled:s||"disabled"in e.props&&e.props.disabled,onChange:t=>{let r=e.props&&"onChange"in e.props&&e.props.onChange||e.props&&"onInput"in e.props&&e.props.onInput;r&&"function"==typeof r&&r(t),this.props.onChange&&this.props.onChange(t)},onInput:t=>{e.props&&"onInput"in e.props&&e.props.onInput&&"function"==typeof e.props.onInput&&e.props.onInput(t),this.props.onInput&&this.props.onInput(t)},onBlur:t=>{this.onInputBlur(t),e.props&&"onBlur"in e.props&&e.props.onBlur&&"function"==typeof e.props.onBlur&&e.props.onBlur(t)}})),r._paramErrors[null!=t?t:"undefined"]&&!s){let e=r._paramErrors[null!=t?t:"undefined"];if(!e)return void console.error("No error for",t);e.msgHTML?h.push((0,a.Y)("div",(0,o._)((0,n._)({className:"error"},t&&{name:t}),{dangerouslySetInnerHTML:{__html:e.msgHTML}}))):h.push((0,a.Y)("div",(0,o._)((0,n._)({className:"error"},t&&{name:t}),{children:e.msg||"Invalid"})))}}else if("object"==typeof e&&e.props&&"type"in e.props&&"submit"===e.props.type)h.push((0,d.cloneElement)(e,{disabled:s||"disabled"in e.props&&e.props.disabled,loading:s||"loading"in e.props&&e.props.loading,onClick:t=>{e.props&&"onClick"in e.props&&e.props.onClick&&"function"==typeof e.props.onClick&&!1!==e.props.onClick(t)&&this.handleSubmit(t)}}));else if("object"==typeof e&&e.props&&"id"in e.props&&"error-container"===e.props.id){if(r._otherErrors&&!s){let t=r._otherErrors.map(e=>e.msgHTML?(0,a.Y)("div",{className:"error other-error",dangerouslySetInnerHTML:{__html:e.msgHTML}}):(0,a.Y)("div",{className:"error other-error",children:e.msg})).concat(e.props&&e.props.children?d.Children.toArray(e.props.children):[]);h.push((0,d.cloneElement)(e,{},t))}}else if("object"==typeof e&&"type"in e&&e.type===_){if(i)throw Error("Can only handle one stripe element");i=!0,h.push((0,d.cloneElement)(e,{ref:t=>{e.props&&e.props.ref&&e.props.ref(t),this.stripeElement=t},element:this._stripeCardOrPaymentElement,isPaymentElement:this.props.useStripePaymentElement,addressElement:this._stripeAddressElement,disabled:u})),!r._stripeError&&this._stripeCardOrPaymentElement||s||"undefined"==typeof window||h.push((0,a.Y)("div",{className:l()("error",t.stripeErrorClassName),role:"alert",children:r._stripeError||"Stripe payments not loaded. Are there blocked scripts?"}))}else if("object"==typeof e&&"type"in e&&e.type===f){if(p)throw Error("Can only handle one stripe payment request button");p=!0,h.push((0,d.cloneElement)(e,{ref:t=>{e.props&&e.props.ref&&e.props.ref(t),this.stripePaymentRequestButton=t},stripe:this._stripe,onSuccess:t=>(e.props&&"onSuccess"in e.props&&e.props.onSuccess&&"function"==typeof e.props.onSuccess&&e.props.onSuccess(t),this.onPaymentRequestAttempt(t))}))}else"object"==typeof e&&"props"in e&&e.props&&e.props.children?h.push((0,d.cloneElement)(e,{},c(e.props.children))):h.push(e)}),h};return(0,a.Y)("form",(0,o._)((0,n._)({className:"form ".concat(t.className||""),action:t.noJsAction||t.action,method:t.method&&["get","post"].includes(t.method.toLowerCase())&&t.method.toLowerCase()||"post",autoComplete:t.autoComplete,onSubmit:e=>this.handleSubmit(e),noValidate:!0},t.enctype&&{enctype:t.enctype},t.id&&{id:t.id}),{children:c(t.children)}))}constructor(e,t){super(e,t),(0,s._)(this,"_stripe",void 0),(0,s._)(this,"_connectedStripe",void 0),(0,s._)(this,"_stripeCardOrPaymentElement",void 0),(0,s._)(this,"_mountTime",void 0),(0,s._)(this,"_stripeElements",void 0),(0,s._)(this,"_stripeAddressElement",void 0),(0,s._)(this,"stripeElement",void 0),(0,s._)(this,"stripePaymentRequestButton",void 0),this.state={_paramErrors:{},_otherErrors:[],_stripeError:null,loading:!1},this.props.stripe_publishable_key&&(this._stripe=function(e,t){if("undefined"==typeof window||void 0===window.Stripe)return null;let r={};return t&&t.stripe_user_id?y.NO_PLATFORM_CUSTOMER_CLONE_COUNTRIES.includes(t.stripe_country)&&(r.stripeAccount=t.stripe_user_id):console.warn("No publication passed for Stripe connection"),window.Stripe(e,r)}(this.props.stripe_publishable_key,this.props.pub),this._stripe)&&(this.props.useStripePaymentElement||(this._stripeCardOrPaymentElement=this._stripe.elements({locale:window._preloads&&window._preloads.language||"auto"}).create("card",{style:{base:{fontSize:"14px",lineHeight:"40px",fontFamily:'-apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'}},disableLink:!0})),this._connectedStripe=function(e,t){if("undefined"==typeof window||void 0===window.Stripe||!(null==t?void 0:t.stripe_user_id))return null;let r={stripeAccount:t.stripe_user_id};return window.Stripe(e,r)}(this.props.stripe_publishable_key,this.props.pub))}}let b=(0,u.yq)(g)}}]);