This commit is contained in:
Brandon Thomas committed 2025-09-12 01:00:03 -04:00
1 parent e48ee589ad
commit 2467d6f2c7
1 file changed
+34 -29
@@ -13,37 +13,9 @@ pub async fn payment_intent_succeeded_handler(
payment_intent: &PaymentIntent,
stripe_client: &Client
) -> Result<StripeArtcraftWebhookSummary, StripeArtcraftWebhookError> {
let payment_intent_id = payment_intent.id.to_string();
let mut should_ignore_retry = false;
let mut action_was_taken = false;
// Payment intent events are bare. They have absolutely no context about what they were for.
// No products, no checkout sessions, etc. We'll have to look them up on success.
info!("Look up payment...");
match payment_intent.status {
stripe_shared::PaymentIntentStatus::Succeeded => {
let purchase = lookup_purchase_from_payment_intent_success(&payment_intent_id, stripe_client)
.await
.map_err(|err| {
error!("Error looking up purchase from payment intent {}: {:?}", &payment_intent_id, err);
StripeArtcraftWebhookError::ServerError("error looking up purchase".to_string())
})?;
info!("Found purchase: {:?}", purchase);
info!("Found purchase: {:?}", purchase);
info!("Found purchase: {:?}", purchase);
info!("Found purchase: {:?}", purchase);
info!("Found purchase: {:?}", purchase);
//should_ignore_retry = true;
},
_ => {} // Fall-through
}
// NB: We'll need this to send them to the "customer portal", which is how they can modify
// or cancel their subscriptions.
let maybe_stripe_customer_id = payment_intent.customer
@@ -54,6 +26,39 @@ pub async fn payment_intent_succeeded_handler(
let maybe_user_token = payment_intent.metadata.get(STRIPE_ARTCRAFT_METADATA_USER_TOKEN)
.map(|t| t.to_string());
let mut should_ignore_retry = false;
let mut action_was_taken = false;
// Payment intent events are bare. They have absolutely no context about what they were for.
// No products, no checkout sessions, etc. We'll have to look them up on success.
let payment_succeeded = match payment_intent.status {
stripe_shared::PaymentIntentStatus::Succeeded => true,
_ => false,
};
if payment_succeeded {
info!("Payment intent succeeded. Looking up payment...");
let purchase = lookup_purchase_from_payment_intent_success(&payment_intent_id, stripe_client)
.await
.map_err(|err| {
error!("Error looking up purchase from payment intent {}: {:?}", &payment_intent_id, err);
StripeArtcraftWebhookError::ServerError("error looking up purchase".to_string())
})?;
if purchase.has_invoice {
// Subscription purchase. Let `invoice.paid` event handle this instead.
should_ignore_retry = true;
action_was_taken = false;
} else {
// TODO: Add credits.
should_ignore_retry = true;
action_was_taken = true;
}
}
Ok(StripeArtcraftWebhookSummary {
maybe_user_token,
maybe_event_entity_id: Some(payment_intent_id),