mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 10:53:23 +00:00
Enhance webhook detection with explicit context tracking and database optimization
- Add database index on version field for optimistic locking performance - Implement explicit webhook context tracking with symbols to avoid conflicts - Replace fragile webhook detection logic with robust context-based approach - Add request metadata support for enhanced debugging and audit trails - Simplify version management in payment collection hooks - Fix TypeScript compilation errors and improve type safety 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import type Stripe from 'stripe'
|
||||
import {
|
||||
webhookResponses,
|
||||
findPaymentByProviderId,
|
||||
updatePaymentStatus,
|
||||
updatePaymentFromWebhook,
|
||||
updateInvoiceOnPaymentSuccess,
|
||||
handleWebhookError,
|
||||
logWebhookEvent
|
||||
@@ -74,7 +74,7 @@ export const stripeProvider = (stripeConfig: StripeProviderConfig) => {
|
||||
// Verify webhook signature and construct event
|
||||
let event: Stripe.Event
|
||||
try {
|
||||
event = stripe.webhooks.constructEvent(body, signature, stripeConfig.webhookSecret)
|
||||
event = stripe.webhooks.constructEvent(body, signature, stripeConfig.webhookSecret!)
|
||||
} catch (err) {
|
||||
return handleWebhookError('Stripe', err, 'Signature verification failed')
|
||||
}
|
||||
@@ -117,12 +117,14 @@ export const stripeProvider = (stripeConfig: StripeProviderConfig) => {
|
||||
timestamp: new Date().toISOString(),
|
||||
provider: 'stripe'
|
||||
}
|
||||
const updateSuccess = await updatePaymentStatus(
|
||||
const updateSuccess = await updatePaymentFromWebhook(
|
||||
payload,
|
||||
payment.id,
|
||||
status,
|
||||
providerData,
|
||||
pluginConfig
|
||||
pluginConfig,
|
||||
'stripe',
|
||||
event.type
|
||||
)
|
||||
|
||||
// If payment is successful and update succeeded, update the invoice
|
||||
@@ -163,12 +165,14 @@ export const stripeProvider = (stripeConfig: StripeProviderConfig) => {
|
||||
timestamp: new Date().toISOString(),
|
||||
provider: 'stripe'
|
||||
}
|
||||
const updateSuccess = await updatePaymentStatus(
|
||||
const updateSuccess = await updatePaymentFromWebhook(
|
||||
payload,
|
||||
payment.id,
|
||||
isFullyRefunded ? 'refunded' : 'partially_refunded',
|
||||
providerData,
|
||||
pluginConfig
|
||||
pluginConfig,
|
||||
'stripe',
|
||||
event.type
|
||||
)
|
||||
|
||||
if (!updateSuccess) {
|
||||
|
||||
Reference in New Issue
Block a user