#joelalcedo - charges
1 messages ยท Page 1 of 1 (latest)
๐ Thanks for reaching out
You can listen to this webhook charge.succeeded
https://stripe.com/docs/api/events/types#event_types-charge.succeeded
is there to parameterize something like this for a specific paymentintent?
You have in the charge object, a field for the related PaymentIntent you can filter on it
https://stripe.com/docs/api/charges/object#charge_object-payment_intent
ok, i see. very helpful. does this flow make sense to you?
1. user checks out -> 2. paymentIntents.create -> 3. charge.succeseded -> 4. stripe.transfers.create
i'm not quite sure this is the most efficient thing to do, since step 3 requires pulling every successful charge over the last 30 days from the API every time a payment is made..if i have 1,000 charges that would be a more time consuming process. isn't there a more efficient way?
for example. would this work too?
const paymentIntent = await stripe.paymentIntents.retrieve(
'pi_3LMJxHGR0hudtWsC0kDo5tMW'
);
if i retrieve a specific payment intent, i can look at paymentIntent.charges
from the documentation of the payment intent data
i see there is a "charges" field
"charges": {
"object": "list",
"data": [],
"has_more": false,
"url": "/v1/charges?payment_intent=pi_3LMJxHGR0hudtWsC0kDo5tMW"
},
what is contained in the "data" field?
can i use the URL to fetch the charge ID?
since step 3 requires pulling every successful charge over the last 30 days from the API every time a payment is made..if i have 1,000 charges that would be a more time consuming process. isn't there a more efficient way?
What I mentioned to use is webhooks https://stripe.com/docs/webhooks, the idea is that you are getting notified every time there is a successful charge and then you do your related flowstripe.transfers.create
so if i understand correctly, the webhooks are an event listener that will fire during different events, so the idea would be to listen to the webhook, when a payment intent has succeeded, then i handle the transfer directly inside the webhook?
Yes that's the logic to follow
Between, your API listening to the webhook needs to respond quickly https://stripe.com/docs/webhooks#:~:text=Your endpoint must quickly return a successful status code (2xx)
then i handle the transfer directly inside the webhook?
You should do it asynchronously, just an advice ๐
ok, i will try this out, thanks so much!!!
what is the difference between these webhooks?
checkout.session.completed
and
charge.captured
Hi there ๐ jumping in as my teammate needed to step away.
The first is triggered whenever a customer completes the checkout flow associated with a Checkout Session, and the event will contain that Checkout Session object.
The latter is triggered whenever a Charge is captured, and the event will contain the associated Charge object.
i see, is the charge event emitted when the checkout is completed? i think the checkout.session.completed event doesn't actually contain the charge ID either
thanks for jumping in!!
The Checkout Session won't have the associated Charge's ID, that is located within the Payment Intent. So the path of objects to follow would be Checkout Session -> Payment Intent -> Charge.
charge.captured events won't be triggered unless you're manually capturing payments though. What you trying to be notified about?
i am trying to simply find a corresponding charge ID for a successful payment, then pass that charge ID into the stripe.transfers.create, which needs the charge_id under the following parameter source_transaction: "{CHARGE_ID}",
If you are using Checkout, you should go through Checkout Session -> Payment Intent -> Charge like toby said. That will be the charge ID that you can use for transfers here
hi Pompey! to make sure i understand correctly, would this step "Payment Intent -> Charge" be done through a webhook event listener?
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded(paymentIntent);
break;
i would try to look out for payment_intent.succeeded to get the corresponding charge ID?
Yes, in your webhook endpoint, you can listen for the checkout.session.completed event or the payment_intent.succeeded event. When you get them you can use the API's retrieve calls to get this info
Then look at the objects' fields. Checkout has a payment_intent field https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_intent
And PaymentIntents have charges list (the first one will be the successful charge if the payment intent has succeeded) https://stripe.com/docs/api/payment_intents/object#payment_intent_object-charges
You can also use expansion to get this data via a single API call https://stripe.com/docs/api/expanding_objects#expanding_objects
one moment while i wrap my head around this, thanks so much for the detail
ok, so i was able to successfully ingest an emitted a payment_intent object from my server during the payment_intent.succeeded event. i am noticing the charge_id is contained inside the fraud_details field.
is this always the case? if i want to retrieve the charge_id, i search for payment_intent.object.charges.fraud_details.charge_id
Can you send me the ID of this payment intent (pi_123)? As far as I know this should be directly in the objects in the charge list as id
sure, one sec
for some reason i can't initialize that payment intent in my app
Hi ๐ I'm stepping in for @ornate star
but for the real payment intent that is being generated, i am noticing the following:
when i listen to my webhook after a successful payment intent, the charge_id shows in the stripe webhook page (see second screenshot)
however, i am taking the full data from the event like this
event = stripe.webhooks.constructEvent( req.rawBody, req.headers["stripe-signature"], whSec,);
and then passing it into a firebase database to see all the data that came through (first attachment) - when the data is passed into firebase, there is no corresponding ID for the charge.
does the output from stripe.webhooks.constructEvent( req.rawBody, req.headers["stripe-signature"], whSec,); arrive asynchonously?
Can you please paste the charge ID? I cannot do anything with pictures
"id": "ch_3LdcF3GR0hudtWsC0quVPb7s",
Okay I've got the payment intent ID. Can you restate the actual question here please?
i figured it out -
the data field inside charges is an array, so to find the charge ID i had to do this:
dataObject.charges.data[0].id
my original question was why there wasn't an id field being emitted when i push the data to firestore
Which event?
payment_intent.succeeded
Okay yeah, in that case the dataObject is a Payment Intent
Payment Intents have an array of charges
in other words, when i push the output from event.data.object.charges.data, the corresponding charge "id" isn't contained in the actual data, it's its own separate field that i have to parse by looking at event.data.object.charges.data[0].id
if i had multiple charges for a payment intent i would have to do something like... event.data.object.charges.data.forEach((value){value.id})