Commit 79e87f5
authored
fix: correct error semantics and add idempotency to financial-gateway webhook handler (#2039)
* fix: correct error semantics and add idempotency to webhook handler
- Define ErrMissingWebhookSecret and use it instead of ErrMissingTenantContext
when webhook secret is absent; the two errors describe distinct failure modes
- Introduce ProcessedEventChecker interface and GormProcessedEventChecker
implementation that queries event_outbox by causation_id
- Add EventChecker field to WebhookHandlerConfig; when set, duplicate Stripe
events are skipped with a 200 rather than re-published; check failures fall
through to publish to avoid silent event drops
- Set CausationID in PublishConfig so outbox entries carry the Stripe event ID,
enabling the DB-backed idempotency check
- Add tests: correct error body on empty secret, duplicate skip, check-error
fall-through
* fix: add tenant scoping and causation_id index to idempotency check
- GormProcessedEventChecker.IsProcessed now filters by tenant_id from
context in addition to causation_id, consistent with the multi-tenant
outbox pattern and preventing cross-tenant scope issues
- Add migration 20260329000001 with a partial index on event_outbox(causation_id)
WHERE causation_id IS NOT NULL to avoid sequential scans on idempotency
lookups as the outbox grows
* fix: use WithGormTenantTransaction for outbox idempotency check
Replace manual tenant_id WHERE clause with WithGormTenantTransaction
to properly set the search_path to the tenant schema, consistent with
the project's multi-tenant outbox pattern.
* fix: enforce atomic idempotency via unique causation_id index
- Make causation_id index UNIQUE to prevent concurrent duplicate inserts
- Handle duplicate key errors on the write path as already-processed
- Default EventChecker in constructor when DB is available
---------
Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>1 parent 81c7e78 commit 79e87f5
4 files changed
Lines changed: 244 additions & 2 deletions
File tree
- services/financial-gateway
- adapters/http
- migrations
Lines changed: 87 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
39 | 76 | | |
40 | 77 | | |
41 | 78 | | |
| |||
49 | 86 | | |
50 | 87 | | |
51 | 88 | | |
| 89 | + | |
52 | 90 | | |
53 | 91 | | |
54 | 92 | | |
| |||
66 | 104 | | |
67 | 105 | | |
68 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
69 | 111 | | |
70 | 112 | | |
71 | 113 | | |
| |||
81 | 123 | | |
82 | 124 | | |
83 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
84 | 130 | | |
85 | 131 | | |
86 | 132 | | |
87 | 133 | | |
88 | 134 | | |
| 135 | + | |
89 | 136 | | |
90 | 137 | | |
91 | 138 | | |
| |||
206 | 253 | | |
207 | 254 | | |
208 | 255 | | |
209 | | - | |
| 256 | + | |
210 | 257 | | |
211 | 258 | | |
212 | 259 | | |
| |||
252 | 299 | | |
253 | 300 | | |
254 | 301 | | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
255 | 320 | | |
256 | 321 | | |
257 | 322 | | |
| |||
266 | 331 | | |
267 | 332 | | |
268 | 333 | | |
| 334 | + | |
269 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
270 | 344 | | |
271 | 345 | | |
272 | 346 | | |
| |||
410 | 484 | | |
411 | 485 | | |
412 | 486 | | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
Lines changed: 154 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
470 | 470 | | |
471 | 471 | | |
472 | 472 | | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
473 | 627 | | |
474 | 628 | | |
475 | 629 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
0 commit comments