PageSourceSearch

https://harbor-os.com/assets/TestAuthorizeNet-Cj90MWjh.js

js harbor-os.com collected 2026-09-24 14:45:29 UTC 19,278 bytes, 1 lines download raw bytes

1import{r as l,j as e,U as ie,bz as oe,c1 as de,gb as Z,I as me,ay as xe,a1 as he}from"./vendor-BeA4siBz.js";import{C as b,a as j,b as N,c as q,g as S,d as f,B as I,I as z,af as ue,f as G}from"./index-C2NQ_9nj.js";import{L as y}from"./label-BgiDwF3G.js";import{S as pe}from"./switch-D4mtp9yh.js";function fe(){var $,U,K;const[v,D]=l.useState(!1),[p,W]=l.useState(!1),[E,_]=l.useState(null),[x,L]=l.useState(null),[i,J]=l.useState(null),[c,T]=l.useState({number:"",expiry:"",cvv:""}),[m,h]=l.useState(null),[w,R]=l.useState(!1),[r,g]=l.useState(null),[C,M]=l.useState(!1),H=l.useRef(!1),Q=l.useRef(!1),P=async()=>{D(!0),_(null);try{const s=await(await G("GET",`/api/authorizenet/test?sandbox=${p}`)).json();L(s),s.details&&_(s.details)}catch(a){L({success:!1,message:a instanceof Error?a.message:"Unknown error"})}finally{D(!1)}};l.useEffect(()=>{P()},[]),l.useEffect(()=>{fetch("/api/pos/payment-config").then(a=>a.json()).then(a=>{var t;if(J(a),H.current)return;H.current=!0;const n=((t=a==null?void 0:a.authorizenet)==null?void 0:t.sandbox)===!0?"https://jstest.authorize.net/v1/Accept.js":"https://js.authorize.net/v1/Accept.js",o=document.createElement("script");o.src=n,o.async=!0,o.onload=()=>{Q.current=!0},document.head.appendChild(o)}).catch(()=>{})},[]);const ee=a=>a.replace(/\D/g,"").slice(0,16).replace(/(.{4})/g,"$1 ").trim(),se=a=>{const s=a.replace(/\D/g,"").slice(0,4);return s.length>=3?`${s.slice(0,2)}/${s.slice(2)}`:s},O=()=>new Promise((a,s)=>{if(!window.Accept)return s(new Error("Accept.js not loaded yet — wait a moment and try again"));const n=i==null?void 0:i.authorizenet;if(!(n!=null&&n.apiLoginId)||!(n!=null&&n.publicClientKey))return s(new Error("Payment config not loaded"));const o=c.number.replace(/\s/g,""),[t,A]=c.expiry.split("/");if(!o||o.length<13)return s(new Error("Enter a valid card number"));if(!t||!A||A.length!==2)return s(new Error("Enter expiry as MM/YY"));if(!c.cvv||c.cvv.length<3)return s(new Error("Enter a 3–4 digit CVV"));const te={authData:{clientKey:n.publicClientKey,apiLoginID:n.apiLoginId},cardData:{cardNumber:o,month:t,year:`20${A}`,cardCode:c.cvv}};window.Accept.dispatchData(te,u=>{var B,F,X,Y;if(u.messages.resultCode==="Error"){const ce=((F=(B=u.messages.message)==null?void 0:B[0])==null?void 0:F.text)||"Tokenization failed",le=((Y=(X=u.messages.message)==null?void 0:X[0])==null?void 0:Y.code)||"";s(new Error(`[${le}] ${ce}`))}else a({descriptor:u.opaqueData.dataDescriptor,value:u.opaqueData.dataValue})})}),ae=async()=>{R(!0),h(null),g(null);try{const{descriptor:a,value:s}=await O();h({ok:!0,message:"✅ Tokenization succeeded — Accept.js encrypted the card successfully",token:`${s.substring(0,16)}...${s.slice(-8)} (${s.length} chars)`,descriptor:a})}catch(a){h({ok:!1,message:a.message})}finally{R(!1)}},re=async()=>{var a;M(!0),h(null),g(null);try{const{descriptor:s,value:n}=await O();h({ok:!0,message:"✅ Tokenization succeeded — submitting $1.00 test charge…",token:`${n.substring(0,16)}...${n.slice(-8)} (${n.length} chars)`,descriptor:s});const t=await(await G("POST","/api/authorizenet/test-charge-opaque",{opaqueDataDescriptor:s,opaqueDataValue:n,sandbox:((a=i==null?void 0:i.authorizenet)==null?void 0:a.sandbox)===!0})).json();g({ok:t.success,message:t.message,raw:t,code:t.responseCode,cvv:t.cvvResultCode,avs:t.avsResultCode,transactionId:t.transactionId})}catch(s){g({ok:!1,message:s.message})}finally{M(!1)}},d=E==null?void 0:E.credentials;function k({fieldName:a,data:s}){var t;if(!s)return null;const n=(t=s.match)==null?void 0:t.includes("DIFFERENT"),o=!!s.warning;return e.jsxs("div",{className:`rounded-lg border p-3 space-y-1.5 text-xs ${o||n?"border-red-300 bg-red-50":"border-gray-200 bg-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-semibold text-gray-800",children:a}),s.match&&e.jsx(S,{variant:"outline",className:n?"text-red-700 border-red-300 bg-red-50":"text-green-700 border-green-300 bg-green-50",children:s.match})]}),e.jsxs("div",{className:"space-y-1 pl-1 text-gray-600",children:[e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{className:"text-gray-400 shrink-0",children:"App is using:"}),e.jsx("code",{className:"font-mono",children:s.active||s.active===0?s.active:"—"})]}),s.hs3Value!==void 0&&e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{className:"text-gray-400 shrink-0",children:"HS3_ secret:"}),e.jsx("code",{className:"font-mono",children:s.hs3Value})]}),s.baseValue!==void 0&&e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{className:"text-gray-400 shrink-0",children:"Base secret:"}),e.jsx("code",{className:"font-mono",children:s.baseValue})]}),s.hs3Set!==void 0&&e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{className:"text-gray-400 shrink-0",children:"HS3_ set:"}),e.jsx("span",{children:s.hs3Set?"✅ yes":"❌ no"})]})]}),s.warning&&e.jsx("div",{className:"mt-1 p-2 bg-red-100 text-red-800 rounded text-xs font-medium",children:s.warning})]})}const V=($=i==null?void 0:i.authorizenet)==null?void 0:$.sandbox,ne=V===!0?"SANDBOX":V===!1?"PRODUCTION":"…";return e.jsxs("div",{className:"container mx-auto py-8 max-w-3xl space-y-4",children:[e.jsxs(b,{children:[e.jsx(j,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(N,{children:"Authorize.NET API Test"}),e.jsx(q,{children:"Verify credentials and test card tokenization end-to-e
1nd"})]}),e.jsx(S,{variant:"outline",className:p?"text-amber-700 border-amber-300 bg-amber-50":"text-green-700 border-green-300 bg-green-50",children:p?"Sandbox Mode":"Production Mode"})]})}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{id:"sandbox-mode",checked:p,onCheckedChange:W}),e.jsx(y,{htmlFor:"sandbox-mode",children:"Use Sandbox (sandbox.authorize.net)"})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:P,disabled:v,children:[e.jsx(ie,{className:`h-4 w-4 mr-2 ${v?"animate-spin":""}`}),v?"Testing…":"Test Connection"]})]}),x&&e.jsxs("div",{className:`p-4 rounded-lg flex items-start gap-3 ${x.success?"bg-green-50 text-green-800 border border-green-200":"bg-red-50 text-red-800 border border-red-200"}`,children:[x.success?e.jsx(oe,{className:"h-5 w-5 mt-0.5 text-green-600 shrink-0"}):e.jsx(de,{className:"h-5 w-5 mt-0.5 text-red-600 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:x.success?"✅ Connection Successful":"❌ Connection Failed"}),e.jsx("p",{className:"text-sm mt-0.5",children:x.message})]})]}),d&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-700",children:"Credential sources"}),e.jsx(S,{variant:"outline",className:(U=d.resolvedEnvironment)!=null&&U.includes("Sandbox")?"text-amber-700 border-amber-300 bg-amber-50":"text-green-700 border-green-300 bg-green-50",children:d.resolvedEnvironment})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"Shows first 8 + last 4 chars. All three must be from the same Authorize.NET account."}),e.jsx(k,{fieldName:"API Login ID",data:d.loginId}),e.jsx(k,{fieldName:"Transaction Key",data:d.transactionKey}),e.jsx(k,{fieldName:"Public Client Key",data:d.publicClientKey}),d.sandbox&&e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-3 text-xs space-y-1",children:[e.jsx("span",{className:"font-semibold text-gray-800",children:"Sandbox flag"}),e.jsxs("div",{className:"pl-1 space-y-1 text-gray-600",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-400",children:"HS3_ value:"}),e.jsx("code",{children:d.sandbox.hs3Value})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-400",children:"Base value:"}),e.jsx("code",{children:d.sandbox.baseValue})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-400",children:"Resolved:"}),e.jsx("code",{children:d.sandbox.resolved})]})]})]})]})]})]}),e.jsxs(b,{className:"border-blue-200",children:[e.jsxs(j,{className:"pb-3",children:[e.jsxs(N,{className:"text-base flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5 text-blue-600"}),"Live Accept.js Tokenization Test"]}),e.jsxs(q,{children:["Bypasses the checkout form entirely. Enter real card details to test tokenization directly. Environment: ",e.jsx("span",{className:"font-semibold",children:ne}),((K=i==null?void 0:i.authorizenet)==null?void 0:K.apiLoginId)&&e.jsxs(e.Fragment,{children:[" · Login ID: ",e.jsxs("span",{className:"font-mono font-semibold",children:[i.authorizenet.apiLoginId.substring(0,4),"***"]}
1)]})]})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-amber-50 border border-amber-200 text-xs text-amber-800",children:[e.jsx("strong",{children:"Admin only."})," These fields are for diagnostics — results are shown only in this browser tab. The card data is sent directly to Authorize.NET's servers via Accept.js and never touches your server unencrypted."]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{className:"text-xs",children:"Card Number"}),e.jsx(z,{value:c.number,onChange:a=>T(s=>({...s,number:ee(a.target.value)})),placeholder:"4111 1111 1111 1111",maxLength:19,className:"font-mono",autoComplete:"cc-number"}),c.number.replace(/\s/g,"").length>=4&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Ending in ",e.jsx("span",{className:"font-mono font-semibold",children:c.number.replace(/\s/g,"").slice(-4)})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{className:"text-xs",children:"Expiry (MM/YY)"}),e.jsx(z,{value:c.expiry,onChange:a=>T(s=>({...s,expiry:se(a.target.value)})),placeholder:"MM/YY",maxLength:5,className:"font-mono",autoComplete:"cc-exp"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(y,{className:"text-xs",children:["CVV ",e.jsx("span",{className:"text-muted-foreground font-normal",children:"(shown for verification)"})]}),e.jsx(z,{value:c.cvv,onChange:a=>T(s=>({...s,cvv:a.target.value.replace(/\D/g,"").slice(0,4)})),placeholder:"123",maxLength:4,className:"font-mono",autoComplete:"cc-csc",type:"text",inputMode:"numeric"}),c.cvv&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.cvv.length," digit",c.cvv.length!==1?"s":""," entered"]})]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(I,{variant:"outline",size:"sm",onClick:ae,disabled:w||C,children:[e.jsx(me,{className:"h-4 w-4 mr-2"}),w?"Tokenizing…":"Tokenize Only (no charge)"]}),e.jsxs(I,{size:"sm",onClick:re,disabled:w||C,className:"bg-blue-600 hover:bg-blue-700",children:[e.jsx(Z,{className:"h-4 w-4 mr-2"}),C?"Charging…":"Tokenize + Charge $1.00 (real charge)"]})]}),m&&e.jsxs("div",{className:`p-3 rounded-lg text-sm border space-y-1.5 ${m.ok?"bg-green-50 border-green-200 text-green-800":"bg-red-50 border-red-200 text-red-800"}`,children:[e.jsx("p",{className:"font-semibold",children:m.ok?"Accept.js":"❌ Tokenization Error"}),e.jsx("p",{children:m.message}),m.token&&e.jsxs("div",{className:"text-xs mt-1 space-y-0.5",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-gray-500",children:"Descriptor:"})," ",e.jsx("code",{className:"font-mono",children:m.descriptor})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-gray-500",children:"Token:"})," ",e.jsx("code",{className:"font-mono",children:m.token})]})]})]}),r&&e.jsxs("div",{className:`p-3 rounded-lg text-sm border space-y-2 ${r.ok?"bg-green-50 border-green-200 text-green-800":"bg-red-50 border-red-200 text-red-800"}`,children:[e.jsx("p",{className:"font-semibold",children:r.ok?"✅ Charge Approved":"❌ Charge Failed"}),e.jsx("p",{children:r.message}),e.jsxs("div",{className:"text-xs space-y-1 pt-1 border-t border-current/10",children:[r.transactionId&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 shrink-0",children:"Transaction ID:"}),e.jsx("code",{className:"font-mono",children:r.transactionId})]}),r.code&&e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"text-gray-500 shrink-0",children:"Error code:"}),e.jsxs("span",{className:"font-mono font-semibold",children:[r.code,r.code==="2"&&e.jsx("span",{className:"font-normal ml-1",children:"— Declined by issuer (insufficient funds, card blocked, or card type not enabled)"}),r.code==="28"&&e.jsx("span",{className:"font-normal ml-1",children:"— Merchant does not accept this card type (AMEX not enabled on your account)"}),r.code==="44"&&e.jsx("span",{className:"font-normal ml-1",children:"— Invalid CVV. For AMEX, use the 4-digit CID printed on the front of the card, not the 3-digit code on the back."}),r.code==="6"&&e.jsx("span",{className:"font-normal ml-1",children:"— Invalid card number"}),r.code==="7"&&e.jsx("span",{className:"font-normal ml-1",children:"— Expired card"}),r.code==="8"&&e.jsx("span",{className:"font-normal ml-1",children:"— Expiration date mismatch"}),r.code==="17"&&e.jsx("span",{className:"font-normal ml-1",children:"— Card type not accepted by merchant"}),r.code==="27"&&e.jsx("span",{className:"font-normal ml-1",children:"— AVS mismatch — billing address doesn't match card records"}),r.code==="65"&&e.jsx("span",{className:"font-normal ml-1",children:"— Transaction declined — exceeds frequency limit"}),r.code==="127"&&e.jsx("span",{className:"font-normal ml-1",children:"— Payment processor unavailable — try again shortly"})]})]}),r.cvv&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 shrink-0",children:"CVV result:"}),e.jsxs("span",{className:"font-mono",children:[r.cvv,r.cvv==="M"&&" — Match ✅",r.cvv==="N"&&" — Mismatch ❌ (wrong security code)",r.cvv==="P"&&" — Not processed",r.cvv==="S"&&" — CVV not supported by issuer",r.cvv==="U"&&" — Unavailable"]})]}),r.avs&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-gray-500 shrink-0",children:"AVS result:"}),e.jsx("code",{className:"font-mono",children:r.avs})]}),!r.ok&&c.number.replace(/\s/g,"").startsWith("3")&&e.jsxs("div",{className:"mt-2 p-2 bg-amber-50 border border-amber-200 rounded text-amber-800",children:[e.jsx("strong",{children:"AMEX card detected."})," To charge AMEX you need to:",e.jsxs("ol",{className:"list-decimal pl-4 mt-1 space-y-0.5",children:[e.jsx("li",{children:"Enable American Express in your Authorize.NET account → Settings → Payment Methods"}),e.jsxs("li",{children:["Enter the ",e.jsx("strong",{children:"4-digit CID"})," printed on the ",e.jsx("em",{children:"front"})," of the card (not the 3-digit code on the back)"]})]}),e.jsx("p",{className:"mt-1",children:"To confirm, try again with a Visa or Mastercard — those work without additional setup."})]})]}),r.raw&&e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-gray-500 hover:text-gray-700",children:"Full raw response"}),e.jsx("pre",{className:"mt-1 overflow-auto bg-white/60 rounded p-2 text-gray-700 max-h-48",children:JSON.stringify(r.raw,null,2)})]})]})]})]}),e.jsxs(b,{className:"border-amber-200 bg-amber-50",children:[e.jsx(j,{className:"pb-3",children:e.jsxs(N,{className:"text-amber-900 flex items-center gap-2 text-base",children:[e.jsx(xe,{className:"h-5 w-5"}),"How to fix authentication errors"]})}),e.jsxs(f,{className:"text-sm text-amber-900 space-y-3",children:[e.jsxs("p",{children:["All three secrets must be from the ",e.jsx("strong",{children:"same account and same environment"})," (all sandbox or all production)."]}),e.jsxs("ol",{className:"list-decimal pl-5 space-y-1.5",children:[e.jsxs("li",{children:["Log in to ",e.jsx("a",{href:"https://account.authorize.net",target:"_blank",rel:"noopener",className:"underline",children:"account.authorize.net"})]}),e.jsxs("li",{children:["Account → API Credentials & Keys → copy ",e.jsx("strong",{children:"API Login ID"})," → ",e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"HS3_AUTHORIZENET_API_LOGIN_ID"})]}),e.jsxs("li",{children:["Generate new ",e.jsx("strong",{children:"Transaction Key"})," → ",e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"HS3_AUTHORIZENET_TRANSACTION_KEY"})]}),e.jsxs("li",{children:["Account → Manage Public Client Key → copy → ",e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"HS3_AUTHORIZENET_PUBLIC_CLIENT_KEY"})]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Delete"})," the bare ",e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"AUTHORIZENET_PUBLIC_CLIENT_KEY"})," secret (without the ",e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"HS3_"}),' prefix) if it exists — its presence causes the "DIFFERENT" warning even when your HS3_ value is correct']}),e.jsxs("li",{children:["Set ",e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"HS3_AUTHORIZENET_SANDBOX"})," to ",e.jsx("code",{className:"bg-amber-100 px-1 rounded",children:"false"})," for production"]}),e.jsx("li",{children:"Redeploy and re-run this test"})]}),e.jsxs("div",{className:"mt-2 p-3 rounded-lg bg-white/60 border border-amber-300 space-y-1.5",children:[e.jsx("p",{className:"font-semibold",children:"Testing with AMEX?"}),e.jsxs("ul",{className:"list-disc pl-4 space-y-1",children:[e.jsx("li",{children:"AMEX must be explicitly enabled: Authorize.NET → Settings → Payment Form → Payment Methods → check American Express"}),e.jsxs("li",{children:["AMEX security code is a ",e.jsx("strong",{children:"4-digit CID on the front"})," of the card — ",e.jsx("em",{children:"not"})," the 3-digit code on the back"]}),e.jsx("li",{children:"To confirm everything works before enabling AMEX, test with a Visa or Mastercard first"})]})]})]})]}),e.jsxs(b,{children:[e.jsx(j,{className:"pb-3",children:e.jsx(N,{className:"text-base",children:"Required Secrets"})}),e.jsx(f,{children:e.jsx("div",{className:"space-y-2 text-sm",children:[{key:"HS3_AUTHORIZENET_API_LOGIN_ID",desc:"API 
1Login ID from Authorize.NET dashboard"},{key:"HS3_AUTHORIZENET_TRANSACTION_KEY",desc:"Transaction Key from Authorize.NET dashboard"},{key:"HS3_AUTHORIZENET_PUBLIC_CLIENT_KEY",desc:"Public Client Key from Authorize.NET dashboard"},{key:"HS3_AUTHORIZENET_SANDBOX",desc:'Set to "true" for sandbox, "false" or unset for production'}].map(({key:a,desc:s})=>e.jsxs("div",{className:"flex items-start gap-3 p-2 rounded bg-gray-50 border",children:[e.jsx("code",{className:"text-xs font-mono bg-gray-200 px-1.5 py-0.5 rounded shrink-0",children:a}),e.jsx("span",{className:"text-gray-600 text-xs",children:s})]},a))})}),e.jsx(ue,{className:"pt-0",children:e.jsxs("a",{href:"https://account.authorize.net",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline flex items-center gap-1",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"Open Authorize.NET Dashboard"]})})]})]})}export{fe 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.