| 63 |
63 |
|
|
| 64 |
64 |
|
// Route by event type
|
| 65 |
65 |
|
if thin.event_type.starts_with("v2.core.account") {
|
| 66 |
|
- |
handle_account_thin_event(&state, stripe.as_ref(), &thin).await;
|
|
66 |
+ |
if let Err(e) = handle_account_thin_event(&state, stripe.as_ref(), &thin).await {
|
|
67 |
+ |
// Unmark so Stripe retries delivery (retries for up to 3 days)
|
|
68 |
+ |
tracing::warn!(event_id = %thin.id, error = ?e, "v2 event processing failed, unmarking for retry");
|
|
69 |
+ |
let _ = db::webhook_events::unmark_event_processed(&state.db, &thin.id).await;
|
|
70 |
+ |
return Err(e);
|
|
71 |
+ |
}
|
| 67 |
72 |
|
} else {
|
| 68 |
73 |
|
tracing::debug!(event_type = %thin.event_type, "unhandled v2 event type");
|
| 69 |
74 |
|
}
|
| 72 |
77 |
|
}
|
| 73 |
78 |
|
|
| 74 |
79 |
|
/// Fetch the full account object and delegate to the shared account-updated handler.
|
| 75 |
|
- |
///
|
| 76 |
|
- |
/// On API fetch failure we log a warning and return gracefully — the v2
|
| 77 |
|
- |
/// endpoint still returns 200 to acknowledge receipt and prevent Stripe retries.
|
| 78 |
80 |
|
async fn handle_account_thin_event(
|
| 79 |
81 |
|
state: &AppState,
|
| 80 |
82 |
|
stripe: &dyn payments::PaymentProvider,
|
| 81 |
83 |
|
thin: &ThinEvent,
|
| 82 |
|
- |
) {
|
|
84 |
+ |
) -> Result<()> {
|
| 83 |
85 |
|
let account_id = match &thin.related_object {
|
| 84 |
86 |
|
Some(obj) => &obj.id,
|
| 85 |
87 |
|
None => {
|
| 86 |
88 |
|
tracing::warn!(event_id = %thin.id, "v2 account event missing related_object");
|
| 87 |
|
- |
return;
|
|
89 |
+ |
return Ok(()); // nothing to fetch — acknowledge
|
| 88 |
90 |
|
}
|
| 89 |
91 |
|
};
|
| 90 |
92 |
|
|
| 91 |
|
- |
match stripe.fetch_account(account_id).await {
|
| 92 |
|
- |
Ok(update) => {
|
| 93 |
|
- |
if let Err(e) = super::webhook::handle_account_updated_from_v2(state, &update).await {
|
| 94 |
|
- |
tracing::warn!(
|
| 95 |
|
- |
account_id = %account_id, error = ?e,
|
| 96 |
|
- |
"failed to process account update from v2 event"
|
| 97 |
|
- |
);
|
| 98 |
|
- |
}
|
| 99 |
|
- |
}
|
| 100 |
|
- |
Err(e) => {
|
| 101 |
|
- |
tracing::warn!(
|
| 102 |
|
- |
account_id = %account_id, error = ?e,
|
| 103 |
|
- |
"failed to fetch account for v2 event, acknowledging anyway"
|
| 104 |
|
- |
);
|
| 105 |
|
- |
}
|
| 106 |
|
- |
}
|
|
93 |
+ |
let update = stripe.fetch_account(account_id).await.map_err(|e| {
|
|
94 |
+ |
tracing::warn!(account_id = %account_id, error = ?e, "failed to fetch account for v2 event");
|
|
95 |
+ |
e
|
|
96 |
+ |
})?;
|
|
97 |
+ |
|
|
98 |
+ |
super::webhook::handle_account_updated_from_v2(state, &update).await.map_err(|e| {
|
|
99 |
+ |
tracing::warn!(account_id = %account_id, error = ?e, "failed to process account update from v2 event");
|
|
100 |
+ |
e
|
|
101 |
+ |
})?;
|
|
102 |
+ |
|
|
103 |
+ |
Ok(())
|
| 107 |
104 |
|
}
|