{"release_id":"01a247c3-a6b6-0000-74b2-4a83f2c91090","chunk_id":"01a247c3-a6eb-7593-baa6-33b448d51dd9","file":"B2Bgcy6g.mjs","mappings":"8ZAoBA,eAAsBA,EAAmBC,EAAmBC,EAA2C,CACtGC,EAAmBC,EAAcH,EAAI,OAAQ,CAAC,CAACC,EAAE,MAAM,EAAGG,EAAaJ,CAAG,EAAG,UAAUA,EAAI,EAAE,IAAIC,EAAE,MAAM,EAAE,EAC3G,GAAI,CACH,MAAMI,EAAM,MAAM,MAAM,uBAAwB,CAC/C,OAAQ,OACR,QAAS,CAAE,eAAgB,kBAAA,EAC3B,KAAM,KAAK,UAAU,CACpB,UAAWL,EAAI,GACf,YAAaC,EAAE,YACf,WAAYA,EAAE,YAAc,GAAG,SAAS,QAAQ,iBAChD,OAAQA,EAAE,MAAA,CACV,CAAA,CACD,EACKK,EAAI,MAAMD,EAAI,KAAA,EACpB,GAAIA,EAAI,IAAMC,EAAE,IACf,cAAO,SAAS,KAAOA,EAAE,IAClB,EAET,MAAQ,CAER,CACA,MAAO,EACR","names":["startTokenCheckout","pkg","o","trackPurchaseClick","withPlusBonus","packUsdPrice","res","j"],"sources":["../../../../../../src/lib/token-checkout.ts"],"sourcesContent":["// Start a Stripe checkout for one token pack: the shared body of BuyTokensModal's buy() and the sculpt\n// unlock sheet's one-tap pack. A navigation, so no user activation is needed after the await (iOS ok).\nimport { trackPurchaseClick } from '$lib/analytics';\nimport { packUsdPrice } from '$lib/pricing-display';\nimport { withPlusBonus } from '$lib/pro-plan';\nimport type { TokenPackage } from '$lib/token-packages';\n\nexport interface TokenCheckoutOptions {\n\t/** where Stripe returns on success (the server falls back to the profile balance) */\n\tsuccessPath?: string;\n\t/** Stripe's back button; defaults to this page with ?canceled=true */\n\tcancelPath?: string;\n\t/** the surface, forwarded to checkout and analytics */\n\tsource: string;\n\t/** Plus members get the bonus server-side: track the granted count */\n\tisPlus?: boolean;\n}\n\n/** Fetch the checkout url and go there. Resolves false when it could not start (the caller re-enables\n *  its button); on success the page is already navigating away. */\nexport async function startTokenCheckout(pkg: TokenPackage, o: TokenCheckoutOptions): Promise<boolean> {\n\ttrackPurchaseClick(withPlusBonus(pkg.tokens, !!o.isPlus), packUsdPrice(pkg), `tokens_${pkg.id}_${o.source}`);\n\ttry {\n\t\tconst res = await fetch('/api/checkout/tokens', {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'content-type': 'application/json' },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tpackageId: pkg.id,\n\t\t\t\tsuccessPath: o.successPath,\n\t\t\t\tcancelPath: o.cancelPath ?? `${location.pathname}?canceled=true`,\n\t\t\t\tsource: o.source\n\t\t\t})\n\t\t});\n\t\tconst j = await res.json();\n\t\tif (res.ok && j.url) {\n\t\t\twindow.location.href = j.url;\n\t\t\treturn true;\n\t\t}\n\t} catch {\n\t\t/* fall through */\n\t}\n\treturn false;\n}\n"],"version":3}