Skip to main content

Testing Subscriptions

Guida per testare le subscription in ambiente sandbox/development.

πŸ§ͺ Ambienti di Test​

ProviderAmbienteNote
StripeTest modeUsa chiavi sk_test_xxx
AppleSandboxUsa App Store Connect Sandbox Testers
GoogleLicense TestingAggiungi email in Play Console

πŸ’³ Stripe Testing​

Attivare Test Mode​

  1. Stripe Dashboard β†’ toggle "Test mode" in alto a destra
  2. Usa chiavi API che iniziano con sk_test_, pk_test_

Carte di Test​

ScenarioNumeroCVVExp
βœ… Successo4242 4242 4242 4242AnyAny future
❌ Declined4000 0000 0000 0002AnyAny future
⏳ Requires auth4000 0025 0000 3155AnyAny future
πŸ’³ Insufficient funds4000 0000 0000 9995AnyAny 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​

  1. App Store Connect β†’ Users and Access β†’ Sandbox β†’ Testers
  2. Crea account con email fittizia (non un vero Apple ID)
  3. Password deve rispettare requisiti Apple

Configurare Device​

Non fare login nelle Settings!

Se fai login in Settings β†’ App Store, l'account sandbox viene "consumato".

  1. Settings β†’ App Store β†’ Sign Out (se loggato)
  2. Apri la tua app
  3. Fai un acquisto
  4. Solo ora ti chiederΓ  di fare login β†’ usa account sandbox

Tempi Accelerati​

Durata RealeSandbox
1 settimana3 min
1 mese5 min
1 anno1 ora

Gestire Subscription​

Settings β†’ App Store β†’ Sandbox Account β†’ Manage Subscriptions


πŸ€– Google License Testing​

Aggiungere License Tester​

  1. Play Console β†’ Settings β†’ License testing
  2. Aggiungi email degli sviluppatori

Test Flow​

  1. Device con account Google del tester
  2. App firmata con keystore di release (o internal testing track)
  3. Gli acquisti sono gratuiti e simulati

Response Codes​

Puoi testare diversi scenari configurando le risposte in Play Console:

  • LICENSED - Acquisto riuscito
  • NOT_LICENSED - Acquisto fallito
  • LICENSED_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