惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
The Cloudflare Blog
量子位
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
D
DataBreaches.Net
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 聂微东
有赞技术团队
有赞技术团队
A
About on SuperTechFans

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Stripe vs Paddle vs Lemon Squeezy: What Wiring All Three ...
Gabriel Rode · 2026-05-18 · via DEV Community
Stripe Paddle Lemon Squeezy
Direct processor. Fastest to set up. You handle your own VAT and sales tax. Fits US-focused SaaS, or any product that already has tax infrastructure in place. Merchant of Record for higher volumes. Provides invoicing, revenue reports, and enterprise billing flows. Fits B2B SaaS or companies that need formal financial tooling and VAT handled at scale. Merchant of Record. Handles global tax on your behalf. Fits indie developers selling digital products internationally, where compliance matters more than optimizing fees.

I wired all three into the same codebase. Here is what you find out only by doing it.

Different billing providers have header names and verification methods. That's about the thing you can count on, but what about the rest? Let's take a look:

  • Stripe's webhook signature comes in the Stripe-Signature header.
  • Paddle's webhook signature comes in the Paddle-Signature header. It looks like this: ts=1704067200;h1=abc123def456.
  • Lemon Squeezy's webhook signature comes in the X-Signature header.

When you connect one billing provider you just learn its API, but when you connect three providers behind the same interface you really learn what billing is all about. You see what it looks like under all the software development kits (SDKs) and provider documentation.

The problem with integrating each provider

Most billing code is written using a providers SDK. It works fine until your business needs to switch providers or you want to run your tests without hitting a live API.

That's when you realize that your checkout logic, webhook handlers and subscription queries are all mixed up with Stripe's details. If you want to switch providers you have to rewrite the application layer.

A better approach would be to figure out what billing really means before deciding which provider to use.

The six-method protocol

In Python, a Protocol defines a contract through structural subtyping. Any class implementing the right methods satisfies it, without inheritance.

For billing, six methods cover the full lifecycle:

class BillingProvider(Protocol):
    async def list_plans(self) -> list[PlanResponse]: ...

    async def create_checkout(
        self, organization_id: str, plan_id: str,
        success_url: str, cancel_url: str

    ) -> CheckoutResponse: ...
    async def create_portal_session(
        self, organization_id: str, return_url: str
    ) -> PortalResponse: ...

    async def get_subscription(
        self, organization_id: str
    ) -> SubscriptionResponse | None: ...

    async def cancel_subscription(
        self, organization_id: str
    ) -> SubscriptionResponse: ...

    async def handle_webhook(
        self, payload: bytes, signature: str
    ) -> dict: ...

Enter fullscreen mode Exit fullscreen mode

The domain layer relies on the protocol. We have three adapters that use this protocol. Our application does not directly use Stripe, Paddle or Lemon Squeezy. It only uses a BillingProvider.

What implementing three adapters reveals

Webhook verification

Stripe delegates to its SDK:

event = stripe.Webhook.construct_event(
    payload, signature, self.config.webhook_secret
)

Enter fullscreen mode Exit fullscreen mode

Paddle uses a custom header format: ts=1704067200;h1=abc123. You split it, extract timestamp and hash, then verify manually:

parts = dict(part.split("=", 1) for part in signature.split(";"))
ts = parts.get("ts", "")
h1 = parts.get("h1", "")

expected = hmac.new(
    secret.encode(),
    f"{ts}:{payload.decode()}".encode(),
    hashlib.sha256
).hexdigest()

if not hmac.compare_digest(expected, h1):
    raise ValueError("Invalid Paddle webhook signature")

Enter fullscreen mode Exit fullscreen mode

Lemon Squeezy uses a direct HMAC-SHA256 over the raw payload:

expected = hmac.new(
    secret.encode(),
    payload,
    hashlib.sha256
).hexdigest()

if not hmac.compare_digest(expected, signature):
    raise ValueError("Invalid Lemon Squeezy webhook signature")

Enter fullscreen mode Exit fullscreen mode

Here is the rule for all three: you have to check the bytes before you do any JSON parsing. The signature is for the payload. If you parse the JSON first and then check it does not work because the JSON can change the bytes without you noticing.

Event types

After you have checked the payload you still need to know what is going on. Each provider names event types differently.

What happened Stripe Paddle Lemon Squeezy
Payment succeeded checkout.session.completed transaction.completed order_created
Subscription created customer.subscription.created subscription.created subscription_created
Subscription cancelled customer.subscription.deleted subscription.canceled subscription_cancelled
Payment failed invoice.payment_failed transaction.payment_failed subscription_payment_failed

Notice that Lemon Squeezy uses subscription_cancelled with two l's (the L letter), while Paddle uses subscription.canceled with only one l. A silly change that can make you debug code for hours.

Checkout URL location

You've created the checkout. Now you need the URL to redirect the user. Each provider puts it somewhere different.

Stripe: session.url

Paddle nests it inside a checkout object, but not reliably:

