PageSourceSearch

https://www.agentweb.us/assets/PaymentApprove-192aEGe_.js

js agentweb.us collected 2026-09-24 15:15:06 UTC 9,367 bytes, 1 lines download raw bytes

1import{b as Q,u as W,j as e,L as U,a as R}from"./index-DTo46tGQ.js";import{u as D,N as Z,L as x,b as c}from"./react-vendor-CfoRXicY.js";import{O as ee,b as te,r as ae,i as se,P as re,l as ne,g as _,a as ie}from"./PhaseTrail-D1yP-1z9.js";import{B as ce,b as oe}from"./constants-B3Cgb6hO.js";import{D as le}from"./DashboardNav-C4gxbIYk.js";import{S as de}from"./SiteBackdrop-B8eImwDW.js";import"./SiteNav-BOhzn1AE.js";const he=["purchase","passkey","confirm"],pe={loading:-1,ready:-1,creating:0,verifying:1,confirming:2,done:3,error:-1},b="aw-mono text-[11px] uppercase tracking-[0.14em] text-white/50";function ke(){Q({title:"Approve purchase",description:"Confirm the exact amount and merchant, then approve the purchase with your passkey."});const{session:a,loading:r}=W(),o=D();return r?e.jsx(M,{children:e.jsxs("div",{className:"flex items-center gap-2.5 text-sm text-white/60",children:[e.jsx(U,{className:"h-4 w-4 shrink-0 animate-spin text-white/45","aria-hidden":!0}),"Loading…"]})}):a?e.jsx(M,{children:e.jsx(ee,{apiKey:oe,environment:ce,theme:te,children:e.jsx(me,{token:a.access_token})})}):e.jsx(Z,{to:`/login?next=${encodeURIComponent(o.pathname+o.search)}`,replace:!0})}function M({children:a}){return e.jsxs("div",{className:"relative flex min-h-screen flex-col overflow-x-clip text-white xl:pl-48",children:[e.jsx(de,{}),e.jsx(le,{}),e.jsxs("main",{className:"relative z-10 mx-auto w-full max-w-3xl flex-1 px-5 pb-20 pt-6 sm:px-6 sm:pt-8 lg:px-8",children:[e.jsx(x,{to:"/dashboard/settings?tab=agent-pay",className:"aw-mono rounded text-xs text-white/50 transition-colors hover:text-white",children:"← Agent Pay"}),e.jsx("p",{className:"aw-eyebrow mt-7",children:"Agent spending · Passkey-secured"}),e.jsx("h1",{className:"mt-3 text-[32px] leading-[1.05] text-white",children:"Approve a purchase"}),e.jsx("p",{className:"mt-2.5 max-w-[52ch] text-sm leading-relaxed text-white/70",children:"Check the merchant and the exact amount, then approve with your passkey. Your agent can only spend what you approve here."}),e.jsx("div",{className:"mt-8",children:a})]})]})}const ue=new Set(["settled","declined","expired","failed"]);function me({token:a}){const{ready:r,verifyInstruction:o}=ae(),S=D(),f=c.useMemo(()=>new URLSearchParams(S.search),[S.search]),d=f.get("purchase_id"),w=fe(f.get("amount_cents")),C=f.get("merchant"),E=(f.get("currency")??"USD").toUpperCase(),h=!d&&w!==null,[l,i]=c.useState("loading"),[y,p]=c.useState(""),[q,$]=c.useState(!1),[s,A]=c.useState(null),[v,B]=c.useState(null),[u,T]=c.useState(""),[O,Y]=c.useState(0),[k,F]=c.useState(null),L=l==="creating"||l==="verifying"||l==="confirming",j=c.useCallback(t=>{se(t)?($(!0),p("")):p(t instanceof Error?t.message:String(t)),i("error")},[]);c.useEffect(()=>{let t=!1;async function n(){try{const[{methods:m},g]=await Promise.all([ne(a),d?_(a,d):Promise.resolve(null)]);if(t)return;B(m);const N=m.filter(P=>P.status==="active").map(P=>P.id);N.length>0&&T(N[0]),g?(A(g.purchase),i(g.purchase.status==="approved"?"done":"ready")):i("ready")}catch(m){t||j(m)}}return n(),()=>{t=!0}},[a,d,O,j]);function z(){p(""),i("loading"),Y(t=>t+1)}async function H(){if(!s||!v)return;const t=v.find(n=>n.id===s.method_id);if(!s.provider_order_id||!(t!=null&&t.provider_agent_id)){p("This purchase has no verifiable payment instruction. Ask your agent to request the checkout again."),i("error");return}p("");try{i("verifying"),await o(t.provider_agent_id,s.provider_order_id),i("confirming");const{purchase:n}=await _(a,s.id);if(A(n),n.status!=="approved")throw new Error(`The purchase is ${n.status}, not approved. The passkey verification did not complete.`);R("purchase_approved"),i("done")}catch(n){j(n)}}async function K(){if(!(!u||w===null)){p("");try{let t=k&&k.methodId===u?k:null;if(!t){i("creating");const{agentId:m,instructionId:g,purchaseId:N}=await ie(a,{methodId:u,amountCents:w,currency:E,merchant:C??void 0});t={methodId:u,agentId:m,instructionId:g,purchaseId:N},F(t)}if(i("verifying"),await o(t.agentId,t.instructionId),i("confirming"),!t.purchaseId)throw new Error("The purchase was verified but no purchase id came back. Contact support.");const{purchase:n}=await _(a,t.purchaseId);if(A(n),n.status!=="approved")throw new Error(`The purchase is ${n.status}, not approved. The passkey verification did not complete.`);R("purchase_approved"),i("done")}catch(t){j(t)}}}if(l==="loading")return e.jsxs("div",{className:"aw-card flex items-center gap-2.5 px-5 py-4 text-sm text-white/60",children:[e.jsx(U,{className:"h-4 w-4 shrink-0 animate-spin text-white/45","aria-hidden":!0}),"Loading purchase…"]});if(q)return e.jsx("div",{className:"aw-card px-5 py-5",children:e.jsxs("p",{className:"text-sm leading-relaxed text-white/70",children:["Agent payments require a paid plan. Upgrade on"," ",e.jsx(x,{to:"/pricing",className:"text-white underline underline-offset-2",children:"pricing"})," ","to approve purchases."]})});if(!d&&!h)return e.jsx("div",{className:"aw-card border-dashed px-5 py-5",children:e.jsxs("p",{className:"text-sm leading-relaxed text-white/60",children:["Nothing to approve. Open this page from the approval link your agent gives you, or manage your cards at"," ",e.jsx(x,{to:"/dashboard/settings?tab=agent-pay",className:"text-white underline underline-offset-2",children:"Agent Pay"}),"."]})});if(d&&!s||!v)return e.jsxs("div",{className:"aw-card space-y-4 px-5 py-5",children:[e.jsx("p",{className:"text-sm leading-relaxed text-white/70",children:"Could not load this purchase. The link may be wrong or expired."}),y&&e.jsx("p",{className:"text-sm text-red-400",role:"alert",children:y}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",onClick:z,className:"aw-btn aw-btn-primary",children:"Retry"}),e.jsx(x,{to:"/dashboard/settings?tab=agent-pay",className:"aw-btn aw-btn-ghost",children:"Agent Pay"})]})]});const G=s&&ue.has(s.status),V=s?s.amount_cents:w??0,X=s?s.currency:E,J=(s?s.merchant:C)??"unknown merchant",I=(v??[]).filter(t=>t.status==="active");return e.jsxs("div",{className:"aw-card space-y-4 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:l==="done"?"Purchase approved":"Approve this purchase"}),e.jsx(re,{steps:he,activeIndex:pe[l]})]}),e.jsxs("dl",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("dt",{className:b,children:"Merchant"}),e.jsx("dd",{className:"aw-mono text-sm text-white",children:J})]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("dt",{className:b,children:"Amount"}),e.jsx("dd",{className:"aw-mono aw-tabular text-sm font-medium text-white",children:ge(V,X)})]}),s&&e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("dt",{className:b,children:"Purchase id"}),e.jsx("dd",{className:"aw-mono aw-tabular break-all text-right text-xs text-white/70",children:s.id})]})]}),l==="done"?e.jsx("p",{className:"text-xs leading-relaxed text-white/60",children:h&&s?"Done. Give your agent this purchase id so it can complete the checkout.":"Done. Return to your agent; it can now complete the checkout with this purchase id."}):G?e.jsxs("p",{className:"text-sm text-white/70",children:["This purchase is ",e.jsx("span",{className:"aw-mono",children:s.status})," and can no longer be approved. Ask your agent to request the checkout again."]}):e.jsxs(e.Fragment,{children:[h&&I.length===0&&e.jsxs("p",{className:"text-sm leading-relaxed text-white/70",children:["You have no active card to pay with. Add one at"," ",e.jsx(x,{to:"/dashboard/settings?tab=agent-pay",className:"text-white underline underline-offset-2",children:"Agent Pay"}),", then reopen this link."]}),h&&I.length>1&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"approveMethod",className:b,children:"Pay with"}),e.jsx("select",{id:"approveMethod",value:u,onChange:t=>T(t.target.value),disabled:L,className:"aw-mono h-10 w-full rounded-lg border border-white/[0.07] bg-white/[0.04] px-3 text-sm text-white",children:I.map(t=>e.jsxs("option",{value:t.id,className:"bg-[#0B0F17]",children:[t.card_brand||t.network||"Card"," •••• ",t.card_last4??"••••"]},t.id))})]}),e.jsx("p",{className:"aw-mono text-[11px] leading-relaxed text-white/40",children:"Approving lets your agent pay exactly this amount at this merchant, and nothing else. Your per-purchase and daily caps still apply."}),y&&e.jsx("p",{className:"text-sm text-red-400",role:"alert",children:y}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",onClick:h?K:H,disabled:L||!r||h&&!u,className:"aw-btn aw-btn-primary",children:xe(l,r)}),e.jsx(x,{to:"/dashboard/settings?tab=agent-pay",className:"aw-btn aw-btn-ghost",children:"Cancel"})]})]})]})}function xe(a,r){if(!r)return"Initializing…";switch(a){case"creating":return"Preparing…";case"verifying":return"Confirm with passkey…";case"confirming":return"Confirming…";case"done":return"Done ✓";default:return"Approve with passkey"}}function ge(a,r){const o=(a/100).toFixed(2);return r.toUpperCase()==="USD"?`$${o}`:`${o} ${r.toUpperCase()}`}function fe(a){if(!a)return null;const r=Number.parseInt(a,10);return Number.isInteger(r)&&r>0?r:null}export{ke 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.