<?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: Abhijit Shilawat</title>
    <description>The latest articles on DEV Community by Abhijit Shilawat (@abhishilawat).</description>
    <link>https://dev.to/abhishilawat</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%2F4272730%2Fcd07f785-aa8e-49c2-b60e-b239cfa705a1.png</url>
      <title>DEV Community: Abhijit Shilawat</title>
      <link>https://dev.to/abhishilawat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhishilawat"/>
    <language>en</language>
    <item>
      <title>Why Stripe payment retries fail in WooCommerce (and the one-line cause)</title>
      <dc:creator>Abhijit Shilawat</dc:creator>
      <pubDate>Sun, 29 Nov 2026 18:25:46 +0000</pubDate>
      <link>https://dev.to/abhishilawat/why-stripe-payment-retries-fail-in-woocommerce-and-the-one-line-cause-4b48</link>
      <guid>https://dev.to/abhishilawat/why-stripe-payment-retries-fail-in-woocommerce-and-the-one-line-cause-4b48</guid>
      <description>&lt;p&gt;A customer's card is declined at checkout. They try again, maybe with the same card after approving a bank notification, maybe from their phone instead of their laptop. Instead of going through, the payment fails again with a confusing error. Some give up; others email support.&lt;/p&gt;

&lt;p&gt;On a WooCommerce membership platform I support (FunnelKit checkout + Stripe), this was happening regularly. The cause turned out to be a single piece of data: the customer's browser &lt;strong&gt;user-agent&lt;/strong&gt; string.&lt;/p&gt;

&lt;h2&gt;
  
  
  A quick primer on Stripe idempotency keys
&lt;/h2&gt;

&lt;p&gt;When a payment plugin sends a request to Stripe, it can include an &lt;strong&gt;idempotency key&lt;/strong&gt;: a unique label for that operation. If the same request is sent twice (say, after a network hiccup), Stripe recognises the key and returns the original result instead of charging the customer twice.&lt;/p&gt;

&lt;p&gt;There's one strict rule: &lt;strong&gt;a key can only be reused with exactly the same parameters.&lt;/strong&gt; If a request arrives with a key Stripe has already seen, but any of the data differs, Stripe rejects it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Keys for idempotent requests can only be used with the same parameters
they were first used with.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stripe remembers keys for about 24 hours, so any retry within a day is subject to this rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the user-agent comes in
&lt;/h2&gt;

&lt;p&gt;Payment plugins often attach &lt;strong&gt;metadata&lt;/strong&gt; to Stripe payments: order number, customer details, and sometimes the customer's browser user-agent (useful for fraud review).&lt;/p&gt;

&lt;p&gt;The trouble starts when the idempotency key is based on the &lt;em&gt;order&lt;/em&gt;, but the metadata includes the &lt;em&gt;current&lt;/em&gt; browser's user-agent:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First attempt: the order's key, with the laptop browser's user-agent in the metadata. The bank declines it.&lt;/li&gt;
&lt;li&gt;The customer retries the same order from their phone, or after their browser updates. Same key (same order), different user-agent.&lt;/li&gt;
&lt;li&gt;Stripe sees a reused key with different parameters and rejects the request before the card is even tried again.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Attempt 1  key: order-1234   metadata.user_agent: "Mozilla/5.0 (Windows NT 10.0 ..."  -&amp;gt; card declined
Attempt 2  key: order-1234   metadata.user_agent: "Mozilla/5.0 (iPhone; CPU iPhone OS ..."  -&amp;gt; idempotency error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To the customer, their second attempt failed for no reason. To the store, a sale was lost to one line of text.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;WooCommerce already saves the customer's user-agent on the order when it's created. A small must-use plugin makes the payment metadata use &lt;strong&gt;the user-agent saved on the order&lt;/strong&gt; rather than the one from the current request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The value saved when the order was created: identical on every retry.&lt;/span&gt;
&lt;span class="nv"&gt;$user_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_customer_user_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now every retry for the same order sends identical data, so the idempotency key is reused correctly. Stripe's duplicate protection still works, and genuine retries go through.&lt;/p&gt;

&lt;p&gt;We applied it through the checkout plugin's own filters, without editing FunnelKit or the Stripe gateway, so it survives updates. If those filters change in a future version, the fix simply stops applying rather than breaking checkout.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to tell if you have this problem
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;Stripe dashboard&lt;/strong&gt;, check &lt;em&gt;Developers → Logs&lt;/em&gt; for failed requests mentioning idempotent requests or idempotency keys.&lt;/li&gt;
&lt;li&gt;In &lt;strong&gt;WooCommerce&lt;/strong&gt;, look for orders that failed and then show a second failed attempt minutes later, especially where customers told support "I tried twice".&lt;/li&gt;
&lt;li&gt;Check whether your payment plugin adds the user-agent, IP address or other "current request" data to Stripe metadata. &lt;strong&gt;Any value that can change between attempts can cause the same conflict.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why small fixes like this matter
&lt;/h2&gt;

&lt;p&gt;Failed payments are already a leak: some customers never retry. When the retry itself is broken, you lose the customers who were trying hardest to pay you. On this platform, fixing payment retries and related issues contributed to more than &lt;strong&gt;$25,000 in recovered failed payments&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Two related fixes from the same project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers paying an existing order through a "Pay for order" link were being redirected to a fresh checkout. We stopped WooCommerce, FunnelKit and Subscriptions from overriding that page.&lt;/li&gt;
&lt;li&gt;When a retried payment finally succeeds, affiliates should still get their commission. AffiliateWP doesn't do that by default: &lt;a href="https://webweavio.com/blog/affiliatewp-referrals-rejected-after-failed-payment" rel="noopener noreferrer"&gt;how we recovered rejected referrals after failed payments&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://webweavio.com/blog/funnelkit-stripe-payment-retry-idempotency-error" rel="noopener noreferrer"&gt;WebWeavio&lt;/a&gt;. I'm Abhijit, a freelance WordPress developer working on WooCommerce, LearnDash and custom plugins. The &lt;a href="https://webweavio.com/portfolio/learndash-buddyboss-membership-platform-reliability-retainer" rel="noopener noreferrer"&gt;full case study&lt;/a&gt; covers everything we fixed on this platform.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>woocommerce</category>
      <category>stripe</category>
      <category>php</category>
    </item>
  </channel>
</rss>
