use crate::client::Stripe;
use crate::webhook::events::ProcessStripeWebhook;
use crate::webhook::verify_webhook;
use crate::Error;
pub async fn handle_platform_webhook(raw_body: &str, signature: &str) -> Result<(), Error> {
let event = verify_webhook(raw_body, signature, &Stripe::config().webhook_secret)?;
let job = ProcessStripeWebhook {
event_type: event.type_.to_string(),
event_json: raw_body.to_string(),
connect_account_id: None,
};
ferro_queue::dispatch(job)
.await
.map_err(|e| Error::Stripe(format!("failed to dispatch webhook job: {e}")))?;
Ok(())
}
pub async fn handle_connect_webhook(raw_body: &str, signature: &str) -> Result<(), Error> {
let connect_secret = Stripe::config()
.connect_webhook_secret
.as_deref()
.ok_or_else(|| Error::Config("STRIPE_CONNECT_WEBHOOK_SECRET not set".to_string()))?;
let event = verify_webhook(raw_body, signature, connect_secret)?;
let connect_account_id = event.account.map(|id| id.to_string());
let job = ProcessStripeWebhook {
event_type: event.type_.to_string(),
event_json: raw_body.to_string(),
connect_account_id,
};
ferro_queue::dispatch(job)
.await
.map_err(|e| Error::Stripe(format!("failed to dispatch webhook job: {e}")))?;
Ok(())
}