#ezequiel-webhook-questions

1 messages · Page 1 of 1 (latest)

silent lanternBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

errant arrow
#

👋 What's your exact question @sharp tartan ? It's best to just ask a clear summarized question upfront

sharp tartan
#

Ok Thz for your time.
I'm working with de webhooks backend code. But I feel a little confused.
I want to receive information to save it in my database when a user do a subscription

#

My code works well. I'm testing it in localhost mode helping me with stripe client.

#

I'm testing the "customer.subscription.created" event

errant arrow
#

Hello! Please try and take a step back and summarize your overall question clearly all in one message. This is important especially if you are quite lot. Right now you said your code works and shared a picture with no info.

sharp tartan
#

In my terminal i got this information :

#

Many events

errant arrow
#

Please try and don't press the return key mid sentence. None of this makes sense yet. Try and explain your exact question with detailed information and sentences so that I can make sense of it.

sharp tartan
#

Ok I will make the question again

errant arrow
#

Are you asking why there are many Events and not just one?
If so that's normal, when you create a Subscription a lot of things need to happen in your account (Customer and Subscription creation but also a PaymentIntent, an Invoice, etc.)

sharp tartan
#

Ok I understand

#

This is my terminal

errant arrow
#

You said you understood but then did it all over again. One sentence and one picture, no qustion, no information

sharp tartan
#

Ok I will send you the same in one question

#

I'm working with de webhooks backend code. But I feel a little confused.
I want to receive information to save it in my database when a user do a subscription
My code works well. I'm testing it in localhost mode helping me with stripe client.

I'm testing the "customer.subscription.created" event

In my terminal i got this information :

My question is:

I need the email that the customer use at the subscription moment. the customer id and the subscription id.

I need to save the information that my backend receives to my database

But i can´t do it if i don´t receive the user email.

#

I cannot identify the user in my database if I do not receive the email with which they subscribed.

errant arrow
#

@sharp tartan Whenever something happens in your account an Event is created and sent to your webhook endpoint. It can be customer.created when a Customer is created, it can be payout.failedwhen a Payout fails, etc. Every Event is here to describe something specific, and each Event maps to a specific API Resource in our API that has the information for that specific object. Apayout.createdwould describe a Payout representing money moving from Stripe to your bank account. Acustomer.created` would describe a Customer representing a specific Customer in your Stripe account with all the Customer information.

So when you get an Event, it won;t magically have everything you need. If you get a Refund-related Event, it won't have any information about the Customer.
It's on you, as the developer, to understand what each Event is used for, what it describes and where to find the information you need.

When you get customer.subscription.created you get a Subscription object: https://stripe.com/docs/api/subscriptions/object. It doesn't have information about the Customer's name or email. That lives on a Customer object https://stripe.com/docs/api/customers/object

So you have to write code to look all of this up either in our API or in your own database. When a Subscription is created, you have already created a Customer earlier. You, as the developer, should already know who that Customer is, have their email in your own database, etc.

#

ezequiel-webhook-questions

silent lanternBOT
sharp tartan
#

Ok I think I understood.

#

When a user create a new subscription i receive a new event 'customer.subscription.created'

id: 'sub_1O8S2HIr6Uv0nOknTpljezBw',
customer: 'cus_OwKhPd0xAn5RSm',

At that moment I need to do a fetch to Stripe API to recovery the email ?

storm helm
#

Hi stepping in here

#

I don't understand

#

What are you trying to do?

sharp tartan
#

I'm trying to receive the subscription information using webhook.

#

When one of my users in my platform done a subscription

#

I need to recovery the information from stripe, using webhook.

#

The user id or customer id, the subscription id, the user email

#

I done some test with webhook

#

with the trigger customer.subscription.created

#

I filtered the information ( my terminal )

#

My first question. Why webhooks send me information about 'customer.subscription.deleted' case for example if i'm testing 'customer.subscription.created' ?

#

I can´t not find the customer or user email inside 'customer.subscription.created' object event that i recived

storm helm
#

```When you get customer.subscription.created` you get a Subscription object: https://stripe.com/docs/api/subscriptions/object. It doesn't have information about the Customer's name or email. That lives on a Customer object https://stripe.com/docs/api/customers/object

So you have to write code to look all of this up either in our API or in your own database. When a Subscription is created, you have already created a Customer earlier. You, as the developer, should already know who that Customer is, have their email in your own database, etc.```

#

Not sure what you mean by this. Can you share a sample event id

sharp tartan
#

Yes I have the user information in my database, even the user email.
Ok so... when I receive the 'customer.subscription.created' object
I need the get the customer "id": "cus_OkicoBt56Dq40E", (for example)
and then i need to do a fetch to the Stripe API with that value to recovery the user email ?

storm helm
#

You just said it's in your database...

#

Just look up the email by customer id in your database

sharp tartan
#

I don´t have the customer id in my database at these moment

#

I just have the name, lastname, phone, email

storm helm
#

Then yeah make an api call

#

You should refactor to create customer id up front though

#

That way it's all in your database

sharp tartan
#

When I receive a webhook event with the subscription id and the client id I also need to have the email with which the user subscribed so I can compare it against my database and know which user I have to save this information to.

storm helm
#

Yep

sharp tartan
#

Okok

storm helm
#

So just retrieve the customer id from the subscription object

sharp tartan
#

ok now i understood

#

And about this question "Why webhooks send me information about 'customer.subscription.deleted' case for example if i'm testing 'customer.subscription.created' ? "

storm helm
sharp tartan
#

Is it correct that you receive all these events at the same time? (in my terminal)
console.log s just for test, to see the information. (I filtered it previously)

storm helm
#

Yes

#

You used stripe trigger

#

It generates all the required events

sharp tartan
#

Ok but in a real case (new user subscription)
I will receive just the 'customer.subscription.created' information (object.event)
Is it ok ?

storm helm
#

No multiple should be generated

#

Just try this out yourself

#

In test mode

#

Create a test mode subscriptoin and see the events generated

#

But I don't understand what the issue is. Just configure your webhook endpoint to only listen to the events you need. Don't configure it to be sent all events

sharp tartan
#

I can configure it from the dashboard? what event webhook has to send me

storm helm
#

Please read our docs