#syed - webhooks
1 messages · Page 1 of 1 (latest)
thank you!
using stripe checkout to do this btw https://stripe.com/docs/payments/save-and-reuse?platform=checkout
unsure if this is an important detail
ah, there's no payment_method attribute on the Checkout session object
You'll likely want to grab the Session's payment_intent attribute: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_intent
Then make a separate call to get the PaymentIntent's payment_method: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-payment_method
hmmmm would doing something like @user.update(payment_method_id: session.payment_intent.payment_method) be a legal move?
I see what you're getting at! Some endpoints support expanding objects but expansion isn't possible with webhook events
More info on expansion is available here: https://stripe.com/docs/expand
So, for example, say you make that separate call to get the PaymentIntent's payment_method . You can opt to expand the payment_method attribute in that call if you want to get the full PaymentMethod object as well, not just its ID
Hmmm, I think I may have overcomplicated the problem I'm trying to solve.
I wanted to retrieve the payment_method attribute and use it as a way to verify that the user does in fact have a card saved to make later payments (by simply just checking if the value is null or not). Is there a simpler way that I should go about this?
Got it. I recommend following the guide you linked above: https://stripe.com/docs/payments/save-and-reuse?platform=checkout#retrieve-checkout-session
The checkout.session.completed event should have a SetupIntent ID. This means the customer successfully provided their payment details.
If you need to pull the PaymentMethod ID (either to create a charge at a later time or store it in some internal database) you can make a call to get the SetupIntent. The PaymentMethod ID should be returned in the response.
gotcha, I'll give that a shot. Thanks for all the help!
One last question: would it be possible to use setup_intent.created? I use checkout.session.completed in another function to verify the user has subscribed to a plan in my app, and it seems to falsely say the user is subscribed when going through the save card for later flow @blazing escarp
setup_intent.created will be sent when a customer has shared their payment details successfully, and their payment details can be used to create charges at a future date
checkout.session.completed will be sent when a customer successfully submits payment details using Checkout. However, this event could be sent for Checkout's setup mode (when saving details for a future charge), payment mode (when a one-time payment was made), or subscription mode (when a payment was made to create a subscription)
If you're looking for Subscription-specific events, I recommend listening for the events listed here: https://stripe.com/docs/billing/subscriptions/webhooks#events