{"version":3,"file":"AddToOrder.BoAn20mn.mjs","names":["useState","loadStripe","_Fragment"],"sources":["https:/framerusercontent.com/modules/wDzlni5Q6k8p3xHug1cx/QRMVPZctcUQ03ru8ay6X/AddToOrder.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useState}from\"react\";import{loadStripe}from\"@stripe/stripe-js\";// @ts-ignore — Framer provides this at runtime\nimport{addPropertyControls,ControlType}from\"framer\";import{useUpsellStore}from\"https://framerusercontent.com/modules/EjsWQMeQbYXeu6MyNlM1/MDwpB7IzrnCXsZ6NvFH2/UpsellStore.js\";const BASE_URL=\"https://quadhook.medvi.org\";const STRIPE_PUBLISHABLE_KEY=\"pk_live_51QSLPP2euyA8TPKhnsLjsRFvCmKSfA812MmXw79H9EKIaebWZUkBmFdSo3hqoBsV0Pm8q6VIeur7wS67d5z64Su800kYexHjk5\";// \"pk_test_51RnQqGGaogCc5kLtER5YJNooQB6OWftsK7GLCev68Bhrnq5HsOWHP2bSXZJ3rzZqw8l6aRARItRnJoLj3CdWjjd1002rgzkJxI\"\nfunction getProgramType(value){const match=value.match(/upsell-(glp|serm|nad)/);return match?match[1]:null;}export default function AddToOrder(props){const{priceId,medication,buttonText,returnUrlPath}=props;const[store,setStore]=useUpsellStore();const[error,setError]=useState(null);const handleUpsell=async()=>{if(store.isProcessing)return;// already locked\nif(!priceId){setError(\"No price selected.\");return;}const params=new URLSearchParams(window.location.search);const customerId=params.get(\"customer_id\");if(!customerId){setError(\"Something went wrong. Please try again.\");return;}params.set(\"price\",priceId);if(medication){params.set(\"medication\",medication);}const returnUrl=`${BASE_URL}/${returnUrlPath}?${params.toString()}`;setStore({isProcessing:true});setError(null);const program=getProgramType(returnUrlPath);const coupon=params.get(\"whowantsacoupon\");try{const prepareRes=await fetch(`${BASE_URL}/v1/stripe/upsell-prepare`,{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify({customer_id:customerId,price:priceId,program,whowantsacoupon:coupon})});const prepareJson=await prepareRes.json().catch(()=>({}));if(!prepareRes.ok){const msg=prepareJson?.message||prepareJson?.errors?.price?.[0]||prepareJson?.errors?.customer_id?.[0]||`Could not start payment (${prepareRes.status})`;setError(msg);setStore({isProcessing:true});return;}if(!prepareJson?.success||!prepareJson?.data?.clientSecret){setError(prepareJson?.message||\"Invalid response from server (no client secret).\");setStore({isProcessing:true});return;}const stripe=await loadStripe(STRIPE_PUBLISHABLE_KEY);if(!stripe){setError(\"Could not load Stripe.\");setStore({isProcessing:true});return;}const{error:confirmError,paymentIntent}=await stripe.confirmPayment({clientSecret:prepareJson.data.clientSecret,confirmParams:{return_url:returnUrl},redirect:\"if_required\"});if(confirmError){setError(confirmError.message??\"Payment failed.\");setStore({isProcessing:true});return;}// No redirect (e.g. no 3DS challenge): finish on quadhook yourself.\nif(paymentIntent?.status===\"succeeded\"){const done=new URL(returnUrl);done.searchParams.set(\"payment_intent\",paymentIntent.id);done.searchParams.set(\"redirect_status\",\"succeeded\");window.location.href=done.toString();return;}// 3DS or bank flow triggered a full-page redirect; this line may not run.\nsetStore({isProcessing:true});}catch(err){const message=err instanceof Error?err.message:\"Unexpected error\";setError(message);setStore({isProcessing:true});}};return /*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(\"button\",{type:\"button\",onClick:()=>void handleUpsell(),disabled:store.isProcessing,style:{fontFamily:\"'Red Hat Text', 'Red Hat Text Placeholder', sans-serif\",fontSize:\"16px\",backgroundColor:store.isProcessing?\"rgba(0, 117, 41, 0.5)\":\"rgb(0, 117, 41)\",color:\"white\",fontWeight:600,width:\"100%\",height:\"100%\",display:\"flex\",flex:1,flexDirection:\"row\",alignItems:\"center\",justifyContent:\"center\",gap:\"8px\",borderRadius:\"9999px\",paddingLeft:\"24px\",paddingRight:\"24px\",paddingTop:\"12px\",paddingBottom:\"12px\",cursor:store.isProcessing?\"not-allowed\":\"pointer\",border:\"none\",opacity:store.isProcessing?.5:1},children:store.isProcessing?\"Processing...\":buttonText}),error&&/*#__PURE__*/_jsx(\"p\",{style:{marginTop:\"8px\",textAlign:\"center\",fontSize:\"14px\",color:\"rgb(239, 68, 68)\"},children:error})]});}addPropertyControls(AddToOrder,{priceId:{type:ControlType.String,title:\"Price ID\"},medication:{type:ControlType.String,title:\"Medication\"},buttonText:{type:ControlType.String,title:\"Button Text\",defaultValue:\"Add to Order\"},returnUrlPath:{type:ControlType.String,title:\"Return Url Path\",defaultValue:\"upsell-glp\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AddToOrder\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AddToOrder.map"],"mappings":"6SAEA,SAAS,EAAe,EAAM,CAAC,IAAM,EAAM,EAAM,MAAM,uBAAuB,EAAE,OAAO,EAAM,EAAM,GAAG,IAAK,CAAC,SAAwB,EAAW,EAAM,CAAC,GAAK,CAAC,UAAQ,aAAW,aAAW,iBAAe,EAAW,CAAC,EAAM,GAAU,EAAe,EAAO,CAAC,EAAM,GAAUA,EAAS,IAAI,EAAQ,EAAa,SAAS,CAAC,GAAG,EAAM,aAAa,OAC9U,GAAG,CAAC,EAAQ,CAAC,EAAS,oBAAoB,EAAE,MAAO,CAAC,IAAM,EAAO,IAAI,gBAAgB,EAAO,SAAS,MAAM,EAAQ,EAAW,EAAO,IAAI,aAAa,EAAE,GAAG,CAAC,EAAW,CAAC,EAAS,yCAAyC,EAAE,MAAO,CAAC,EAAO,IAAI,QAAQ,CAAO,EAAK,GAAY,EAAO,IAAI,aAAa,CAAU,EAAG,IAAM,EAAU,GAAG,EAAS,GAAG,EAAc,GAAG,EAAO,SAAS,IAAI,EAAS,CAAC,aAAa,EAAI,CAAC,EAAE,EAAS,IAAI,EAAE,IAAM,EAAQ,EAAe,CAAa,EAAQ,EAAO,EAAO,IAAI,iBAAiB,EAAE,GAAG,CA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