Repository navigation
Fix custom-amount retries failing with a Stripe idempotency error - #146
Merged
Merged
Conversation
getOrCreatePriceForProduct compared Stripe's integer unit_amount with a float, so it never matched an existing price and created a new one on every request. A retry in the same form session reused the subscription idempotency key, but sent a different price, so Stripe rejected it before any card was charged (RE-174). - Round the amount to an integer number of minor units - Lowercase the currency, as Stripe stores it - Read every page of price search results, not just the first 10 - Only reuse a recurring price with the same interval Bump version to 1.4.47. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joaquimds
added a commit
that referenced
this pull request
Nov 11, 2026
Since #146 the plugin sends Stripe the plan's currency in lowercase. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
conatus
pushed a commit
that referenced
this pull request
Nov 11, 2026
Saving again now reuses the Stripe price of a plan priced in pence, so the test is no longer skipped, and the docs no longer list it as a known problem. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BL2bFrTk84JMy3CPAsCTV9
conatus
pushed a commit
that referenced
this pull request
Nov 12, 2026
StripePriceReuseTest (from #146) arrived with the merge of master. With phpcs and PHPStan now covering the tests: - Put the log stub's empty method bodies on their own lines (phpcbf). - Drop its CamelCaps phpcs:ignore comments; phpcs.xml excludes that rule for tests. - Reset Stripe's HTTP client to its default CurlClient rather than null, which the SDK's signature doesn't allow, as StripeInvoicePaidTest does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BL2bFrTk84JMy3CPAsCTV9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a member's first payment on a custom-amount tier was declined, every retry in the same form session failed before any card was charged. The error was a Stripe
IdempotencyException: "Keys for idempotent requests can only be used with the same parameters they were first used with."The retry correctly reused the subscription idempotency key. But
getOrCreatePriceForProductcompared Stripe's integerunit_amountwith a float ($amount * 100), so===never matched. Each request created a new Price, the subscription request changed, and Stripe rejected it. Production logs from the last month show 0 reused recurring prices, 88 newly created ones, and 30 failed retries across 6 members.Fix
In
getOrCreatePriceForProduct:(int) round($amount * 100), which also handles amounts like 3.30)getOrCreateOneTimePriceForProductnow reads every page too.Tests
New tests in
StripePriceReuseTestrun the real lookup against an in-memory fake of the Stripe API, including a regression test that submits the same custom-amount join twice and checks that both subscription requests are identical. 7 of the 8 tests fail without the fix.The existing
SubscriptionIdempotencyKeyTestchecked that the key was stable, but not that the request it protects was.Not covered
Version bumped to 1.4.47 with a changelog entry.
🤖 Generated with Claude Code