#jmak
1 messages · Page 1 of 1 (latest)
I have a CockroachDB that I have set up where I will mark a user as subscribed once i receive the customer.subscription.updated event
however, it doesn't seem to work when the checkout.session.completed and customer.subscription.updated are sent together
but there are no errors
when i resend the customer.subscription.updated event, the DB changes it correctly
I am wondering if this has to do with the time of these events being sent literally 1ms apart
but I am returning status 200 on the first request, just the DB doesn't seem to update
I don't know how the logic of your application works so it's hard for me to help.
If there's a ✅ that means that your app has received the webhook event from Stripe and responded with OK.
Maybe you could send some code that's related to this logic?
this is the code where the subscription is created. in q.CreateUserSubscription I will update the DB
This case comes before my checkout.session.completed
see here
Try using logs to see where your flow stops. I don't see anything out of the ordinary in the code.
ok
standby
It seems theres a null pointer in CustomerDetails
func getUserFromStripeCustomerEmail(session *stripe.CheckoutSession, c *gin.Context, q db.Queriers) (user *models.User, err error) {
var email string
if session.CustomerEmail != "" {
email = session.CustomerEmail
} else { // get it from the customer details
email = session.CustomerDetails.Email
}
user, err = q.GetUserByEmail(email)
if err != nil {
c.AbortWithError(http.StatusBadRequest, err)
return
}
return
}
but the customer details show that its filled in
is customer details not automatically part of the included fields
@solar crest
Please, let me check
Please share the ID of the webhook event evt_xxx
You might need to expand the customer
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
expanding now and testing
Yes, I see customer is just an ID cus_xxx
okay i just tried and it looks like ist still not working
this is with customer expanded
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
SESSION COMPLETE: https://dashboard.stripe.com/events/evt_1Mk3gLB9t5l6pstBCSLQ9lEd
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Where is this code from?
i fixed that one -- it looks like its coming from checkout session completed
im not sure if its a logging thing but that checkout session completed seems to log first..? but the times are off
Please don't rely on the order of the events. Stripe does not guarantee that events are sent in any specific order
even the creation times?
What do you mean?
of these
do the creation times matter
The creation time will be correct, but some events might arrive later than others.
im just so confused what could be going wrong
when i resend the events independently, everything works as expected
Why are you listening to both events?
this is all within one big handler
thats why i have multiple case statements
otherwise i listen to checkout.session.completed because i have other independent items people can buy
Can you use Stripe Customer ID instead?
Okay, so where's the issue now?
You said you fixed one?
the issue is that subscribed is not being set to True
In your database?
yes
it doesn't work when its sent together with checkout session completed
but independently it works
The problem is in how your application handles it. It's a bit hard for me to debug your own code for you. It will help me if you at least point me at the place where it stops working.
it doesn't stop working anywhere it just continues to flow through
does async_payment_succeeded get called at some point?
What's async_payment_succeeded?
the event
for payments
im receiving no bugs in handling any events and am handling all errors and logging
payment_intent.succeeded is called when a payment is successfully processed: https://stripe.com/docs/api/events/types#event_types-payment_intent.succeeded
mhmmm
i'm not tracking that one
but it should be working on the events that I capture no?
You don't need to listen to all events.
are you aware of potential race conditions?
it seems like sometimes it works and sometimes it doesnt
Taking over here, can you summarise the issue? Equally, as my colleague noted if you don't intend to action an event type then don't configure your webhook to listen for it.
we are listening to a few events right now but the only ones that are pertinent are checkout.session.completed and customer.subscription.updated
when these two events are sent in tandem, sometimes the DB doesn't update for customer.subscription.updated
but upon resending the DB properly updates
Well this is something that your integration needs to account for. We don't guarantee event ordering, and the nature of those events and your integration means that they will likely sent at the exact same time.
You need to debug your code and figure out why the checkout.session.completed event is reversing/preventing whatever database logic/call you're making.
hmmm
standby
u may be right
because its taking in pointers and perhaps calling update simultaneously
Yep, seems that way
Definitely a race condition issue, but hard to debug without full context of your code.
Which bug?