#sparklefaces_webhooks
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1437928635872055446
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
To add context I am just trying to test out my webhook code. ie,
if event.type == "checkout.session.completed":
checkout_session_id = event.data.object.id # Grab Checkout id
checkout_session = stripe.checkout.Session.retrieve(checkout_session_id, stripe_account=seller_id)
if checkout_session.payment_status != "unpaid":
# Handle order fulfillment
Hi there,
sorry for the waiting time. It's been a bit busy.
Let me take a quick look
Just for me to fully understand, you want to trigger a webhook event checkout.session.completed through the Stripe CLI?
Yes, but I want it to list my specific checkout session id (cs_test_...). This is because I associate an order in my database with this id, so that when the webhook fires, I can then proceed to retrieve that order and perform order fulfillment steps
My understanding is that the event data returned by the webhook should be the checkout session object. or did I misunderstand the docs?
So when I look at the fixture for checkout.session.completed in the github, I'm a little confused why it doesn't contain any checkout object data and instead has stuff about product data
I'm listening for the webhook locally with this:
stripe listen --forward-to http://localhost:5000/stripe/webhooks
If that helps!
The checkout.session.completed webhook event should only contain the checkout session object
Yes, that's my understanding too. So why does the checkout.session.completed.json in the github for fixtures have this:
"fixtures": [
{
"name": "product",
"path": "/v1/products",
"method": "post",
"params": {
"name": "myproduct",
"description": "(created by Stripe CLI)"
}
},
{
"name": "price",
"path": "/v1/prices",
"method": "post",
"params": {
"product": "${product:id}",
"unit_amount": "1500",
"currency": "usd"
}
},
{
"name": "checkout_session",
"path": "/v1/checkout/sessions",
"method": "post",
"params": {
"success_url": "https://httpbin.org/post",
"cancel_url": "https://httpbin.org/post",
"mode": "payment",
"line_items": [
{
"price": "${price:id}",
"quantity": 2
}
],
"payment_intent_data": {
"shipping": {
"name": "Jenny Rosen",
"address": {
"line1": "510 Townsend St",
"postal_code": "94103",
"city": "San Francisco",
"state": "CA",
"country": "US"
}
}
}
}
What is event.data.object.id here?
I guess that's where I'm confused. I was hoping to send this webhook via the stripe cli fixtures
So that in my code, I can grab the checkout session id like so:
if event.type == "checkout.session.completed":
checkout_session_id = event.data.object.id # Checkout id
Could you help me craft the correct fixture for checkout.session.completed?
so that I can test this event locally?
We describe the returned object in our API reference here: https://docs.stripe.com/api/events/types
You can see for checkout.session.completed, it returns a checkout session https://docs.stripe.com/api/events/types#event_types-checkout.session.completed
Gotcha, thanks for the links.
How would I send this webhook event to my localhost for local testing?
You would use the CLI https://docs.stripe.com/cli/trigger
a basic trigger would be stripe trigger checkout.session.completed
How do I get the basic trigger "stripe trigger checkout.session.completed" to return my specific checkout session id: "cs_test_b1cFJyTPlj55eeEjki11sfjIgT4mt0PDSb1zjsVrahVGrTU5JXphICMdnM"?
So that event.data.object.id == "cs_test_b1cFJyTPlj55eeEjki11sfjIgT4mt0PDSb1zjsVrahVGrTU5JXphICMdnM"?
You can customize the parameter of the object by using the --override parameter https://docs.stripe.com/cli/trigger#trigger-override
We have that also explained in our docs here: https://docs.stripe.com/stripe-cli/triggers#customize-events
Thanks for the link. I have tried the override like this:
stripe trigger checkout.session.completed --override event:"id"=cs_test_b1cFJyTPlj55eeEjki11sfjIgT4mt0PDSb1zjsVrahVGrTU5JXphICMdnM
But I think it's wrong. This is the result:
Setting up fixture for: product
Running fixture for: product
Setting up fixture for: price
Running fixture for: price
Setting up fixture for: checkout_session
Running fixture for: checkout_session
Setting up fixture for: payment_page
Running fixture for: payment_page
Setting up fixture for: payment_method
Running fixture for: payment_method
Setting up fixture for: payment_page_confirm
Running fixture for: payment_page_confirm
Trigger succeeded! Check dashboard for event details.
And the event.type == "charge.updated" and the overridden id is not what I specified.
Could you help me build the correct command?
Haven't done this in a while but it should be something like stripe trigger checkout.session.completed --override checkout_session:id=cs_test_123
Thank you. But it looks like I'm unable to change the id?
Trigger failed: Request failed, status=400, body={
"error": {
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"message": "Received unknown parameter: id",
"param": "id",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_GQCF0cvkv6o18d?t=1762902880",
"type": "invalid_request_error"
}
}
Is there another way to specify my checkout session id for the checkout.session.completed webhook event?
But it looks like I'm unable to change the id?
Yes you are right. I just tested it on my end too. I can change other values, but not the id.
Is there another way to specify my checkout session id for the checkout.session.completed webhook event?
I don't think there is. But if the event already exist, you can try to resend the existing event to your endpoint using stripe events resend <event_id> https://docs.stripe.com/cli/events/resend
I went through the checkout process, and on my platform's stripe account I saw the application_fee.created event. How can I grab the "checkout.session.completed" event from the standard connected account? I think the actual checkout event lives there.
The associated connected account is an account I generated via Blueprints in the Developers panel.
Ah ok, I found the event: evt_1SSR5X87EYReyaUxNvSxCOf6
It is associated with the test connected account I mentioned before.
I tried to resend the event via the stripe cli:
stripe events resend evt_1SSR5X87EYReyaUxNvSxCOf6 --stripe-account acct_1SRQuI87EYReyaUx
But this resulted in this error:
{
"error": {
"message": "You are not permitted to configure webhook endpoints on a connected account. Did you mean to create a Connect webhook on your account instead?",
"type": "invalid_request_error"
}
}
Am I missing something in my command?
I tried to resend without the --stripe-account, but got this error:
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such notification: 'evt_1SSR5X87EYReyaUxNvSxCOf6'",
"param": "id",
"type": "invalid_request_error"
}
}
Which I think makes sense since this event only happened on the test connected account.
Using the --stripe-account flag means you try to send the event AS the connected account. If you try --account=<account_id> you resend an event that has been send to a connect webhook endpoint on a platform.
So if you already have a connect webhook endpoint on your platform, you would need to use the --account flag instead. If you don't have that endpoint, I recommend creating that first and retry.
Thank you so much! That worked perfectly.
You are very welcome