url = result.get("checkout", {}).get("url") or result.get("url", "")

Enter fullscreen mode Exit fullscreen mode

Lemon Squeezy uses JSON:API format, so everything lives under data.attributes:

url = data["data"]["attributes"]["url"]

Enter fullscreen mode Exit fullscreen mode

Portal sessions

The portal page is where customers can upgrade or downgrade or cancel. This page works differently depending on who is providing it.

Stripe requires creating a session before returning a URL:

session = await stripe_client.billing_portal.sessions.create_async(
    customer=customer_id,
    return_url=return_url
)
return PortalResponse(url=session.url)

Enter fullscreen mode Exit fullscreen mode

Paddle returns the portal URL directly on the customer object. No session creation:

customer = await self._get_customer(organization_id)
return PortalResponse(url=customer.portal_url)

Enter fullscreen mode Exit fullscreen mode

Lemon Squeezy stores it nested under customer.urls:

portal_url = customer_data["attributes"]["urls"]["customer_portal"]

Enter fullscreen mode Exit fullscreen mode

Status values

Subscription statuses look the same until they don't:

Stripe Paddle Lemon Squeezy
active active active
trialing trialing on_trial
past_due past_due past_due
canceled canceled cancelled
--- paused paused
incomplete --- ---

trialing versus on_trial. canceled versus cancelled.

These won't cause an error. They can cause your query for trials to return zero rows on two out of three providers, and you will spend an afternoon figuring out why.

Normalize at the adapter boundary - what enters the database should come from your vocabulary, and should not be copied from provider documents.

Plan feature metadata

Each provider has a different convention for storing the feature list shown on a pricing page.

Stripe uses marketing_features on the product, falling back to product metadata:

features = [f.name for f in product.marketing_features] \
    if product.marketing_features \
    else product.metadata.get("features", "").split(",")

Enter fullscreen mode Exit fullscreen mode

Paddle uses custom_data, falling back to description lines:

features = product.custom_data.get("features", []) \
    if product.custom_data \
    else [line for line in product.description.split("\n") if line.strip()]

Enter fullscreen mode Exit fullscreen mode

Lemon Squeezy parses variant description lines directly.

None of these options are wrong. They show three ways to think about where information about features is stored. The adapter keeps this hidden from the rest of the application.

What the abstraction makes visible

When we look at three adapters one thing becomes clear: the differences are not about the business logic.

The core ideas common for all three providers are the same:

  • how to define a subscription
  • when it starts
  • when it ends
  • is it active or cancelled

The differences are about how we connect to them: the names of headers, the structure of URLs, the words we use for events, the strings we use for status.

Why hexagonal architecture

The hexagonal architecture draws a line between these two concerns. The main part of the application does not know what a Stripe-Signature is. The main part of the application knows what a SubscriptionResponse is.

This has an effect on testing. With the protocol as the boundary each adapter can be tested alone using made payloads and real HMAC signatures. We do not need API accounts and we do not need to mock providers that might not behave like they do in production. All 110 tests across the domain, providers, configs, router, webhook and repository layers can run offline.

Choosing between the three

Once the architecture is in place choosing a provider is a business decision. The technical differences are real and quite limited.

Stripe has the mature software development kit and the best documentation. It also has the complex rules to follow when selling outside the US.

Paddle and Lemon Squeezy are both services that handle payments and taxes for us, send VAT and sales tax on our behalf. If we are selling to customers in the EU and do not want to register for tax in countries this matters even more.

Lemon Squeezy has the simplest way of working. JSON:API is a bit wordy but consistent. The webhook verification is the simplest of the three to do correctly.

Paddle has the flexible pricing models. We can charge based on usage, seats or custom plans. The ts=...;h1=... Signature format is the trickiest to get right and the easiest to get wrong without noticing.

If you take one thing from each section

First write down the six protocol methods as ideas before you look at the Stripe documentation. This one step helps you understand what billing means in your code without getting confused with what Stripe calls things. If you think about Stripe early it can mess up your understanding of what billing means.

Make status strings and event types consistent at the adapter boundary. The webhook handler should not see things like on_trial or subscription_cancelled.

When you check signatures use the bytes, not a re-serialized dictionary. If you convert JSON back and forth it can quietly change the bytes. That can cause a really bad kind of bug if someone tampers with the payload.

Do not pretend to check webhook signature verification in tests. Instead create a HMAC and use the real verification function. The Paddle format has cases that a pretend version will not catch, like what happens when the ts key is there but empty.

These patterns took me a while to get right. If you'd rather skip that, Billing Foundation is a paid starter kit that ships all three adapters already wired behind this Protocol, with 110 tests, a FastAPI backend, Next.js 16, PostgreSQL, Redis, Docker Compose, and an interactive (12-section) step-by-step tutorial runs in any browser.

You can start with a billing layer that you know works instead of debugging special cases like ts=...;h1=....

What's your experience ?

If you're running billing in production: which provider, and what's the edge case you hit that the documentation didn't mention?