#rc9999999-webhook

1 messages · Page 1 of 1 (latest)

turbid remnant
#

Hey! Which part is failing? This?

await pool.query(
        `UPDATE users SET
        status = $1
        WHERE stripeId = $2`,
        [status, customer]
      );
marble needle
#

Yes, it logs the update but it's zero

#

Result {
command: 'UPDATE',
rowCount: 0,

#

This is how my table looks too, dummy data

turbid remnant
#

Sorry, but I've no idea what this is. Doesn't seem related to Stripe (other than the webhook)?

marble needle
#

Well, I didn't know if i'm not understanding the webhooks properly

turbid remnant
#

invoice.payment_succeeded, right?

marble needle
#

Is there a reason why it wouldn't work if I've only just created the customer in the previous webhook "checkout.session.completed"

turbid remnant
#

You're listening for invoice.payment_succeeded right?

marble needle
#

Yeah

turbid remnant
#

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

marble needle
#

But isn't subscription just the event.data.object?

#

the way I've defined it there

turbid remnant
#

Nope, as I explained event.data.object will be an Invoice object, not the Subscription object that I guess you're expecting

marble needle
#

How do I access the status from the invoice then?

turbid remnant
#

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

marble needle
#

it's the invoice object

#

it was just defined differently

#

I should still be able to get the status

turbid remnant
#

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

marble needle
#

It works for inserts, updates, selects, deletes

#

I don't really understand what you mean

turbid remnant
#

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