-
Notifications
You must be signed in to change notification settings - Fork 0
CIVIMM-426: Add webhook queue infrastructure for payment processors #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ef3df89 to
65cf38f
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds centralized webhook processing infrastructure for payment processors with automatic deduplication, retry logic, and queue management. The system eliminates code duplication across payment processor extensions by providing reusable base classes and services.
Key Changes:
- Webhook queue infrastructure with exponential backoff retry (5min → 15min → 45min)
- Auto-discovery of payment processors via dependency injection
- Scheduled job processing all webhooks every 5 minutes with batch limiting
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| xml/schema/CRM/Paymentprocessingcore/PaymentWebhook.xml | Added retry fields (attempts, next_retry_at) and permanent_error status |
| sql/auto_install.sql | Added database columns and index for retry logic |
| managed/Job_WebhookQueueRunner.mgd.php | Scheduled job definition for webhook processing |
| api/v3/WebhookQueueRunner/Run.php | API endpoint for processing webhook queues |
| Civi/Paymentprocessingcore/Webhook/WebhookHandlerInterface.php | Interface contract for webhook handlers |
| Civi/Paymentprocessingcore/Service/WebhookReceiverService.php | Abstract base class for webhook receivers |
| Civi/Paymentprocessingcore/Service/WebhookQueueService.php | Queue management service |
| Civi/Paymentprocessingcore/Service/WebhookQueueRunnerService.php | Queue processing with retry logic |
| Civi/Paymentprocessingcore/Service/WebhookHandlerRegistry.php | Handler registry for auto-discovery |
| CRM/Paymentprocessingcore/BAO/PaymentWebhook.php | Database operations for webhook management |
| tests/phpunit/TESTING.md | Testing strategy documentation |
| tests/phpunit/**/*Test.php | Unit tests for webhook infrastructure |
| README.md | Documentation of webhook system |
| CLAUDE.md | Architecture documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Civi/Paymentprocessingcore/Service/WebhookQueueRunnerService.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
65cf38f to
21a7f5e
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…k detection Add processing_started_at timestamp field to track when webhooks enter processing state, fixing critical bug where resetStuckWebhooks() incorrectly used created_date. Changes: - Add processing_started_at field to PaymentWebhook schema - Update updateStatusAtomic() to set timestamp when status becomes 'processing' - Refactor updateStatusAtomic() to use API4 instead of raw SQL - Fix resetStuckWebhooks() to use processing_started_at instead of created_date - Add 4 comprehensive tests for processing_started_at functionality - Regenerate DAO files with new schema
6683bea to
79b6c2f
Compare
Overview
Add centralized webhook processing infrastructure that payment processors can use for async webhook handling with automatic deduplication, retry logic, and queue management. This eliminates code
duplication across payment processor extensions.
Before
Each payment processor extension implemented its own webhook handling:
After
Payment processors extend base classes and register handlers via DI:
Architecture
Components Overview
Database Schema
civicrm_payment_webhook
Retry Logic Deep Dive
How Retry Works
When a webhook fails to process, the system implements exponential backoff retry:
Attempt 1 → Fails → Wait 5 minutes → Retry (Attempt 2)
Attempt 2 → Fails → Wait 15 minutes → Retry (Attempt 3)
Attempt 3 → Fails → Wait 45 minutes → Permanent Error
Constants:
Retry Flow
Example Timeline
Webhook arrives at 10:00 AM:
Total time before permanent error: ~20 minutes
Stuck Webhook Recovery
If a webhook gets stuck in "processing" status (e.g., server crash during processing), it's automatically reset:
Called automatically at the start of each scheduled job run.
Monitoring Failed Webhooks
Query webhooks needing attention:
Step 2: Create Event Handler
Implement WebhookHandlerInterface for each event type:
Step 3: Register Handler
Register handlers in your extension's ServiceContainer:
Step 4: That's It!
The infrastructure handles: