#rc9999999-webhook
1 messages · Page 1 of 1 (latest)
Hey! Which part is failing? This?
await pool.query(
`UPDATE users SET
status = $1
WHERE stripeId = $2`,
[status, customer]
);
Yes, it logs the update but it's zero
Result {
command: 'UPDATE',
rowCount: 0,
This is how my table looks too, dummy data
Sorry, but I've no idea what this is. Doesn't seem related to Stripe (other than the webhook)?
Well, I didn't know if i'm not understanding the webhooks properly
invoice.payment_succeeded, right?
Is there a reason why it wouldn't work if I've only just created the customer in the previous webhook "checkout.session.completed"
You're listening for invoice.payment_succeeded right?
Yeah
That event will contain an Invoice object: https://stripe.com/docs/api/invoices/object
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
In that object the subscription field is just an ID
So when you're trying to do:
subscription = event.data.object;
status = subscription.status;
This won't work
Nope, as I explained event.data.object will be an Invoice object, not the Subscription object that I guess you're expecting
How do I access the status from the invoice then?
But both status and customer fields exist on the Invoice object so they should be defined, and don't think that's your issue here
Can you throw a console.log in to ensure your subscription variable is what you think it is
it's the invoice object
it was just defined differently
I should still be able to get the status
Yep, true. So that's not your issue here and I don't really know what pool.query does. I guess some kind of DB write
Anyway, you should look up the actual Subscription object from the API otherwise your status field will be wrong
It works for inserts, updates, selects, deletes
I don't really understand what you mean
subscription.status in your code there isn't actually the status field from the Subscription. It's the status field from the Invoice
So it's not going to reflect the actual status of the subscription in your database
So what you need to do is make an API call to Stripe to retrieve the actual Subscription using the ID from the Invoice object