# Stripe & email debugging

> Resolve Stripe Test vs Live mix-ups, missing webhooks, stalled order unlocks, bounced emails, and SPF, DKIM, or DMARC authentication failures fast.

- Canonical: https://exaspark.ai/docs/debug-payments-and-email/

## Why payment and email bugs fail silently

Unlike visual layout glitches, payment fulfillment and transactional emails execute asynchronously behind the scenes. A visitor can complete Stripe Checkout, see a cheerful confirmation page, and still find their account stuck on Free because a webhook failed — or wait forever for a receipt blocked by a broken DNS record.

Never debug payments or email from the browser screen alone. Always trace the two authoritative server logs first: **Stripe Dashboard → Developers → Webhooks** for payments, and **Cloud → Email → Logs** for outgoing mail.

## Fixing Stripe Test vs Live key mix-ups

Stripe maintains two completely separate worlds: **Test mode** (permanently wired to your ExaSpark **Preview** environment) and **Live mode** (used when your published app charges real cards). Nearly half of launch-week checkout errors happen when an artifact from Test mode leaks into Live mode.

Four separate identifiers change between Test and Live — none of them cross environments:

- **API keys:** Test keys begin with `pk_test_` and `sk_test_`; Live keys begin with `pk_live_` and `sk_live_`.
- **Product and Price IDs:** Every `price_...` created in Stripe Test mode exists only in Test mode. You must reference matching Live `price_...` IDs when Live mode runs.
- **Webhook signing secrets:** Each webhook endpoint has its own unique `whsec_...` secret. Using a Test webhook secret against Live traffic fails signature verification on every event.
- **Customer and subscription IDs:** A `cus_...` or `sub_...` stored in **Preview** never exists inside your Live Stripe account.

Match the exact error message in Stripe or server logs to fix mix-ups immediately:

| Error or symptom | Exact root cause | Reliable fix |
| --- | --- | --- |
| **`No such price: 'price_...'`** | Live checkout requested a Price ID that only exists in Stripe Test mode | Create the matching product/price in Stripe **Live mode** and bind the Live Price ID |
| **Real card rejected: "Your card was declined (test mode)"** | Published app still runs in Stripe **Test mode** | Switch project payment settings to **Live mode** and click **Publish** |
| **`No signatures found matching the expected signature`** | Wrong `whsec_...` secret, or middleware parsed JSON before verifying raw body | Configure the Live endpoint's exact signing secret and verify against the raw request body |
| **`No such customer: 'cus_...'`** | Test `stripe_customer_id` copied or left in a Live user record | Clear stale test customer IDs in Live **Cloud** so Live checkout creates a clean `cus_...` |
| **Checkout opens with wrong currency or old amount** | Checkout button still passes a previous Stripe Price ID | Confirm active Live Price ID in Stripe Dashboard and update the checkout route |

