#anon-paymentintent-charge

1 messages ยท Page 1 of 1 (latest)

buoyant hollowBOT
queen heath
#

@haughty granite let's chat here

haughty granite
#

Yo!

queen heath
#

Can you remove the other message from the main channel? It helps us keep it clean ๐Ÿ™‚

haughty granite
#

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.

queen heath
#

Oh I meant removing the second message where you shared your code ๐Ÿ˜…
not the original (first) one

haughty granite
#

oh

#

ok the code was very simple

queen heath
#

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

haughty granite
#

Charge.refunded. or charge.refund.updated

queen heath
#

No, I mean how exactly are you testing your code?

haughty granite
#

I'm using something similar to ngrok

queen heath
#

How are you invoking the code on your webhook endpoint?

#

and what exactly is making a request to /refund ?

haughty granite
#

This refund payment button

#

via the Stripe Dashboard

queen heath
#

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

haughty granite
#

yeah, I read about this on Stack Overflow

#

That's why I moved the payments route above this bodyParser.json()).

queen heath
#

have you tried console.log(req.body) yet to confirm if its still being parsed to JSON or not?

haughty granite
#

yeah, it's weird, getting nothing.

#

If found one more middleware I'm moving the route above.

#

ahhh

queen heath
#

So when you print out req.body its just null?

haughty granite
#

my ngrok is down

queen heath
#

ah

haughty granite
#

yeah my thing is down

#

Let me reboot it

queen heath
#

๐Ÿ‘

haughty granite
#

ok it's working now, let me do it one more time with a message so I know what I'm looking at.

queen heath
#

๐Ÿ‘

haughty granite
#

So this looks good

queen heath
#

Still getting the error or no?

haughty granite
#

Yeah I guess I'm confused about what key to use.

queen heath
#

Use the one from the dashboard

haughty granite
#

this one right?

queen heath
#

yup

haughty granite
#

ok

queen heath
#

each endpoint has a diff secret

haughty granite
#

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?

queen heath
#

NP! ๐Ÿ™‚ Happy to help
Glad that you're unblocked

haughty granite
#

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.

queen heath
#

So Checkout Session object and Charge Refund objects are not directly related.

Checkout Session object has a PaymentIntent, the PaymentIntent creates a charge underneath.

haughty granite
#

ok, so dang

queen heath
haughty granite
#

ok so I can check this customer object in ```js
await stripe.checkout.sessions.create()

queen heath
haughty granite
#

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

queen heath
haughty granite
#

yep I see the payment intent

queen heath
#

That should get you your local DB user ID and the line items

haughty granite
#

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

queen heath
#

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

haughty granite
#

url: '/v1/charges/ch_3NNdL6CrnLkr8CZ70N9CrpXT/refunds'

#

I see this

#
   const chargeRefunded = event.data.object;
      const payment = await stripe.charges.retrieve(chargeRefunded.payment_intent);
queen heath
#

You don't see PaymentIntent ID when you console log event.data.object ?

haughty granite
#

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?

queen heath
haughty granite
#

ahhh I'm dumb

#

I see

queen heath
#

Let me know if you're blocked anywhere or if ^that worked ๐Ÿ™‚

buoyant hollowBOT
haughty granite
#
      const pi = stripe.paymentIntents.retrieve(chargeRefunded.payment_intent);
      console.log('REFUNDED', chargeRefunded);
      console.log('PI', pi);
steel fable
#

anon-paymentintent-charge

haughty granite
#

Does this seem okay for retreiving the payment intent object?

steel fable
#

assuming you react to a charge.* Event then yes. Easiest is to try in Test mode to confirm

haughty granite
#
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

steel fable
#

yes you do

haughty granite
#

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?

steel fable
haughty granite
#

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

steel fable
#

You're going way too fast

#

Really the first step is to look at the objects, all the involved API resources, etc.

haughty granite
#

I just need 2 pieces of info

#
  1. Email to look up the user;
#
  1. 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

steel fable
#

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

haughty granite
#

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

steel fable
#

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"

haughty granite
#

So you're saying I can just set this like so?

#

or do I have to MAKE a stripe customer?

steel fable
#

I have no idea what you mean, those are just pictures

#

Our Customer object ids look like cus_123

haughty granite
#

Dude, this Customer ID.

#

I set it on the checkout session, right>?

steel fable
#

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

haughty granite
#

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?

steel fable
#

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.

haughty granite
#

You're not listening to me

steel fable
#

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

haughty granite
#

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?

steel fable
#

You can refund any amount, there's no "line item" mapping on Refund, Charge or PaymentIntent.

haughty granite
#

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

steel fable
#

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

haughty granite
#

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?

steel fable
#

Do you see a Checkout Session id on your PaymentIntent object? If not, that will answer the question!

haughty granite
#

Yeah but you're not helpful

#

Can I get someone elsse?

#

You're getting angry and not helping

steel fable
#

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

haughty granite
#

I'm looking at everything you're providing.

steel fable
#

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

haughty granite
#

I understand 1 and 2

steel fable
#

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?