DEV Community

Alex Spinov
Alex Spinov

Posted on

Stripe Has a Free Payment API — Accept Payments with 10 Lines of Code

Stripe's API handles payments, subscriptions, invoicing, and billing portals. Free to integrate — you only pay per transaction (2.9% + $0.30).

Why Every SaaS Uses Stripe

PayPal: checkout redirects, iframe hell, inconsistent APIs.
Stripe: a REST API that makes payments feel like any other API call.

What You Get for Free (No Monthly Fee)

One-time payments:

const session = await stripe.checkout.sessions.create({
  line_items: [{
    price_data: {
      currency: 'usd',
      product_data: { name: 'Pro Plan' },
      unit_amount: 2999, // $29.99
    },
    quantity: 1,
  }],
  mode: 'payment',
  success_url: 'https://myapp.com/success',
  cancel_url: 'https://myapp.com/cancel',
});
// Redirect user to session.url
Enter fullscreen mode Exit fullscreen mode

Subscriptions:

const subscription = await stripe.subscriptions.create({
  customer: 'cus_xxx',
  items: [{ price: 'price_xxx' }], // recurring price
  trial_period_days: 14,
});
Enter fullscreen mode Exit fullscreen mode

Webhooks (real-time events):

app.post('/webhook', (req, res) => {
  const event = stripe.webhooks.constructEvent(req.body, sig, secret);
  switch (event.type) {
    case 'checkout.session.completed':
      // Activate user's account
      break;
    case 'invoice.payment_failed':
      // Send dunning email
      break;
  }
  res.sendStatus(200);
});
Enter fullscreen mode Exit fullscreen mode

What Stripe Handles

  • Checkout — hosted payment page (PCI-compliant, mobile-friendly)
  • Billing Portal — customers manage their own subscriptions
  • Invoicing — automatic invoice generation and delivery
  • Tax — automatic tax calculation for 130+ countries
  • Fraud detection — Radar ML-based fraud prevention
  • Connect — marketplace payments (pay sellers, take commission)

Quick Start

npm i stripe
Enter fullscreen mode Exit fullscreen mode
import Stripe from 'stripe';
const stripe = new Stripe('sk_test_...');
Enter fullscreen mode Exit fullscreen mode

Test Mode

Stripe's test mode is identical to production. Use test API keys, test card numbers (4242 4242 4242 4242), and test webhooks. Ship with confidence.

If you're building a product that charges money — Stripe setup takes 30 minutes and handles everything.


Need web scraping or data extraction? Check out my tools on Apify — get structured data from any website in minutes.

Custom solution? Email spinov001@gmail.com — quote in 2 hours.

Top comments (0)