1 line
3.6 KiB
JavaScript
1 line
3.6 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[44],{3402:function(e,t,n){Promise.resolve().then(n.bind(n,3611))},3611:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return u}});var c=n(7437),o=n(2265),a=n(9376),r=n(4604),s=n(8672);let i="pk_live_51SqANn1rqkv2RWz2gkUOO02pZMWvIRQZvfQv4lsFI7voNTUqDNhPa49K32bZ8P4gi8fnCvNdWGoQUZfgCWc7pYBB00UOsEtw91";i||console.error("Missing NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY. Add it to your environment for Stripe.js.");let l=i?(0,s.J)(i):null;function d(e){var t;let{accountId:n,product:a}=e,s=(0,r.MD)(),i=(0,r.lq)(),[l,d]=(0,o.useState)(""),[u,p]=(0,o.useState)(!1);async function m(e){if(e.preventDefault(),!s||!i)return;p(!0),d("");let t=await s.confirmPayment({elements:i,confirmParams:{return_url:"".concat(window.location.origin,"/success")}});t.error&&d(t.error.message||"Payment failed."),p(!1)}return(0,c.jsxs)("form",{className:"payment-form",onSubmit:m,children:[(0,c.jsx)("h2",{children:a.name}),(0,c.jsx)("p",{className:"payment-muted",children:a.description||"No description provided."}),(0,c.jsx)("div",{className:"payment-price",children:(null===(t=a.default_price)||void 0===t?void 0:t.unit_amount)?"".concat((a.default_price.unit_amount/100).toFixed(2)," ").concat(a.default_price.currency.toUpperCase()):"No price"}),(0,c.jsx)("div",{className:"payment-section",children:(0,c.jsx)(r.Wd,{})}),(0,c.jsx)("div",{className:"payment-section",children:(0,c.jsx)(r.Hn,{})}),(0,c.jsx)("button",{className:"btn",type:"submit",disabled:!s||u,children:u?"Processing...":"Pay now"}),l?(0,c.jsx)("div",{className:"connect-message",children:l}):null]})}function u(e){let{params:t}=e,{accountId:n}=t,s=(0,a.useSearchParams)().get("productId"),[i,u]=(0,o.useState)(null),[p,m]=(0,o.useState)(""),[f,h]=(0,o.useState)(""),[v,N]=(0,o.useState)(""),j=(0,o.useMemo)(()=>p?{clientSecret:p}:null,[p]);return((0,o.useEffect)(()=>{if(!s){h("Missing productId in URL.");return}n&&window.localStorage.setItem("connectStoreSlug",n),async function(){h("");try{var e,t;let c=await fetch("/api/connect/account/lookup?slug=".concat(n)),o=await c.json();if(!c.ok)throw Error(o.error||"Store not found");N(o.accountId);let a=await fetch("/api/connect/products/get?accountId=".concat(o.accountId,"&productId=").concat(s)),r=await a.json();if(!a.ok)throw Error(r.error||"Failed to load product");u(r.product);let i=null===(t=r.product)||void 0===t?void 0:null===(e=t.default_price)||void 0===e?void 0:e.id;if(!i)throw Error("Product does not have a default price.");let l=await fetch("/api/connect/payment-intent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountId:o.accountId,priceId:i})}),d=await l.json();if(!l.ok)throw Error(d.error||"Failed to create payment intent");m(d.clientSecret)}catch(e){h(e.message||"Failed to initialize checkout.")}}()},[n,s]),l)?(0,c.jsx)("main",{className:"storefront-page",children:(0,c.jsx)("section",{className:"section",children:(0,c.jsxs)("div",{className:"container storefront-page__inner",children:[(0,c.jsx)("h1",{className:"page-title",children:"Card Checkout"}),(0,c.jsxs)("p",{className:"storefront-muted",children:["Store: ",n]}),f?(0,c.jsx)("div",{className:"connect-message",children:f}):null,i&&j?(0,c.jsx)(r.eK,{stripe:l,options:j,children:(0,c.jsx)(d,{accountId:v,product:i})}):null]})})}):(0,c.jsx)("main",{className:"storefront-page",children:(0,c.jsx)("section",{className:"section",children:(0,c.jsx)("div",{className:"container storefront-page__inner",children:(0,c.jsx)("div",{className:"connect-message",children:"Missing `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY`."})})})})}}},function(e){e.O(0,[274,971,117,744],function(){return e(e.s=3402)}),_N_E=e.O()}]); |