#anon-paymentintent-charge
1 messages ยท Page 1 of 1 (latest)
@haughty granite let's chat here
Yo!
Can you remove the other message from the main channel? It helps us keep it clean ๐
done
Yeah so I get this very strange error.
I'm a little confused about the secret
I see you provide one automatically in the webhook example
I also see you provide one here. However, I had success with the one in the boilerplate example.
Oh I meant removing the second message where you shared your code ๐
not the original (first) one
All good, what error message are you seeing?
How exactly are you triggering the event/request?
If you're making a POST manually via POSTMAN or something then this is expected
Charge.refunded. or charge.refund.updated
No, I mean how exactly are you testing your code?
I'm using something similar to ngrok
How are you invoking the code on your webhook endpoint?
and what exactly is making a request to /refund ?
gotcha. if you console.log(req.body) before calling constructEvent then what do you see in the output?
Ideally you should be seeing binary data
but if you see JSON instead then you might have a middleware that's parsing the incoming request before it hits /refund route
yeah, I read about this on Stack Overflow
That's why I moved the payments route above this bodyParser.json()).
have you tried console.log(req.body) yet to confirm if its still being parsed to JSON or not?
yeah, it's weird, getting nothing.
If found one more middleware I'm moving the route above.
ahhh
So when you print out req.body its just null?
my ngrok is down
ah
๐
ok it's working now, let me do it one more time with a message so I know what I'm looking at.
๐
So this looks good
Still getting the error or no?
Yeah I guess I'm confused about what key to use.
Use the one from the dashboard
yup
ok
each endpoint has a diff secret
yay! praise the Stripe tech support!
Thank you sir ๐
MailChimp should take some pointers from Stripe in terms of good API support ๐
Can I give you a 5 star review?
NP! ๐ Happy to help
Glad that you're unblocked
I actually have another question
So when I make the checkout session
Where should I add the Db ID of the user so that it comes back with this charge.refunded object? Also, I need an identifier for the product.
So Checkout Session object and Charge Refund objects are not directly related.
Checkout Session object has a PaymentIntent, the PaymentIntent creates a charge underneath.
ok, so dang
charge.refunded has the charge object as payload
The charge object has the customer parameter you can expand
https://stripe.com/docs/api/charges/object?lang=node#charge_object-customer
ok so I can check this customer object in ```js
await stripe.checkout.sessions.create()
Oh you want to add your local DB user ID to it, hmm
You'd want to use client_reference_id for that
https://stripe.com/docs/api/checkout/sessions/create?lang=node#create_checkout_session-client_reference_id
Yeah I use that but I doesn't come back on the refund object
The email does
and I need a product name sent with it as well
Gotcha. In that case, you can find the PaymentIntent ID on the Charge object
https://stripe.com/docs/api/charges/object#charge_object-payment_intent
And list the Checkout Session object using the PaymentIntent ID
https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent
That should get you the Checkout Session object with the client_reference_id
When you list the checkout session, you can expand line_items
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
yep I see the payment intent
That should get you your local DB user ID and the line items
ok great, so you you're saying I can get the list via ```js
stripe.charges.list();
Then find the all of this info using the PaymentIntent ID
you don't need to get a list for the charge. The charge object is the payload when you receive charge.refunded event
It should have the PaymentIntent ID already
url: '/v1/charges/ch_3NNdL6CrnLkr8CZ70N9CrpXT/refunds'
I see this
const chargeRefunded = event.data.object;
const payment = await stripe.charges.retrieve(chargeRefunded.payment_intent);
You don't see PaymentIntent ID when you console log event.data.object ?
Yes I do, I don't know what to do it with it. Make another API call to get the info?
Use stripe.charges.something?
You'd make another API call to retrieve Checkout Session using the List Checkout API endpoint
https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent
Let me know if you're blocked anywhere or if ^that worked ๐
const pi = stripe.paymentIntents.retrieve(chargeRefunded.payment_intent);
console.log('REFUNDED', chargeRefunded);
console.log('PI', pi);
anon-paymentintent-charge
Does this seem okay for retreiving the payment intent object?
assuming you react to a charge.* Event then yes. Easiest is to try in Test mode to confirm
switch (event.type) {
case 'charge.refunded':
const chargeRefunded: any = event.data.object;
const pi = stripe.paymentIntents.retrieve(chargeRefunded.payment_intent);
console.log('REFUNDED', chargeRefunded);
console.log('PI', pi);
// Then define and call a function to handle the event charge.refunded
break;
case 'charge.refund.updated':
const chargeRefundUpdated = event.data.object;
console.log('REFUND UPDATE', chargeRefundUpdated);
// Then define and call a function to handle the event charge.refund.updated
break;
// ... handle other event types
default:
console.log(`Unhandled event type ${event.type}`);
}
Yeah my entire block looks like this
oh maybe I need to await
yes you do
Ah got it!
Now on my ```js
const session = await stripe.checkout.sessions.create({
function, there is a customerDetails that I can add that will be in this PI object?
I see customer
and that's shared between this PI and CheckSessions object?
both would have customer: 'cus_123' which is the id of a real Customer that you can retrieve https://stripe.com/docs/api/customers/retrieve or you can use the Expand feature: https://stripe.com/docs/expand
ok, I need the name of the product to so I can revoke the license.
Is there a place I can add a product name?
ok, I see I can only use customer or customer email
You're going way too fast
Really the first step is to look at the objects, all the involved API resources, etc.
I just need 2 pieces of info
- Email to look up the user;
- Product ID to revoke the license
I need to set these via ```js
const session = await stripe.checkout.sessions.create
They need to comeback with the chargeRefunded object or payment_intent I guess
why?
You create a Checkout Session, so listen to checkout.session.completed if it's about the completion
When you get a Charge Event later, you can look up in your database to map that Charge id to the data you want
No this is about charge.refunded
using webhooks
If there is a refund or you know a customer complains to you and you give them the money back. I need to create an endpoint that recieves the charge.refunded, looks up the user and revoke the license of a specific product
I understand, I just explained what to do
"oh a refund Event for ch_123, let me check my database, oh yeah ch_123 was for pi_123 and cs_test_ABC"
So you're saying I can just set this like so?
or do I have to MAKE a stripe customer?
I have no idea what you mean, those are just pictures
Our Customer object ids look like cus_123
You can't "set a customer id" so no?
I want to help you but you need to try and help yourself first and ask clear questions as there are many other people to help in parallel
Ok...
I need to set some meta data on the checkout session that's retrieved on the charge.refund object...
Can you please give me a percise code example?
you seem to have changed your mind again so it's hard
You were just asking about the exact Customer id cus_123 and customer email. Now you're back to metadata.
You're not listening to me
Every object has its own metadata, we have dozens of API resources. There's no magic metadata pipeline that goes through every object involved in the lifecycle of your Stripe account
How do you not have a productID on the refund object?
That seems so basic
How do I know what product to revoke access to?
You can refund any amount, there's no "line item" mapping on Refund, Charge or PaymentIntent.
There's no metadata I can set on checkout that's not shared with at least payment_intent?
the email is being shared
I just need 1 more piece of info and it's good
I don't see a session ID on the charge.refund object to retrieve the session
what would the email have to do with line items though. I'm sorry you keep being extremely vague.
1/ Get a Refund
2/ Refund -> PaymentIntent via the payment_intent: 'pi_123' property
3/ PaymentIntent -> Checkout Session via the https://stripe.com/docs/api/checkout/sessions/list API
4/ What's inside that Checkout Session via the line_items property
All the objects are related to each other, you need to take a few minutes to look at our API reference and connect the dots
so the payment intent id can be used to look up the checkout session or the checkout session id is on the payment intent object?
Do you see a Checkout Session id on your PaymentIntent object? If not, that will answer the question!
Yeah but you're not helpful
Can I get someone elsse?
You're getting angry and not helping
I'm sorry but I am trying to force you to try stuff. There are 8 other developers asking questions right now. You're just askingquestions without looking and it's important that you tried.
I did give you the exact steps above
I'm looking at everything you're providing.
1/ Get a Refund
2/ Refund -> PaymentIntent via the payment_intent: 'pi_123' property
3/ PaymentIntent -> Checkout Session via the https://stripe.com/docs/api/checkout/sessions/list API
4/ What's inside that Checkout Session via the line_items property
All the objects are related to each other, you need to take a few minutes to look at our API reference and connect the dots
I understand 1 and 2
You are not, instead of looking at https://stripe.com/docs/api/payment_intents which clearly list every property of a PaymentIntent object, you're asking me "is there a Checkout Session id on PaymentIntent". And I am saying: look at the doc.
What is confusing about 1 and 2?
1 is when you get the refund Event which is what you were discussing earlier in the thread switch (event.type) { case 'charge.refunded': const chargeRefunded: any = event.data.object; const pi = stripe.paymentIntents.retrieve(chargeRefunded.payment_intent); console.log('REFUNDED', chargeRefunded); console.log('PI', pi); // Then define and call a function to handle the event charge.refunded break; case 'charge.refund.updated': const chargeRefundUpdated = event.data.object; console.log('REFUND UPDATE', chargeRefundUpdated); // Then define and call a function to handle the event charge.refund.updated break; // ... handle other event types default: console.log(`Unhandled event type ${event.type}`);
you shared this code which was you doing 1 and 2 since you called const chargeRefunded: any = event.data.object; const pi = stripe.paymentIntents.retrieve(chargeRefunded.payment_intent);
Does that part make sense?
@haughty granite did you make progress based on what I explained?