# Stripe Payments

> Take card payments for physical goods and services, where Play billing is not required.

- **Applies to:** Appwright
- **Source:** the Integration Guide shipped inside the app; this page is generated from it.
- **HTML:** https://freewebsitetoapk.com/docs/stripe-payments

Charge users in AI-generated apps with your own Stripe account - keys stay server-side, fulfillment is webhook-verified

### 1. What this gives your app

Lets apps you generate charge real money - paywalls, 'Pro' upgrades, buy buttons - through Stripe Checkout.

It's YOUR Stripe account: your keys, your money, paid straight to you. Appwright takes no cut and no payment liability (no Stripe Connect). You connect Stripe ONCE in Settings; every app you generate reuses it - you only describe what to sell, never re-enter keys.

The AI writes all the payment code. Your secret key never ships inside the app - it lives in your Supabase backend.

### 2. First connect Supabase (required)

Stripe payments need a secure server to hold your secret key and to confirm payments - that server is your Supabase project. So connect and enable Supabase first (Settings → BACKEND - SUPABASE).

If Supabase isn't active you'll see 'Stripe keys saved, but payments also need Supabase active'. Appwright pushes your Stripe secret into your Supabase functions automatically on deploy - it's never put in the generated app.

### 3. Get your Stripe keys (start in test)

On a computer:

1. Open the Stripe Dashboard and stay in test mode / a sandbox while you build (Stripe now calls the test environment a 'sandbox'; older accounts show a Test/Live toggle). No real charges happen here.
2. Go to Developers → API keys.
3. Copy the 'Publishable key' (starts with pk_test_…) and reveal + copy the 'Secret key' (starts with sk_test_…).

Use the standard Secret key (sk_…), not a Restricted key (rk_…) - Appwright validates and pushes the sk_ secret. No merchant approval is needed to build and test the whole flow before activating live payments.

[Open Stripe API keys](https://dashboard.stripe.com/test/apikeys)

### 4. Connect Stripe in Appwright

Open AI Studio → Settings → scroll to 'PAYMENTS - STRIPE (OPTIONAL)' → 'CONNECT STRIPE (YOUR ACCOUNT)':

1. Leave 'Live mode' OFF for now (off = Test).
2. Paste your publishable key into the pk_test_… field.
3. Paste your secret key into the sk_test_… field (kept encrypted on this device).
4. Turn ON 'Enable Stripe payments for generated apps'.
5. Tap 'Validate & save Stripe keys'. Appwright checks the format, makes sure both keys are the same mode, and verifies the secret with Stripe. On success you'll see '● Connected (TEST)'.

### 5. What Appwright wires up for you

When you generate an app with payments, Appwright does the plumbing automatically - you don't touch Supabase or Stripe dashboards:

- Pushes your STRIPE_SECRET_KEY into your Supabase Edge Functions (encrypted, server-side only).
- Deploys a 'create-checkout' function (starts a Stripe Checkout session) and a 'stripe-webhook' function (confirms payments).
- Registers the webhook with Stripe and stores its signing secret.
- Creates an 'entitlements' table so the app knows who paid.

The publishable key (pk_) is the only Stripe value that ships in the app - that key is safe to be public.

### 6. Describe your paywall - the AI builds it

Just say what you want in plain English. The AI adds the buy button, the checkout call, and gates the paid features for you:

- 'Charge $5 one-time to unlock the Pro theme.'
- 'A $9/month subscription that removes ads.'
- 'Sell a downloadable PDF for $19.'

You never paste keys or prices into the chat as config - only the intent. Access is unlocked only after Stripe confirms the payment via the webhook, never from a client-side 'paid' flag, so it can't be faked.

### 7. Test a payment end-to-end

While in Test mode, no real money moves. Run the full flow:

1. Open your app and tap the buy/upgrade button.
2. On the Stripe Checkout page, pay with the test card:

```
 4242 4242 4242 4242, any future expiry, any CVC, any ZIP.
```

1. You're returned to the app and the paid feature unlocks.
2. Check Stripe Dashboard (Test mode) → Payments - you'll see the test charge.

If it unlocks, your webhook + entitlements are wired correctly.

```
4242 4242 4242 4242   exp: any future date   CVC: any 3 digits
```

### 8. Go Live when you're ready

1. Activate your Stripe account for live payments (Stripe Dashboard → 'Activate' / complete business details).
2. In Stripe, switch from sandbox/test to live mode and copy your LIVE keys (pk_live_… and sk_live_…) from Developers → API keys.
3. In Appwright → Settings → Payments: turn ON 'Live mode', paste the pk_live_/sk_live_ keys, and tap 'Validate & save'. The badge turns to '● Connected (LIVE)'.
4. Rebuild your app.

Appwright blocks mixing test and live keys, and switching mode re-points the deployed secret - test and live never coexist on one app, so you can't accidentally ship test keys.

### 9. If something doesn't work

- 'Stripe keys saved, but payments also need Supabase active' → enable Supabase first (step 2).

- 'You selected TEST but the keys are LIVE' (or vice-versa) → the mode toggle must match your keys' prefix (pk_test/sk_test vs pk_live/sk_live).

- 'Stripe rejected the key' → the secret key is wrong or revoked. Re-copy it from Developers → API keys.

- Payment succeeds but the feature stays locked → the webhook didn't reach Supabase. Rebuild/redeploy so Appwright re-registers the webhook, and confirm the app's Supabase project is the one you connected.

- Can't activate a live account → Stripe does NOT onboard merchants in some countries (including India). Test mode still works everywhere for building; for live payments there you'd need a Stripe-supported country or a different provider.

