fix(billing): tolerate Razorpay notes:[] (polymorphic) in webhook entities#274
Merged
Merged
Conversation
…ities
Razorpay's `notes` field is polymorphic: an OBJECT when populated, an empty
ARRAY ([]) when absent. The structs used map[string]string, so a payment.failed
webhook carrying notes:[] failed to parse:
json: cannot unmarshal array into Go struct field rzpPaymentEntity.notes of type map[string]string
→ handlePaymentFailed swallowed the event and the immediate payment-failure
handling (SendPaymentFailed) never ran. Found by the live failure-path test
(bank-sim 'Failure' button → payment.failed with notes:[]).
New rzpNotes type with UnmarshalJSON that tolerates object / empty-array / null
(decoding only the object form), used by both the subscription and payment
entities. Tier-upgrade safety is unaffected (a failed payment never carried a
subscription.charged); this restores the failure-NOTIFICATION path.
Test: TestRzpNotes_ToleratesArrayObjectAndNull (notes:[] / {} / null / object).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… value) 100%-patch: a notes object with a non-string value exercises the decode-error path in rzpNotes.UnmarshalJSON (billing.go:1372-1373).
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.
Found by the live payment failure test
Driving the Razorpay bank-sim Failure button produced a
payment.failedwebhook withnotes:[], and the api logged:So
handlePaymentFailedswallowed the event and the immediate payment-failure handling (SendPaymentFailed) never ran. (Tier correctly stayedfree— a failed payment never carries subscription.charged — so the bug is the missing failure notification, not a false upgrade.)Fix
Razorpay's
notesis polymorphic: object when populated,[]when empty. NewrzpNotestype withUnmarshalJSONtolerating object / empty-array / null, used by both the subscription and payment entities. Test:TestRzpNotes_ToleratesArrayObjectAndNull.🤖 Generated with Claude Code