fix: emit a consistent webhook payload from both dispatch paths#1
Open
2ro wants to merge 1 commit into
Open
Conversation
The two webhook dispatch paths drifted in payload shape: - GrinService.DispatchWebhook (checkout / broadcast -> InvoiceProcessing) sent top-level `invoiceId` + `storeId`, `invoice.confirmations`, and `metadata.order_id`. - GrinPaymentMonitorService.DispatchWebhookAsync (settled / invalid / expired) omitted `invoiceId`, `storeId` and `confirmations`, and used `metadata.medusa_cart_id` instead of `metadata.order_id`. So a webhook consumer that handles both broadcast and settlement events sees two different shapes, and any consumer keyed on `metadata.order_id` silently drops every settlement/expiry (the broadcast arrives, but the order never advances or cancels). The in-code comments claiming the two paths are kept "bit-for-bit identical" only ever applied to the signature encoding, not the payload. Extract a single GrinWebhookPayload.Build() used by both paths so they can't drift. To stay backward compatible the order reference is emitted under BOTH `order_id` and `medusa_cart_id` (same value), and the monitor path now also includes `invoiceId`, `storeId` and `confirmations`. No signature-format change (WebhookSignatureTests still pass). Co-Authored-By: Claude Opus 4.8 (1M context) <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.
What
The plugin has two webhook dispatch paths and they had drifted in payload shape:
GrinService.DispatchWebhook(checkout / broadcast →InvoiceProcessing) sent top-levelinvoiceId+storeId,invoice.confirmations, andmetadata.order_id.GrinPaymentMonitorService.DispatchWebhookAsync(settled / invalid / expired) omittedinvoiceId,storeId, andconfirmations, and usedmetadata.medusa_cart_idinstead ofmetadata.order_id.Why it matters
A webhook consumer that handles both broadcast and settlement events sees two different shapes. Any consumer keyed on
metadata.order_idsilently drops every settlement/expiry event — the broadcast arrives, but the order never advances or cancels. (The in-code comments claiming the two paths are kept "bit-for-bit identical" only ever applied to the signature encoding, not the payload.)Fix
Extract a single
GrinWebhookPayload.Build()used by both paths so they can no longer drift.To stay backward compatible, the order reference is emitted under both
order_idandmedusa_cart_id(same value), and the monitor path now also includesinvoiceId,storeId, andconfirmations.No signature-format change —
WebhookSignatureTestsstill pass.Changes
BTCPayServer.Plugins.Grin/Services/GrinWebhookPayload.cs— single source of truth for the payload.GrinService.csandGrinPaymentMonitorService.csnow both callGrinWebhookPayload.Build(invoice, eventType).