Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

The Annoying Piecewise Math Behind Payment Fees (and Migrating Off Lemon Squeezy Before March 2027) published: true

If you build SaaS or sell digital products, you probably think payment fee math is one line of code: const fee = price * 0.029 + 0.30; I thought the same thing when I started building SwiftKitHub as a side proje

If you build SaaS or sell digital products, you probably think payment fee math is one line of code:

const fee = price * 0.029 + 0.30;

I thought the same thing when I started building SwiftKitHub as a side project on muhammadjunaid.dev. Then I actually tried to make the numbers match real bank payouts — and ran straight into three things that break naive calculators.

1. Reverse invoicing breaks the moment a fee has a min/max cap

Solving "what should I invoice a client so I keep exactly $N after Stripe or PayPal takes their cut?" looks simple at first:

const gross = (targetNet + fixedFee) / (1 - rate);

That works until a seller turns on Instant Transfer (1.5%, minimum $0.50, maximum $15.00). Now the equation isn't linear anymore — it has three piecewise regimes depending on whether the intermediate payout hits the $0.50 floor, lands in the 1.5% middle band, or caps out at $15.00:

function solveReverseWithCappedTransfer(
  targetNet: number,
  feeRate: number,
  fixedFee: number
): number {
  const denom = 1 - feeRate;

  // Case 1: Instant transfer hits the $0.50 minimum floor
  const netBeforeFloor = targetNet + 0.50;
  if (netBeforeFloor * 0.015 <= 0.50) {
    return (netBeforeFloor + fixedFee) / denom;
  }

  // Case 2: Instant transfer sits inside the 1.5% linear band
  const netBeforeLinear = targetNet / (1 - 0.015);
  if (netBeforeLinear * 0.015 < 15.00) {
    return (netBeforeLinear + fixedFee) / denom;
  }

  // Case 3: Instant transfer hits the $15.00 hard cap
  return (targetNet + 15.00 + fixedFee) / denom;
}

If you skip that branch check and just divide by (1 - 0.015) on a $2,000 invoice, your calculator overcharges the client by more than $15. I ended up writing 548 automated math assertions just to keep edge cases like this honest across my PayPal Merchant Fee Calculator and Stripe tools.

2. The Lemon Squeezy shutdown forced a real MoR math rewrite

Right now a lot of indie devs are scrambling because Lemon Squeezy closed new sign-ups on Nov 16, 2026 and permanently stops processing and renewals on March 31, 2027.

When you actually model the migration choices side-by-side in December 2026, the flat "5% vs 2.9%" mental model falls apart:

  • Stripe Managed Payments (migration opened Dec 2, 2026) has a 1.5% promotional MoR fee through Dec 1, 2027 (on top of standard Stripe card fees), jumping to 3.5% standard after — and it still lacks built-in license keys, storefronts, and PayPal subscriptions.
  • Polar.sh moved to tiered monthly plans in May 2026: Starter ($0/mo at 5% + $0.50), Pro ($20/mo at 3.8% + $0.40), Growth ($100/mo at 3.6% + $0.35), and Scale ($400/mo at 3.4% + $0.30), plus +1.5% on non-US cards.
  • Direct Stripe + Stripe Tax (0.5%) + CPA/filing software looks cheaper on paper until you add a $100–$300/mo compliance cost at low MRR.

So instead of guessing in a spreadsheet, I wired up a full migration breakdown in Stripe vs. Lemon Squeezy vs. Polar MoR Calculator that finds the exact MRR break-even where switching tiers (or leaving an MoR completely) stops losing money.

3. The humbling SEO lesson I learned building this

Technically, the React + Vite static pre-rendering setup worked great. Everything runs 100% client-side with zero backend calls, zero login walls, and shareable URL permalinks.

In reality? Shipping code alone doesn't get users.

Early on I made every rookie mistake: bloated the site out to 136 thin pages, panicked and pruned it back down to 18 focused tools (including niche regulatory stuff like the new EU €3 customs duty + Nov 2026 €2 handling fee in the EU Low-Value Parcel Duty & IOSS Calculator), and watched 17 out of 18 pages sit in Google's "Crawled - currently not indexed" purgatory while I obsessively tweaked CSS and TypeScript instead of talking to actual humans.

Sharing what I'm actually building here is my attempt to stop coding in a cave.

If you're migrating off Lemon Squeezy before March 2027 — or if you've dealt with gnarly fee-stacking edge cases in your own billing code — I'd genuinely love to hear which provider you're moving to and what tripped you up.

You can poke at the tools at swiftkithub.com or see what else I'm building at muhammadjunaid.dev. Feedback (and bug reports if you manage to break the math!) is always welcome.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.