DEV Community

Alex Spinov
Alex Spinov

Posted on

Stripe Has a Free API (for Testing) — Build Payment Flows Without Spending a Cent

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
Enter fullscreen mode Exit fullscreen mode

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}")
Enter fullscreen mode Exit fullscreen mode

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}")
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Real Use Cases for Test Mode

  1. Build entire payment flow before going live
  2. Test edge cases (declined cards, 3DS, refunds)
  3. Build a SaaS prototype with working payments
  4. Practice webhook handling
  5. Portfolio project with real payment UX

More | GitHub


More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs

Top comments (0)