1import{e as P,u as j,r as p,j as e,P as I,bB as N,bC as k}from"./index-D1aKNduO.js";import{p as E}from"./pure-CSzON2Ea.js";import{E as _,u as C,a as F,P as v}from"./react-stripe.esm-CJsfUwAF.js";import{c as B,t as A}from"./firebase-DGovvYsO.js";import{f as R}from"./priceFormatting-BRJIJJ2C.js";import"./index-HYYaAa2z.js";import"./index-Chjiymov.js";const M=new Map,b=new Map,g="Payment configuration is currently unavailable. Please try again in a few minutes.";function d(t){return typeof t=="string"?t.trim():""}function x(t){const n=typeof t=="number"?t:Number(t);return Number.isFinite(n)?Math.round(n):0}function K(t){if(!t||typeof t!="object")throw new Error("Unexpected payment response payload.");const n=t,r=n.data,s=n.paymentSession,c=[n];r&&typeof r=="object"&&c.push(r),s&&typeof s=="object"&&c.push(s);const o=c.find(u=>d(u.clientSecret)||d(u.publishableKey))??n,a=d(o.clientSecret),i=d(o.publishableKey),l=d(o.paymentIntentId);if(!a)throw new Error("Payment session is missing client secret.");if(!i)throw new Error(g);return{clientSecret:a,paymentIntentId:l,publishableKey:i,researcherStripeAccountId:d(o.researcherStripeAccountId),amountMinor:x(o.amountMinor),platformFeeMinor:x(o.platformFeeMinor),transferAmountMinor:x(o.transferAmountMinor),currency:d(o.currency).toUpperCase()||"USD"}}function U(t,n){return`${t}:${n}`}async function $(t,n){const r=U(t,n),s=M.get(r);if(s)return s;const c=b.get(r);if(c)return c;const o=B(),i=A(o,"accept_bid_callable")({requestId:t,bidId:n}).then(l=>{const u=K(l.data);return M.set(r,u),u}).finally(()=>{b.delete(r)});return b.set(r,i),i}function D({amountMinor:t,platformFeeMinor:n,transferAmountMinor:r,currency:s}){const{t:c,i18n:o}=j(),a=i=>R(i,s,o.language);return e.jsxs("div",{className:"rounded-lg border border-gray-200 p-4 text-sm space-y-2 mb-4",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-600",children:c("checkout.researcher_receives")}),e.jsx("span",{className:"font-medium",children:a(r)})]}),e.jsxs("div",{className:"flex justify-between text-gray-400",children:[e.jsx("span",{children:c("checkout.platform_fee")}),e.jsx("span",{children:a(n)})]}),e.jsxs("div",{className:"flex justify-between font-semibold border-t pt-2",children:[e.jsx("span",{children:c("checkout.total")}),e.jsx("span",{children:a(t)})]})]})}function O({requestId:t,bidId:n}){const r=C(),s=F(),{t:c}=j(),[o,a]=p.useState(!1),[i,l]=p.useState(null),u=async f=>{if(f.preventDefault(),!(!r||!s)){a(!0),l(null);try{const{error:h}=await r.confirmPayment({elements:s,confirmParams:{return_url:`${window.location.origin}/payment-success?requestId=${encodeURIComponent(t)}&bidId=${encodeURIComponent(n)}`}});h&&(l(h.message??c("checkout.payment_failed")),a(!1))}catch{l(c("checkout.payment_failed")),a(!1)}}};return e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsx(v,{}),i&&e.jsx("p",{className:"text-sm text-red-500",children:i}),e.jsx("button",{type:"submit",disabled:!r||o,className:"w-full bg-blue-600 text-white py-2.5 rounded-lg font-medium hover:bg-blue-700 disabled:opacity-50",children:c(o?"common.loading":"checkout.pay_now")})]})}function J(){const{requestId:t,bidId:n}=P(),{t:r}=j(),[s,c]=p.useState(null),[o,a]=p.useState(null),[i,l]=p.useState(null),u=p.useRef(null);return p.useEffect(()=>{if(!t||!n)return;let f=!1;return(async()=>{try{const m=await $(t,n),y=m.publishableKey.trim();if(!y||!y.startsWith("pk_"))throw new Error(g);const w=await E.loadStripe(y);if(!w)throw new Error(g);if(f)return;if(c(m),a(Promise.resolve(w)),u.current!==m.paymentIntentId){u.current=m.paymentIntentId;const S={currency:m.currency,product_type:"document_request",value:m.amountMinor/100};N(S),k(m.paymentIntentId,S)}}catch(m){if(f)return;l(m.message)}})(),()=>{f=!0}},[t,n]),i?e.jsx("div",{className:"max-w-md mx-auto mt-16 text-center",children:e.jsx("p",{className:"text-red-500",children:i})}):!s||!o?e.jsx("div",{className:"flex h-screen items-center justify-center",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-blue-500 border-t-transparent"})}):e.jsxs(e.Fragment,{children:[e.jsx(I,{title:r("checkout.page_title"),description:r("checkout.page_description")}),e.jsxs("div",{className:"max-w-md mx-auto mt-10 p-6 rounded-2xl border border-gray-200 bg-white shadow-sm",children:[e.jsx("h1",{className:"text-xl font-semibold mb-4",children:r("checkout.page_title")}),e.jsx(D,{amountMinor:s.amountMinor,platformFeeMinor:s.platformFeeMinor,transferAmountMinor:s.transferAmountMinor,currency:s.currency}),e.jsx(_,{stripe:o,options:{clientSecret:s.clientSecret},children:e.jsx(O,{requestId:t,bidId:n})})]})]})}export{J as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.