Repository navigation
fix: Make a customer's first card their default payment method - #119
Merged
Merged
Conversation
A first card could finish setup without becoming the billing account's default (#118). The portal designates the card default as soon as it turns Active, but the BillingAccount webhook read the card through the manager's cache, which can lag the API by about a second, and rejected it as still AwaitingConfirmation. Nothing retried. - Validate defaultPaymentMethodRef against the API server instead of the cache, as the BillingArrangement webhook already does. - Have the BillingAccount controller set the default when the account has none and exactly one Active payment method. An existing default is never replaced, and with several Active cards the customer chooses. The patch is optimistically locked so it can't overwrite a default set concurrently. - Index PaymentMethods by billing account for the lookup. - Add a webhook test with a stale cache, envtest specs for the defaulting, and a payment-method-default chainsaw test that sets a card Active and immediately designates it default. Fixes #118
mattdjenkinson
requested review from
JoseSzycho,
savme and
scotwells
and removed request for
savme and
scotwells
October 13, 2026 21:18
Contributor
Author
|
@JoseSzycho @scotwells could you take a look at this please? |
Contributor
|
@mattdjenkinson sure, taking a look in the next minutes |
JoseSzycho
approved these changes
Oct 19, 2026
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.
Summary
Fixes #118. A customer's first card could finish setup without becoming the billing account's default, which left the organization stuck short of onboarding. The portal designates the card default as soon as it turns Active. The BillingAccount webhook checked the card through the manager's cache, which can lag the API by about a second, so it rejected the request as if the card were still AwaitingConfirmation. Nothing retried.
Either change below closes the bug on its own. Together they also cover a browser that leaves before it designates the card.
defaultPaymentMethodRefis now validated withmgr.GetAPIReader(), as the BillingArrangement webhook already does. It costs one GET on a rare write. The comment onValidateBillingAccountDefaultPaymentMethodRefclaimed it already read the live API, so that's corrected too.Behaviour changes
payment-method-lifecyclee2e still passes. The controller may now set the default before the test links it, and applying the same ref is a no-op. I updated that step's description.Tests
payment-method-defaultchainsaw test: covers the same cases on a real cluster, including setting a card Active and immediately designating it default. On kind the cache usually catches up within milliseconds, so the unit test is the reliable guard against a regression.go test ./...(including envtest) and golangci-lint pass locally. The chainsaw tests haven't been run locally, so CI is their first run.Not in this PR
The PaymentMethod delete webhook also checks the account's default through the cache. A card deleted moments after it became the default could get past that check. It's the same class of bug, so I'm leaving it for a follow-up.