<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Henrique Miguel</title>
    <description>The latest articles on DEV Community by Henrique Miguel (@henrique_miguel_983f83345).</description>
    <link>https://dev.to/henrique_miguel_983f83345</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263232%2Fbe1e4b0a-c5ed-4838-85ba-95132b2368b0.jpg</url>
      <title>DEV Community: Henrique Miguel</title>
      <link>https://dev.to/henrique_miguel_983f83345</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/henrique_miguel_983f83345"/>
    <language>en</language>
    <item>
      <title>How to Handle Stripe's invoice.payment_failed Webhook (Without Breaking Dunning)</title>
      <dc:creator>Henrique Miguel</dc:creator>
      <pubDate>Tue, 24 Nov 2026 18:21:11 +0000</pubDate>
      <link>https://dev.to/henrique_miguel_983f83345/how-to-handle-stripes-invoicepaymentfailed-webhook-without-breaking-dunning-846</link>
      <guid>https://dev.to/henrique_miguel_983f83345/how-to-handle-stripes-invoicepaymentfailed-webhook-without-breaking-dunning-846</guid>
      <description>&lt;p&gt;Every SaaS billing integration eventually hits the same milestone: a customer's renewal fails, and you decide to listen to Stripe's &lt;code&gt;invoice.payment_failed&lt;/code&gt; webhook to send a recovery email.&lt;/p&gt;

&lt;p&gt;The webhook handler takes 20 minutes to write. The edge cases take months to discover.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Extract the actual &lt;code&gt;decline_code&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;When &lt;code&gt;invoice.payment_failed&lt;/code&gt; fires, don't treat all failures the same way. Inspect the underlying &lt;code&gt;payment_intent.last_payment_error.decline_code&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;webhooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;constructEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rawBody&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;webhookSecret&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"invoice.payment_failed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Branch on soft vs. hard decline codes:&lt;/span&gt;
  &lt;span class="c1"&gt;// - Hard declines (expired_card, lost_card, authentication_required): email on day 0&lt;/span&gt;
  &lt;span class="c1"&gt;// - Soft declines (insufficient_funds, do_not_honor): wait 48h for Smart Retries&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want a zero-dependency TypeScript helper that classifies 45+ Stripe &lt;code&gt;decline_code&lt;/code&gt; values into &lt;code&gt;soft&lt;/code&gt; vs. &lt;code&gt;hard&lt;/code&gt;, I open-sourced it here: &lt;a href="https://github.com/Henrique1817/stripe-decline-classifier" rel="noopener noreferrer"&gt;stripe-decline-classifier on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Four traps that break DIY dunning
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate emails on Smart Retries:&lt;/strong&gt; Stripe fires &lt;code&gt;invoice.payment_failed&lt;/code&gt; on &lt;em&gt;every&lt;/em&gt; retry attempt. Without per-invoice state tracking, customers get emailed 4 times for one temporary &lt;code&gt;insufficient_funds&lt;/code&gt; decline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting to cancel queued emails:&lt;/strong&gt; You also need to listen to &lt;code&gt;invoice.paid&lt;/code&gt; and &lt;code&gt;customer.subscription.deleted&lt;/code&gt; to stop follow-ups when a payment succeeds or cancels.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3D Secure (&lt;code&gt;authentication_required&lt;/code&gt;):&lt;/strong&gt; Retrying won't pass SCA. Customers need a hosted confirmation link, not a generic card-update form.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No expiring-card visibility:&lt;/strong&gt; &lt;code&gt;invoice.payment_failed&lt;/code&gt; only fires &lt;em&gt;after&lt;/em&gt; a payment fails.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you want to see how much MRR is currently stuck in soft vs. hard declines (and cards expiring in the next 30–90 days) without writing webhook queues first, you can run a free read-only 90-day scan at &lt;a href="https://savedmrr.company" rel="noopener noreferrer"&gt;SavedMRR&lt;/a&gt; or check the &lt;a href="https://savedmrr.company/decline-codes" rel="noopener noreferrer"&gt;45+ Stripe decline codes reference&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>saas</category>
      <category>stripe</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
