Docs / Testing

Testing

Validate your credit flow before going live — from metered events to Stripe-powered top-ups.

What to test

  • SDK initializes correctly
  • meterEvent() deducts credits
  • Wallet balances update correctly
  • Stripe test purchases add credits
  • Webhooks are received and processed
  • UI reflects updated balances

Local development checklist

Use test API keys and Stripe test mode. Use test customers and wallets. Avoid mixing live and test data.

  • Use test API keys
  • Use Stripe test mode
  • Use test customers and wallets
  • Avoid mixing live and test data

Test a metered event

app.js
await chargly.meterEvent({
  customerId: "user_123",
  event: "image.generate",
  credits: 40
})

Expected: event is recorded, credits are deducted, wallet balance updates.

Test a top-up flow

Create a Stripe test checkout, complete the purchase with test mode, and verify Chargly syncs the credits back to the wallet.

Test webhook handling

Forward webhooks to a local/dev endpoint (e.g. with Stripe CLI or ngrok). Verify signature handling, handle retries safely, and keep handlers idempotent.

Recommended test scenarios

Successful metered deductionInsufficient balanceSuccessful Stripe top-upRepeated webhook deliveryInvalid webhook signature rejectionUI balance refresh after purchase

Go-live checklist

  • Switch to live API keys
  • Switch Stripe to live mode
  • Configure production webhook endpoint
  • Verify real credit pack mappings
  • Confirm logging and monitoring

Next