Repository navigation
Create the payment in payment_changed if payment.created hasn't arrived - #4
Merged
Merged
Conversation
When a stored card is charged it settles about a second after it is created, so the payment.changed webhook can be handled before payment.created has saved the local Payment. payment_changed then raised Payment.DoesNotExist, which also stopped any handlers registered after it. Use get_or_create like payment_created does, so whichever webhook comes first creates the row. Version 0.1.26. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 stored card is charged it settles about a second after the payment is created. The
payment.changedwebhook can then be handled beforepayment.createdhas saved the localPayment. When that happens, the defaultpayment_changedhandler raisedPayment.DoesNotExistand the webhook returned a 500.Handlers are run in order, so the exception also stopped any handlers registered after it. In godi_hirdirinn this meant carts were never marked paid even though the customer had been charged.
Fix
payment_changednow usesget_or_create, the same waypayment_createdalready does. Whichever webhook arrives first creates the row. A latepayment.createdfinds the existing row and leaves it alone, so a settled payment isn't reset topending.Version bumped to 0.1.26 in
setup.pyandrelease.sh.Testing
test_webhook_payment_changed_before_payment_created: sends a signedpayment.changed(statesettled) for an unknown payment, then the latepayment.created. It failed withPayment.DoesNotExistbefore the fix.ruffis clean.🤖 Generated with Claude Code