Remember that ExaSpark charges **0%** platform fee on every Stripe transaction across all plans (standard Stripe card processing fees still apply). See [Payments with Stripe](https://exaspark.ai/docs/payments/).

## Diagnosing missing webhooks and stalled unlocks

When a card succeeds in Stripe Dashboard yet **Cloud** stays unpaid or Free, trace the webhook delivery end to end rather than rewriting Checkout:

1. **Check the Stripe mode toggle** — Confirm Stripe Dashboard is switched to **Test mode** (Preview) or **Live mode** (Live). Looking at the wrong mode hides failed deliveries.
2. **Read the HTTP delivery status** — Open **Developers → Webhooks → Recent deliveries**. `400` signals a signature mismatch, `404` a wrong route path, `500` a backend crash, and `301`/`307` a domain redirect trap.
3. **Eliminate apex-to-www redirect traps** — Stripe drops `POST` webhooks on `301`/`307` redirects. Always point your Stripe webhook URL straight to your exact canonical Live hostname.
4. **Verify events and session metadata** — Confirm the endpoint subscribes to `checkout.session.completed`, `invoice.paid`, `invoice.payment_failed`, `customer.subscription.updated`, `customer.subscription.deleted`, and `charge.refunded`, and that `metadata.user_id` or `metadata.order_id` is populated.
5. **Resend after publishing the fix** — Click **Resend** inside Stripe's webhook log and confirm **Cloud** updates to `paid` or `active` without duplicating records.

> **Note:** **Keep webhook handlers fast and idempotent.** Verify the signature, update **Cloud**, store the processed Stripe event ID, and return `200 OK` quickly so retries never double-credit accounts. See [Testing & subscriptions](https://exaspark.ai/docs/testing-stripe-and-webhooks/).

## Diagnosing transactional email failures and bounces

Open **Cloud → Email → Logs** to trace outgoing verification links, receipts, and alerts. First verify your plan's sending allowance:

- **Free ($0):** `100` emails/month, **authentication only** (verification, password resets, magic links), default sender, `7-day` logs, pauses at cap.
- **Starter ($4.99/mo or $3.99/mo annual):** `1,000` emails/month covering auth and custom app notifications, `1` custom sending domain, `7-day` logs, overage allowed.
- **Pro ($25/mo or $20/mo annual):** `10,000` emails/month, up to `3` custom sending domains, `30-day` logs, overage allowed.

Match what you see in **Cloud → Email → Logs** to the exact fix:

| Log status or symptom | Likely root cause | Exact fix |
| --- | --- | --- |
| **No log entry at all after checkout or booking** | App is on **Free** (auth-only) or server trigger never ran after webhook | Upgrade to **Starter** or **Pro** for custom app emails, or verify the webhook calls your send helper |
| **Status shows `Soft bounce`** | Recipient inbox full or temporary throttling by receiving server | Wait for automatic retry; no DNS change required unless repeated across all providers |
| **Status shows `Hard bounce` (`550 User Unknown`)** | Customer mistyped their email address (`gmial.com`) or mailbox closed | Stop retrying hard-bounced addresses automatically and prompt users to update their email |
| **Status shows `Delivered`, but email lands in Gmail Spam** | Missing DMARC, broken SPF/DKIM alignment, or link shorteners in body | Verify SPF + DKIM + DMARC pass via Gmail "Show original" and remove third-party short links |
| **Custom sending domain stuck in `Pending`** | DNS host duplicated root domain or Cloudflare proxy enabled on DKIM `CNAME` | Remove duplicate domain suffix in DNS host field and switch email CNAMEs to **DNS only** |
| **Verification emails stopped mid-month on Free** | Free plan reached its `100/month` authentication email cap | Upgrade to **Starter** (`1,000/mo`) or **Pro** (`10,000/mo`) to restore sending immediately |

## Fixing SPF, DKIM, and DMARC authentication errors

Modern inbox providers reject or spam-folder unauthenticated custom-domain mail automatically. Four specific DNS configuration mistakes cause almost every branded email failure.

### Mistake 1: Duplicate `v=spf1` records (SPF PermError)

DNS allows **only one** `v=spf1` TXT record per hostname. If you already publish a Google Workspace or Microsoft 365 SPF record on your root domain and add a second `v=spf1` record, both fail immediately with `PermError`.

Either merge the `include:` mechanism into your single existing `v=spf1` record, or — much cleaner — send app mail from a dedicated subdomain like `mail.yourdomain.com` with its own isolated SPF record.

### Mistake 2: Cloudflare orange cloud on DKIM CNAMEs

When Cloudflare's orange **Proxied** switch is turned on for a DKIM `CNAME`, Cloudflare intercepts the DNS query and serves HTTP proxy records instead of the cryptographic public key. Switch every DKIM `CNAME` to **DNS only (grey cloud)** immediately. See [DNS for Cloudflare & GoDaddy](https://exaspark.ai/docs/dns-cloudflare-godaddy/).

### Mistake 3: Doubled domain names in registrar forms

Many registrars (including GoDaddy and Namecheap) automatically append `.yourdomain.com` to whatever you type in the **Host** field. Pasting `s1._domainkey.mail.yourdomain.com` into those panels accidentally creates `s1._domainkey.mail.yourdomain.com.yourdomain.com`. Enter only the relative host prefix (`s1._domainkey.mail`) when your registrar auto-appends the root domain.

### Mistake 4: Missing DMARC policy or skipped header check

Gmail and Yahoo require a valid `_dmarc.yourdomain.com` TXT record for bulk and high-trust custom senders. Start with `p=none` to monitor cleanly, then verify all three records directly from your terminal and inside Gmail's **Show original** menu:

```text
Email DNS Verification Commands
------------------------------------------------------------------
1. Check SPF TXT record (confirm exactly ONE v=spf1 record exists):
   dig +short TXT mail.studionorth.co

2. Check DKIM CNAME target (must resolve to provider key, NOT Cloudflare IP):
   dig +short CNAME s1._domainkey.mail.studionorth.co

3. Check DMARC TXT record on organizational root domain:
   dig +short TXT _dmarc.studionorth.co

4. Inspect test email in Gmail -> Three dots -> "Show original":
   SPF:   PASS
   DKIM:  PASS
   DMARC: PASS
```

See [Branded email & delivery](https://exaspark.ai/docs/branded-email/) and [Email authentication & DNS](https://exaspark.ai/docs/email-authentication-dns/) for complete setup guides.

## Copyable repair prompts for Stripe and email

Use this prompt to harden a Stripe webhook that charges cards without updating **Cloud**:

> **Example prompt (App):** Stripe Checkout completes in Live mode, but orders in Cloud stay `pending`. Audit `/api/webhooks/stripe`: ensure signature verification reads the exact raw request body using the server-side Stripe webhook secret, pass `user_id` and `order_id` in Checkout Session metadata, store processed Stripe event IDs for idempotency, handle `checkout.session.completed`, `invoice.paid`, `customer.subscription.updated`, `customer.subscription.deleted`, and `charge.refunded`, and log clear server errors without exposing secrets.

Use this prompt to ensure receipt emails send reliably without ever breaking webhook acknowledgment:

> **Example prompt (App):** When `checkout.session.completed` marks an order `paid` in Cloud, send a branded confirmation email from our verified sending domain with a real `Reply-To` address, clear order summary, and both HTML and plain-text bodies. Wrap the email send in its own error handler and log delivery failures cleanly so a temporary mail error never causes the Stripe webhook to return HTTP 500 or roll back the paid order status.

## Next steps

- [Testing & subscriptions](https://exaspark.ai/docs/testing-stripe-and-webhooks/) — Run full test-card, decline, and Test-to-Live verification flows.
- [Branded email & delivery](https://exaspark.ai/docs/branded-email/) — Set up custom sending domains, quotas, and delivery monitoring.
- [Email authentication & DNS](https://exaspark.ai/docs/email-authentication-dns/) — Configure SPF, DKIM, and DMARC records cleanly across registrars.

## From the blog

- [How online payments work](https://exaspark.ai/blog/how-online-payments-work/) — Plain-English guide to Stripe sessions, webhooks, and payouts.
- [App launch checklist](https://exaspark.ai/blog/app-launch-checklist/) — Catch live payment and email glitches before announcing launch.
- [Why AI-built apps stall after launch](https://exaspark.ai/blog/why-ai-built-apps-stall-after-launch/) — Fix silent revenue leaks in checkout and follow-up flows.
