[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7347RMTCYY5KZQQFESXX54J":3,"skill-same:01M7347RMTCYY5KZQQFESXX54J":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M7347RMTCYY5KZQQFESXX54J","square-billing-setup",null,"Set up Square card billing (hosted Payment Links) end-to-end for a web store — create and correctly identify Square credentials (App ID vs access token, sandbox vs production), configure env vars and Vercel scopes, set product prices, wire webhooks, and verify with sandbox test cards or a real-card-and-refund. Use when someone says \"set up Square\", \"Square checkout\", \"Square keys\u002Ftoken\", \"Pay by Card not showing\", \"Square UNAUTHORIZED\", \"sandbox test card 4111\", \"checkout failed\", \"Invalid phone\u002Femail on Square\", or is wiring Square payments into a Next.js\u002FVercel storefront.","LiamVisionary\u002Fhivemindos","LiamVisionary","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F102138294?v=4","01M73379NZZ99TT4ZS17XR3Q9D","01M73379PX6AKQNWN05VNSYRXW",13,"MIT","https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fpackaged-skills\u002Foptional\u002Fops\u002Fhivemindos\u002Fsquare-billing-setup\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: square-billing-setup\ndescription: Set up Square card billing (hosted Payment Links) end-to-end for a web store — create and correctly identify Square credentials (App ID vs access token, sandbox vs production), configure env vars and Vercel scopes, set product prices, wire webhooks, and verify with sandbox test cards or a real-card-and-refund. Use when someone says \"set up Square\", \"Square checkout\", \"Square keys\u002Ftoken\", \"Pay by Card not showing\", \"Square UNAUTHORIZED\", \"sandbox test card 4111\", \"checkout failed\", \"Invalid phone\u002Femail on Square\", or is wiring Square payments into a Next.js\u002FVercel storefront.\n---\n\n# Square Billing Setup (Hosted Payment Links)\n\nHow to stand up Square card checkout for a storefront **correctly the first time**, and how to diagnose it when it breaks. Written from a real, painful setup (a furniture storefront built on Next.js and Vercel) where every one of the gotchas below actually bit. The reference implementation shape referred to below: `lib\u002Fpayments.ts`, `app\u002Fapi\u002Fcheckout\u002F*`, `app\u002Fapi\u002Fwebhooks\u002Fsquare\u002Froute.ts`, a `scripts\u002Fsquare-setup.sh` helper, and a `deploy\u002FSQUARE.md` runbook — adapt the paths to your own project.\n\n## The integration model this covers\n\nServer-side **hosted Payment Links** (`POST \u002Fv2\u002Fonline-checkout\u002Fpayment-links`). The app builds a checkout session from the live cart and redirects the buyer to a Square-hosted page (`checkout.square.site\u002F...`). **No card data ever touches the app** (no PCI scope). It authenticates with the **access token alone** — the Square *Application ID* is **not used** by this flow (that's only for the client-side Web Payments SDK, which this model does not use).\n\nThe \"Pay by Card\" option is **env-gated**: the server advertises Square only when its credentials are present. In the reference implementation that gate is:\n```ts\n\u002F\u002F lib\u002Fpayments.ts\nsquare: Boolean(process.env.SQUARE_ACCESS_TOKEN && process.env.SQUARE_LOCATION_ID)\n```\nSo if either var is missing\u002Fempty in the environment serving the page, the buyer sees only fallback methods (Phone \u002F Cash on Delivery) and **no card option**. \"Configuring Square in the dashboard\" is not enough — the running server must have the env vars.\n\n## Credential taxonomy — the #1 source of pain\n\nSquare has several credential strings and they are **not interchangeable**. Getting these wrong causes ~every failure below.\n\n| String | Prefix | What it is | Used by this flow? |\n| --- | --- | --- | --- |\n| Production Access Token | `EAAA…` (~64 chars) | Auth for **production** API (`connect.squareup.com`) | ✅ yes (prod) |\n| Sandbox Access Token | `EAAA…` (~64 chars) | Auth for **sandbox** API (`connect.squareupsandbox.com`) | ✅ yes (sandbox) |\n| Application ID | `sq0idp-…` (prod) \u002F `sandbox-sq0idb-…` | Client-side app identifier | ❌ **NOT used** — do not put this in `SQUARE_ACCESS_TOKEN` |\n| OAuth client secret | `sq0csp-…` | OAuth app secret | ❌ not this flow |\n| Webhook signature key | opaque | HMAC key for webhook verification | ✅ (webhooks only) |\n\n**Critical traps:**\n- **`sq0idp-…` is an Application ID, not an access token.** Pasting it into `SQUARE_ACCESS_TOKEN` makes the gate pass (non-empty) but every Square API call returns `UNAUTHORIZED`. Access tokens start `EAAA…` and are ~64 chars.\n- **Sandbox and production access tokens BOTH start `EAAA…`** — you cannot tell them apart by looking. A **production** token returns `UNAUTHORIZED` against the **sandbox** host, and vice-versa. This is the trap that eats hours: you grab \"the token,\" it looks right, and it's the wrong *environment's* token.\n\n### Where to get each token in the Square Developer Dashboard\n`developer.squareup.com\u002Fapps` → open the application → **toggle the environment selector (top-left) to Sandbox or Production** → left nav **Credentials** → copy the **Access Token** for that environment. The dashboard defaults to **Production**, so the #1 mistake when someone asks for \"the sandbox token\" is handing back the production one because they never flipped the toggle.\n\n### Identify an unknown token (do this before trusting any token)\nTest it against **both** hosts — the one it authenticates on tells you its environment; the location it returns confirms the account:\n```bash\n# production host\ncurl -s https:\u002F\u002Fconnect.squareup.com\u002Fv2\u002Flocations \\\n  -H \"Square-Version: 2026-05-20\" -H \"Authorization: Bearer $TOK\" | jq '.locations[]|{id,name,status} \u002F\u002F .errors'\n# sandbox host\ncurl -s https:\u002F\u002Fconnect.squareupsandbox.com\u002Fv2\u002Flocations \\\n  -H \"Square-Version: 2026-05-20\" -H \"Authorization: Bearer $TOK\" | jq '.locations[]|{id,name,status} \u002F\u002F .errors'\n```\n`UNAUTHORIZED` on one host + a real location list on the other = you now know exactly which environment (and which account) the token belongs to. **Everything except the token is derivable from the token** — you never need to hunt for the location ID by hand.\n\n## Environment variables\n\n| Var | Secret? | Notes |\n| --- | --- | --- |\n| `SQUARE_ACCESS_TOKEN` | **yes** | `EAAA…`, environment-matched (see above) |\n| `SQUARE_LOCATION_ID` | no | derive via `GET \u002Fv2\u002Flocations`. Sandbox default-test-account location ≠ production business location |\n| `SQUARE_ENVIRONMENT` | no | `production` → `connect.squareup.com`; anything else → sandbox host. Must match the token's environment |\n| `SQUARE_VERSION` | no | optional, defaults to a pinned `Square-Version` in code |\n| `SQUARE_WEBHOOK_SIGNATURE_KEY` | **yes** | shown only once at subscription creation |\n| `SQUARE_WEBHOOK_URL` | no | must match the subscription's `notification_url` **exactly** |\n\nExample locations (placeholders — yours will differ, always derive from the token): production `LXXXXXXXXXXXX`, sandbox default-test-account `LYYYYYYYYYYYY`.\n\n**Golden rule:** `SQUARE_ENVIRONMENT` and `SQUARE_ACCESS_TOKEN` must be the **same environment**. `production` + a sandbox token → `UNAUTHORIZED`; `sandbox` + a production token → `UNAUTHORIZED`.\n\n## Deployment on Vercel — the traps that wasted the most time\n\n1. **Env vars bind at BUILD time.** Adding\u002Fchanging a var does **nothing** to an existing deployment. You must **redeploy** after any env change. The currently-live build reads the vars that existed when *it* built.\n2. **Scopes are separate: Production vs Preview vs Development.** A **Preview** deployment does **not** see Production-scoped vars. Convention: Production scope = production creds (`SQUARE_ENVIRONMENT=production`); Preview scope = sandbox creds (`SQUARE_ENVIRONMENT=sandbox`) so branch\u002Fpreview deploys hit the sandbox. If the card tile is missing on a preview URL, its scope probably lacks the vars.\n3. **Combined-scope removal trap.** If a var is attached to `Production, Preview` as one entry, `vercel env rm NAME preview` can remove it from **both** environments — this silently wiped a production token during a \"just change preview\" edit. Keep each environment's value as a **separate** entry; overwrite one scope with `--force`, e.g. `printf '%s' \"$VAL\" | vercel env add NAME preview --force`.\n4. **Sensitive vars are write-only.** `vercel env pull` returns **empty** for sensitive vars, so you can't verify them from the CLI. Add non-secret values (`SQUARE_ENVIRONMENT`, `SQUARE_LOCATION_ID`) with `--no-sensitive` so they're readable\u002Fverifiable; keep the token `--sensitive`.\n5. **Preview URLs sit behind Vercel deployment protection** → `curl` gets a `302`. Verify runtime behavior in a **logged-in browser**, not curl. `vercel env ls` and `vercel inspect \u003Curl>` are your read-only truth for scopes\u002Ftimestamps.\n\nFastest safe path: use `scripts\u002Fsquare-setup.sh \u003Cproduction|sandbox> [notify_url]` — it sets the core vars in the right scope, creates the webhook, and stores the signature key (shown once). Prereqs: `vercel login` + `vercel link`. It prompts for the token hidden (never on disk\u002Fin chat).\n\n**Never accept a secret token through chat** (it gets logged). Have the human paste it via the setup script's hidden prompt, or `pbpaste > file` after copying, then read the file and delete it. Verify the token against the API *before* redeploying so you don't burn a build on a wrong token.\n\n## Setting prices \u002F products\n\n- **Base catalog** lives in code (`data\u002Fproducts.ts`): id, name, price (whole dollars), image, etc.\n- **Live overrides** (price, hide, out-of-stock, badges, featured rank) are DB patches merged in `lib\u002Fcatalog.ts` via the admin API — these take effect **without a redeploy** (`revalidateTag`). Note: a **preview** deployment may have **no DB access** (DB creds are Production-scoped), so on preview you see only the in-code base prices; add\u002Fchange items in `data\u002Fproducts.ts` and redeploy for preview.\n- The Payment Link is built **dynamically from the cart** — every line item plus shipping and tax are sent as order line items so the amount charged **equals exactly what the buyer saw**. (Example: `$25` flat shipping, free over `$500`, `6%` state tax.) Change prices in the catalog, not in Square.\n\n## Webhooks\n\n- Create the subscription first — the **signature key is returned only once** (retrieving the subscription later does not return it; rotate to get a fresh one).\n- Verification HMACs `notificationUrl + rawBody` with the signature key. `SQUARE_WEBHOOK_URL` must equal the subscription's `notification_url` **exactly** (even a trailing slash rejects every event).\n- Sandbox webhooks need a **public** URL (a Vercel preview host), not localhost.\n- Until the key is deployed, the webhook route returns `400` on events — expected, not a failure.\n\n## Testing\n\n**Sandbox** (`SQUARE_ENVIRONMENT=sandbox` + sandbox token + sandbox location):\n- Success card: `4111 1111 1111 1111`, CVV `111`, any **future** expiry, any **valid** ZIP.\n- Decline triggers: CVV `911`, ZIP `99999`, expiry `01\u002F40`, card `4000000000000002`.\n- Square rule: **sandbox rejects real cards; production rejects test cards.** `4111…` will always decline on production.\n\n**Production** (when you can't easily get a sandbox token, or want to prove the real path):\n- Add a **$1 test item** to the catalog and give it free shipping (guard the free-ship on the test item's id so real products are unaffected), so the charge is ~$1 not ~$27.\n- Pay with a **real card**, confirm the success page + the charge in the Square dashboard, then **refund it**. One real transaction validates the exact path customers use.\n- **Never enter card details on someone's behalf** — hand off the link; the human enters their own card.\n\n**Verify the gate + the redirect:** the \"Pay by Card\" tile should appear, and \"Continue to Payment\" should land on `checkout.square.site\u002F...` (production) or the sandbox equivalent. Reaching the Square page proves link creation (token + location) works; the decline\u002Fapprove is separate.\n\n## The `pre_populated_data` email\u002Fphone gotcha (real bug — fix pattern below)\n\nSquare **hard-rejects the entire payment link** if `pre_populated_data.buyer_email` or `buyer_phone_number` fails its validation — even though those fields only *pre-fill* Square's form. Symptoms: `Square checkout failed: Invalid phone number.` (phone must be **E.164**, e.g. `+19415551234`; `9415551234` is rejected) or `Invalid email address.` (reserved domains like `example.com` rejected). A real customer typing `(941) 555-1234` would be blocked from paying.\n\nFix (in the checkout\u002Fpayments module): normalize the phone to E.164 best-effort, and if Square still rejects the pre-fill, **retry once without `pre_populated_data`** so a bad email\u002Fphone can never block checkout. Pattern:\n```ts\nfunction toE164(raw){ const d=(raw||\"\").replace(\u002F\\D\u002Fg,\"\"); if(d.length===10)return`+1${d}`; if(d.length===11&&d[0]===\"1\")return`+${d}`; return undefined; }\n\u002F\u002F build payload with\u002Fwithout pre_populated_data; POST with prefill=true;\n\u002F\u002F if !res.ok and error mentions email\u002Fphone → POST again with prefill=false.\n```\n\n## Failure → cause quick table\n\n| Symptom | Likely cause |\n| --- | --- |\n| No \"Pay by Card\" tile at all | `SQUARE_ACCESS_TOKEN` or `SQUARE_LOCATION_ID` empty in the serving env; or vars set but **not redeployed**; or wrong Vercel scope (viewing a preview, vars only in production scope) |\n| `Square checkout failed: This request could not be authorized` (`UNAUTHORIZED`) | Token is the wrong **type** (`sq0idp-` App ID) or wrong **environment** (prod token on sandbox host or vice-versa) — `SQUARE_ENVIRONMENT` and token mismatch |\n| Reached Square page, card declined (\"your order didn't go through\") | On **production** with a test card, or on sandbox with a decline-trigger value (CVV `911`\u002FZIP `99999`) |\n| `Invalid phone number` \u002F `Invalid email address` | `pre_populated_data` validation — apply the E.164 + retry-without-prefill fix |\n| Webhook events all rejected (`400`) | `SQUARE_WEBHOOK_URL` ≠ subscription `notification_url`, or signature key missing\u002Fnot deployed |\n\n## Setup checklist\n\n1. Decide sandbox vs production for this environment; grab the **matching** access token (flip the dashboard toggle!).\n2. `curl \u002Fv2\u002Flocations` on both hosts to confirm the token's environment + its location id.\n3. Set `SQUARE_ACCESS_TOKEN` (sensitive), `SQUARE_LOCATION_ID` + `SQUARE_ENVIRONMENT` (non-sensitive) in the **correct Vercel scope**.\n4. Create the webhook subscription; store `SQUARE_WEBHOOK_SIGNATURE_KEY` + `SQUARE_WEBHOOK_URL`.\n5. **Redeploy** (vars bind at build).\n6. Verify the tile shows and checkout reaches the Square page (logged-in browser, not curl).\n7. Run a test payment (sandbox `4111…` or production real-card + refund).\n8. Set\u002Fadjust prices in the catalog (base `data\u002Fproducts.ts` or live overrides), not in Square.\n","# Square Billing Setup (Hosted Payment Links)\n\nHow to stand up Square card checkout for a storefront **correctly the first time**, and how to diagnose it when it breaks. Written from a real, painful setup (a furniture storefront built on Next.js and Vercel) where every one of the gotchas below actually bit. The reference implementation shape referred to below: `lib\u002Fpayments.ts`, `app\u002Fapi\u002Fcheckout\u002F*`, `app\u002Fapi\u002Fwebhooks\u002Fsquare\u002Froute.ts`, a `scripts\u002Fsquare-setup.sh` helper, and a `deploy\u002FSQUARE.md` runbook — adapt the paths to your own project.\n\n## The integration model this covers\n\nServer-side **hosted Payment Links** (`POST \u002Fv2\u002Fonline-checkout\u002Fpayment-links`). The app builds a checkout session from the live cart and redirects the buyer to a Square-hosted page (`checkout.square.site\u002F...`). **No card data ever touches the app** (no PCI scope). It authenticates with the **access token alone** — the Square *Application ID* is **not used** by this flow (that's only for the client-side Web Payments SDK, which this model does not use).\n\nThe \"Pay by Card\" option is **env-gated**: the server advertises Square only when its credentials are present. In the reference implementation that gate is:\n```ts\n\u002F\u002F lib\u002Fpayments.ts\nsquare: Boolean(process.env.SQUARE_ACCESS_TOKEN && process.env.SQUARE_LOCATION_ID)\n```\nSo if either var is missing\u002Fempty in the environment serving the page, the buyer sees only fallback methods (Phone \u002F Cash on Delivery) and **no card option**. \"Configuring Square in the dashboard\" is not enough — the running server must have the env vars.\n\n## Credential taxonomy — the #1 source of pain\n\nSquare has several credential strings and they are **not interchangeable**. Getting these wrong causes ~every failure below.\n\n| String | Prefix | What it is | Used by this flow? |\n| --- | --- | --- | --- |\n| Production Access Token | `EAAA…` (~64 chars) | Auth for **production** API (`connect.squareup.com`) | ✅ yes (prod) |\n| Sandbox Access Token | `EAAA…` (~64 chars) | Auth for **sandbox** API (`connect.squareupsandbox.com`) | ✅ yes (sandbox) |\n| Application ID | `sq0idp-…` (prod) \u002F `sandbox-sq0idb-…` | Client-side app identifier | ❌ **NOT used** — do not put this in `SQUARE_ACCESS_TOKEN` |\n| OAuth client secret | `sq0csp-…` | OAuth app secret | ❌ not this flow |\n| Webhook signature key | opaque | HMAC key for webhook verification | ✅ (webhooks only) |\n\n**Critical traps:**\n- **`sq0idp-…` is an Application ID, not an access token.** Pasting it into `SQUARE_ACCESS_TOKEN` makes the gate pass (non-empty) but every Square API call returns `UNAUTHORIZED`. Access tokens start `EAAA…` and are ~64 chars.\n- **Sandbox and production access tokens BOTH start `EAAA…`** — you cannot tell them apart by looking. A **production** token returns `UNAUTHORIZED` against the **sandbox** host, and vice-versa. This is the trap that eats hours: you grab \"the token,\" it looks right, and it's the wrong *environment's* token.\n\n### Where to get each token in the Square Developer Dashboard\n`developer.squareup.com\u002Fapps` → open the application → **toggle the environment selector (top-left) to Sandbox or Production** → left nav **Credentials** → copy the **Access Token** for that environment. The dashboard defaults to **Production**, so the #1 mistake when someone asks for \"the sandbox token\" is handing back the production one because they never flipped the toggle.\n\n### Identify an unknown token (do this before trusting any token)\nTest it against **both** hosts — the one it authenticates on tells you its environment; the location it returns confirms the account:\n```bash\n# production host\ncurl -s https:\u002F\u002Fconnect.squareup.com\u002Fv2\u002Flocations \\\n  -H \"Square-Version: 2026-05-20\" -H \"Authorization: Bearer $TOK\" | jq '.locations[]|{id,name,status} \u002F\u002F .errors'\n# sandbox host\ncurl -s https:\u002F\u002Fconnect.squareupsandbox.com\u002Fv2\u002Flocations \\\n  -H \"Square-Version: 2026-05-20\" -H \"Authorization: Bearer $TOK\" | jq '.locations[]|{id,name,status} \u002F\u002F .errors'\n```\n`UNAUTHORIZED` on one host + a real location list on the other = you now know exactly which environment (and which account) the token belongs to. **Everything except the token is derivable from the token** — you never need to hunt for the location ID by hand.\n\n## Environment variables\n\n| Var | Secret? | Notes |\n| --- | --- | --- |\n| `SQUARE_ACCESS_TOKEN` | **yes** | `EAAA…`, environment-matched (see above) |\n| `SQUARE_LOCATION_ID` | no | derive via `GET \u002Fv2\u002Flocations`. Sandbox default-test-account location ≠ production business location |\n| `SQUARE_ENVIRONMENT` | no | `production` → `connect.squareup.com`; anything else → sandbox host. Must match the token's environment |\n| `SQUARE_VERSION` | no | optional, defaults to a pinned `Square-Version` in code |\n| `SQUARE_WEBHOOK_SIGNATURE_KEY` | **yes** | shown only once at subscription creation |\n| `SQUARE_WEBHOOK_URL` | no | must match the subscription's `notification_url` **exactly** |\n\nExample locations (placeholders — yours will differ, always derive from the token): production `LXXXXXXXXXXXX`, sandbox default-test-account `LYYYYYYYYYYYY`.\n\n**Golden rule:** `SQUARE_ENVIRONMENT` and `SQUARE_ACCESS_TOKEN` must be the **same environment**. `production` + a sandbox token → `UNAUTHORIZED`; `sandbox` + a production token → `UNAUTHORIZED`.\n\n## Deployment on Vercel — the traps that wasted the most time\n\n1. **Env vars bind at BUILD time.** Adding\u002Fchanging a var does **nothing** to an existing deployment. You must **redeploy** after any env change. The currently-live build reads the vars that existed when *it* built.\n2. **Scopes are separate: Production vs Preview vs Development.** A **Preview** deployment does **not** see Production-scoped vars. Convention: Production scope = production creds (`SQUARE_ENVIRONMENT=production`); Preview scope = sandbox creds (`SQUARE_ENVIRONMENT=sandbox`) so branch\u002Fpreview deploys hit the sandbox. If the card tile is missing on a preview URL, its scope probably lacks the vars.\n3. **Combined-scope removal trap.** If a var is attached to `Production, Preview` as one entry, `vercel env rm NAME preview` can remove it from **both** environments — this silently wiped a production token during a \"just change preview\" edit. Keep each environment's value as a **separate** entry; overwrite one scope with `--force`, e.g. `printf '%s' \"$VAL\" | vercel env add NAME preview --force`.\n4. **Sensitive vars are write-only.** `vercel env pull` returns **empty** for sensitive vars, so you can't verify them from the CLI. Add non-secret values (`SQUARE_ENVIRONMENT`, `SQUARE_LOCATION_ID`) with `--no-sensitive` so they're readable\u002Fverifiable; keep the token `--sensitive`.\n5. **Preview URLs sit behind Vercel deployment protection** → `curl` gets a `302`. Verify runtime behavior in a **logged-in browser**, not curl. `vercel env ls` and `vercel inspect \u003Curl>` are your read-only truth for scopes\u002Ftimestamps.\n\nFastest safe path: use `scripts\u002Fsquare-setup.sh \u003Cproduction|sandbox> [notify_url]` — it sets the core vars in the right scope, creates the webhook, and stores the signature key (shown once). Prereqs: `vercel login` + `vercel link`. It prompts for the token hidden (never on disk\u002Fin chat).\n\n**Never accept a secret token through chat** (it gets logged). Have the human paste it via the setup script's hidden prompt, or `pbpaste > file` after copying, then read the file and delete it. Verify the token against the API *before* redeploying so you don't burn a build on a wrong token.\n\n## Setting prices \u002F products\n\n- **Base catalog** lives in code (`data\u002Fproducts.ts`): id, name, price (whole dollars), image, etc.\n- **Live overrides** (price, hide, out-of-stock, badges, featured rank) are DB patches merged in `lib\u002Fcatalog.ts` via the admin API — these take effect **without a redeploy** (`revalidateTag`). Note: a **preview** deployment may have **no DB access** (DB creds are Production-scoped), so on preview you see only the in-code base prices; add\u002Fchange items in `data\u002Fproducts.ts` and redeploy for preview.\n- The Payment Link is built **dynamically from the cart** — every line item plus shipping and tax are sent as order line items so the amount charged **equals exactly what the buyer saw**. (Example: `$25` flat shipping, free over `$500`, `6%` state tax.) Change prices in the catalog, not in Square.\n\n## Webhooks\n\n- Create the subscription first — the **signature key is returned only once** (retrieving the subscription later does not return it; rotate to get a fresh one).\n- Verification HMACs `notificationUrl + rawBody` with the signature key. `SQUARE_WEBHOOK_URL` must equal the subscription's `notification_url` **exactly** (even a trailing slash rejects every event).\n- Sandbox webhooks need a **public** URL (a Vercel preview host), not localhost.\n- Until the key is deployed, the webhook route returns `400` on events — expected, not a failure.\n\n## Testing\n\n**Sandbox** (`SQUARE_ENVIRONMENT=sandbox` + sandbox token + sandbox location):\n- Success card: `4111 1111 1111 1111`, CVV `111`, any **future** expiry, any **valid** ZIP.\n- Decline triggers: CVV `911`, ZIP `99999`, expiry `01\u002F40`, card `4000000000000002`.\n- Square rule: **sandbox rejects real cards; production rejects test cards.** `4111…` will always decline on production.\n\n**Production** (when you can't easily get a sandbox token, or want to prove the real path):\n- Add a **$1 test item** to the catalog and give it free shipping (guard the free-ship on the test item's id so real products are unaffected), so the charge is ~$1 not ~$27.\n- Pay with a **real card**, confirm the success page + the charge in the Square dashboard, then **refund it**. One real transaction validates the exact path customers use.\n- **Never enter card details on someone's behalf** — hand off the link; the human enters their own card.\n\n**Verify the gate + the redirect:** the \"Pay by Card\" tile should appear, and \"Continue to Payment\" should land on `checkout.square.site\u002F...` (production) or the sandbox equivalent. Reaching the Square page proves link creation (token + location) works; the decline\u002Fapprove is separate.\n\n## The `pre_populated_data` email\u002Fphone gotcha (real bug — fix pattern below)\n\nSquare **hard-rejects the entire payment link** if `pre_populated_data.buyer_email` or `buyer_phone_number` fails its validation — even though those fields only *pre-fill* Square's form. Symptoms: `Square checkout failed: Invalid phone number.` (phone must be **E.164**, e.g. `+19415551234`; `9415551234` is rejected) or `Invalid email address.` (reserved domains like `example.com` rejected). A real customer typing `(941) 555-1234` would be blocked from paying.\n\nFix (in the checkout\u002Fpayments module): normalize the phone to E.164 best-effort, and if Square still rejects the pre-fill, **retry once without `pre_populated_data`** so a bad email\u002Fphone can never block checkout. Pattern:\n```ts\nfunction toE164(raw){ const d=(raw||\"\").replace(\u002F\\D\u002Fg,\"\"); if(d.length===10)return`+1${d}`; if(d.length===11&&d[0]===\"1\")return`+${d}`; return undefined; }\n\u002F\u002F build payload with\u002Fwithout pre_populated_data; POST with prefill=true;\n\u002F\u002F if !res.ok and error mentions email\u002Fphone → POST again with prefill=false.\n```\n\n## Failure → cause quick table\n\n| Symptom | Likely cause |\n| --- | --- |\n| No \"Pay by Card\" tile at all | `SQUARE_ACCESS_TOKEN` or `SQUARE_LOCATION_ID` empty in the serving env; or vars set but **not redeployed**; or wrong Vercel scope (viewing a preview, vars only in production scope) |\n| `Square checkout failed: This request could not be authorized` (`UNAUTHORIZED`) | Token is the wrong **type** (`sq0idp-` App ID) or wrong **environment** (prod token on sandbox host or vice-versa) — `SQUARE_ENVIRONMENT` and token mismatch |\n| Reached Square page, card declined (\"your order didn't go through\") | On **production** with a test card, or on sandbox with a decline-trigger value (CVV `911`\u002FZIP `99999`) |\n| `Invalid phone number` \u002F `Invalid email address` | `pre_populated_data` validation — apply the E.164 + retry-without-prefill fix |\n| Webhook events all rejected (`400`) | `SQUARE_WEBHOOK_URL` ≠ subscription `notification_url`, or signature key missing\u002Fnot deployed |\n\n## Setup checklist\n\n1. Decide sandbox vs production for this environment; grab the **matching** access token (flip the dashboard toggle!).\n2. `curl \u002Fv2\u002Flocations` on both hosts to confirm the token's environment + its location id.\n3. Set `SQUARE_ACCESS_TOKEN` (sensitive), `SQUARE_LOCATION_ID` + `SQUARE_ENVIRONMENT` (non-sensitive) in the **correct Vercel scope**.\n4. Create the webhook subscription; store `SQUARE_WEBHOOK_SIGNATURE_KEY` + `SQUARE_WEBHOOK_URL`.\n5. **Redeploy** (vars bind at build).\n6. Verify the tile shows and checkout reaches the Square page (logged-in browser, not curl).\n7. Run a test payment (sandbox `4111…` or production real-card + refund).\n8. Set\u002Fadjust prices in the catalog (base `data\u002Fproducts.ts` or live overrides), not in Square.\n",{"name":5,"description":7},"main","f270c4ae4f9d09c4e5da9cfa8adab7e89ae1f53e","packaged-skills\u002Foptional\u002Fops\u002Fhivemindos\u002Fsquare-billing-setup",4,"https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos","https:\u002F\u002Fgithub.com\u002FLiamVisionary","2026-11-10 21:48:41",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add LiamVisionary\u002Fhivemindos --skill square-billing-setup",{"tool":36,"command":37},"bunx","bunx skills add LiamVisionary\u002Fhivemindos --skill square-billing-setup",{"tool":39,"command":40},"pnpm","pnpm dlx skills add LiamVisionary\u002Fhivemindos --skill square-billing-setup","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fpackaged-skills\u002Foptional\u002Fops\u002Fhivemindos\u002Fsquare-billing-setup\u002FSKILL.md",true,[44],{"path":45,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":48,"sourceHtmlUrl":49},".hivemind-skill-source.json","REFERENCE","参考文档",910,"https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fpackaged-skills\u002Foptional\u002Fops\u002Fhivemindos\u002Fsquare-billing-setup\u002F.hivemind-skill-source.json",[51,58,65,72,79,86],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":18},"01M734AA85KQEXDQXQJ3T7769M","tailscale-generation-skill-authoring","This skill should be used when the user asks to \"create a Tailscale generation skill\", \"add a local generation skill\", \"document a generation endpoint\", \"add an image generation provider\", \"add a TTS provider\", \"add video generation\", \"add 3D generation\", or needs guidance on where HivemindOS Tailscale or local generation providers belong in the shared skills shelf.","https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fskills\u002Ftailscale-generation-skill-authoring\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":18},"01M734A7VD69PRA0C0EV5EFY9T","localtts","This skill should be used when the user asks to \"generate local TTS\", \"use local text to speech\", \"use remote TTS over Tailscale\", \"make speech audio\", \"add a TTS provider\", \"use Qwen3-TTS\", or needs TTS endpoint setup through local or HivemindOS Tailscale routes.","https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fskills\u002Flocaltts\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":18},"01M734A4K2Z0F74QZP7V7WBFRY","karpathy-guidelines","Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.","https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fskills\u002Fkarpathy-guidelines\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":18},"01M734A1HMVYVJX3YJGNQ6KF6C","comfyui-image-generation","This skill should be used when the user asks to \"generate images\", \"generate images with ComfyUI\", \"use local ComfyUI\", \"use remote ComfyUI\", \"use Z-Image\", \"add an image generation provider\", or needs image-generation endpoint setup through local or HivemindOS Tailscale routes.","https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fskills\u002Fcomfyui-image-generation\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":18},"01M7349Y684Q676DNNHZPSC8W1","wrangler","Cloudflare Workers CLI for deploying, developing, and managing Workers, KV, R2, D1, Vectorize, Hyperdrive, Workers AI, Containers, Queues, Workflows, Pipelines, and Secrets Store. Load before running wrangler commands to ensure correct syntax and best practices. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.","https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fskills\u002Fcloudflare\u002Fwrangler\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":18},"01M7349V3WCBF835QP74SA9Q8C","workers-best-practices","Reviews and authors Cloudflare Workers code against production best practices. Load when writing new Workers, reviewing Worker code, configuring wrangler.jsonc, or checking for common Workers anti-patterns (streaming, floating promises, global state, secrets, bindings, observability). Biases towards retrieval from Cloudflare docs over pre-trained knowledge.","https:\u002F\u002Fgithub.com\u002FLiamVisionary\u002Fhivemindos\u002Fblob\u002Fmain\u002Fskills\u002Fcloudflare\u002Fworkers-best-practices\u002FSKILL.md",[],[]]