Testing Subscriptions
Guida per testare le subscription in ambiente sandbox/development.
π§ͺ Ambienti di Testβ
| Provider | Ambiente | Note |
|---|---|---|
| Stripe | Test mode | Usa chiavi sk_test_xxx |
| Apple | Sandbox | Usa App Store Connect Sandbox Testers |
| License Testing | Aggiungi email in Play Console |
π³ Stripe Testingβ
Attivare Test Modeβ
- Stripe Dashboard β toggle "Test mode" in alto a destra
- Usa chiavi API che iniziano con
sk_test_,pk_test_
Carte di Testβ
| Scenario | Numero | CVV | Exp |
|---|---|---|---|
| β Successo | 4242 4242 4242 4242 | Any | Any future |
| β Declined | 4000 0000 0000 0002 | Any | Any future |
| β³ Requires auth | 4000 0025 0000 3155 | Any | Any future |
| π³ Insufficient funds | 4000 0000 0000 9995 | Any | Any future |
Test Webhook Localmenteβ
# Installa Stripe CLI
brew install stripe/stripe-cli/stripe
# Login
stripe login
# Forward webhooks
stripe listen --forward-to localhost:8088/webhooks/stripe
# Trigger eventi
stripe trigger customer.subscription.created
stripe trigger invoice.payment_failed
π Apple Sandbox Testingβ
Creare Sandbox Testerβ
- App Store Connect β Users and Access β Sandbox β Testers
- Crea account con email fittizia (non un vero Apple ID)
- Password deve rispettare requisiti Apple
Configurare Deviceβ
Non fare login nelle Settings!
Se fai login in Settings β App Store, l'account sandbox viene "consumato".
- Settings β App Store β Sign Out (se loggato)
- Apri la tua app
- Fai un acquisto
- Solo ora ti chiederΓ di fare login β usa account sandbox
Tempi Acceleratiβ
| Durata Reale | Sandbox |
|---|---|
| 1 settimana | 3 min |
| 1 mese | 5 min |
| 1 anno | 1 ora |
Gestire Subscriptionβ
Settings β App Store β Sandbox Account β Manage Subscriptions
π€ Google License Testingβ
Aggiungere License Testerβ
- Play Console β Settings β License testing
- Aggiungi email degli sviluppatori
Test Flowβ
- Device con account Google del tester
- App firmata con keystore di release (o internal testing track)
- Gli acquisti sono gratuiti e simulati
Response Codesβ
Puoi testare diversi scenari configurando le risposte in Play Console:
LICENSED- Acquisto riuscitoNOT_LICENSED- Acquisto fallitoLICENSED_OLD_KEY- Versione precedente
π§ Test End-to-Endβ
1. Test Stripe β Billing Serviceβ
# Terminal 1: Start billing service
docker-compose up -d billing postgres-billing redis
# Terminal 2: Forward Stripe webhooks
stripe listen --forward-to localhost:8088/webhooks/stripe
# Terminal 3: Trigger event
stripe trigger customer.subscription.created
# Check logs
docker-compose logs -f billing
Verifica: Log mostra "Processed Stripe event..."
2. Test API Checkβ
# Check subscription status
curl http://localhost:8088/api/subscriptions/check/123
3. Test Redis Eventβ
docker exec -it redis redis-cli
XREAD STREAMS billing:events 0
β Test Checklistβ
Stripeβ
- Checkout session creata correttamente
- Webhook ricevuto e processato
- Subscription creata nel DB
- Evento pubblicato su Redis
- Customer Portal funziona
Appleβ
- Prodotti caricati in app
- Purchase flow completo
- Webhook ricevuto (controlla logs)
- Subscription creata nel DB
- Restore purchases funziona
Googleβ
- Prodotti caricati in app
- Purchase flow completo (con acknowledge)
- RTDN ricevuto
- Subscription creata nel DB