#itaied - payment intent source
1 messages · Page 1 of 1 (latest)
Good question. Checking in to it. Are you listening for subscription payments in another webhook or are you trying to do both in one event handler?
I'm doing it in the same event handler. My customers can both subscribe and one time purchase. I'm using the built-in checkout session, but it's not enough to listen to checkout.session.completed as capture_method of type manual require listening to payment_intent.amount_capturable_updated
So an easy way to check if the payment is from a subscription or not would be to check its invoice parameter. If the PaymentIntent is from a subscription, there will be an invoice ID in that field. Otherwise the field will be blank https://stripe.com/docs/api/payment_intents/object#payment_intent_object-invoice
This field won't be black only for subscriptions?
Good point. It will also be populated if you create one-off invoices
So you may want to retrieve the invoice and check that it has a subscription ID in its subscription field
Also depending on what you are doing, you may want to check the invoice's billing_reason field to see if it is for a subscription update/cycle/creation
OK I see.
It feels a bit of a hassle, do you think there is a better implementation path for what I'm trying to do?
Can you tell me a bit more about what you are trying to do here? So right now are you just trying to differentiate between one-off payments and your subscription payments via these webhook events?
yes, while also enabling manual capture (hold-capture later) and using the built-in checkout session pages
If those are all of your scenarios, you can just check that invoice field. If all of your payments are a one off manual payment or a subscription payment, that will successfully tell the difference between the two
Though actually in that case, you can just process invoice.paid events for your subscription payments and listen to a payment_intent event for the manual payments (checking exactly which event that should be)
payment_intent.amount_capturable_updated
ok I got it. thank you for your support
just sharing a thought here, I would like to hear your thoughts @open bolt .
I can listen for subscriptions using checkout.session.completed and verifying their event.data.object.mode is subscription. Right?
If a checkout session of mode subscription succeeded, then it's done, there is no pending state or something like that
Correct, you can also do that for the first payment. I was thinking first payment + subscription cycles when I said invoice.paid
yes but I would like to keep it as lean as possible, and I think I can avoid listening to invoice.paid events
Of course, whatever works for you