Test Mode Is Basically a Free Payment API
Stripe test mode gives you a fully functional payment API with fake money. Same endpoints, same webhooks, same everything — just no real charges.
Setup
pip install stripe
# or
npm install stripe
Use test keys from dashboard.stripe.com/test/apikeys.
Create a Payment Intent (Python)
import stripe
stripe.api_key = "sk_test_your_test_key"
intent = stripe.PaymentIntent.create(
amount=2000, # $20.00 in cents
currency="usd",
payment_method_types=["card"]
)
print(f"Client secret: {intent.client_secret}")
Create a Checkout Session
session = stripe.checkout.Session.create(
payment_method_types=["card"],
line_items=[{
"price_data": {
"currency": "usd",
"product_data": {"name": "Pro Plan"},
"unit_amount": 999, # $9.99
},
"quantity": 1,
}],
mode="payment",
success_url="https://example.com/success",
cancel_url="https://example.com/cancel",
)
print(f"Checkout URL: {session.url}")
Test Cards
| Card Number | Result |
|---|---|
| 4242 4242 4242 4242 | Success |
| 4000 0000 0000 0002 | Declined |
| 4000 0000 0000 3220 | 3D Secure |
Any future expiry date and any CVC work.
Handle Webhooks
from flask import Flask, request
app = Flask(__name__)
@app.route("/webhook", methods=["POST"])
def webhook():
event = stripe.Webhook.construct_event(
request.data, request.headers["Stripe-Signature"],
"whsec_your_webhook_secret"
)
if event["type"] == "payment_intent.succeeded":
payment = event["data"]["object"]
print(f"Payment received: ${payment[amount]/100}")
return "", 200
Real Use Cases for Test Mode
- Build entire payment flow before going live
- Test edge cases (declined cards, 3DS, refunds)
- Build a SaaS prototype with working payments
- Practice webhook handling
- Portfolio project with real payment UX
More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
Top comments (0)