#2clutch - checkout subscriptions
1 messages ยท Page 1 of 1 (latest)
That's an event related to a mode-payment session, not a subscription creation
when mode=payment the subscription attribute will be set in the object
you can retrieve that subscription to inspect the items with the specific price etc
how do i test that with the stripe cli?
right now, i am running, stripe trigger checkout.session.completed
i only want to know about the transactions once it's been handled successfully
You can't, just make an API request to create the subscription session directly and run through the flow using a test card
yes, i mean create a checkout session with the API in subscription mode
then follow the url to complete the session
how do i create a checkout session in subscription mode?
also, with the cli, is there a way to trigger checkout.session.completed, with checkout being in subscription mode
because right now, each plan has it own checkout url
wouldn't that make it be in subscription mode already?
Sure but the CLI session test events use a payment mode session, not a subscription
because right now, each plan has it own checkout url
What do you mean by this?
in the stripe dashboard, when creating a subscription, each plan got its own url
happy to send a screenshot if you'd like
Sure, that might help
(APi for Checkout mode is here: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-mode )
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I created a subscription production with 3 plans. really 2 since the free is basically useless.
each plan has a payment link
here's a sample link: https://buy.stripe.com/test_bIY7uLc957dHaKQ289
as you can see, the button at the bottom reads, Subscribe
is this what you mean by checkout with subscription mode on?
OK yes, that will create a subscription mode session
you can complete the checkout session with any of our test cards to generate an event
4242424242424242
The event session object will have the subscription attribute set: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-subscription
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So you can either retrieve the subscription, or retrieve the session itself and use expansion to get the line_items:
https://stripe.com/docs/api/checkout/sessions/retrieve
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
https://stripe.com/docs/api/expanding_objects
expand[]=line_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
is there a way to test this with the stripe cli?
you would have to make test mode API requests but you can "listen" for webhook events via the CLI and then do what synthrider suggested
i'm sorry but i don't understand. do you mind rephrasing?
I meant make the API requests in your integration so that you get responses or webhook events
You can use Stripe CLI to listen to the webhook events and run any code to retrieve more objects from the API
I would recommend that, don't know off hand if the CLI does exactly the test case you want, so easier to just repro it in your integration/code
so when testing, you can do it with live events. you have to manually trigger using the stripe trigger command.
By live events do you mean live mode?
You shouldn't test in live mode
But you can either test with test-mode events by using stripe trigger
Or just test out different scenarios in your code that generate the events you want to test
yes.
i'm in test mode right now
i see the subscription key in one of the urls you provided, but how come i don't see it with the checkout.session.completed i triggered?
it should still be there and be null right?
actually, nevermind, i see the subscription key
would that key contain the price_id?
As in sub_123? You can retrieve the subscription and look at the items that make it up https://stripe.com/docs/api/subscriptions/object#subscription_object-items-data-price
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
well, mine says None right now so idk about its format (i.e. sub_123). but i will checkout the documentation above and let you know if i have any more questions.
Ah I see, did not fully read what you said. Sounds good to me, happy to answer any questions that you run in to
okay, so subscription is the subscription_id, which i can than use to hit the subscription endpoint which will give me more info about the subscription
From the returned object, I can look at:
"data": [
{
"id": "si_KJGI8rGwEcwlVU",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1632825740,
"metadata": {},
"price": {
"id": "15",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1386685951,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {
"charset": "utf-8",
"content": "15"
},
And id will be the price_id?
There are two ids there. the first one appears to be the ID of the a Subscription Item, and price.id would be the ID of the Price object.
Okay so what's the current state of your question?
This thread was archived before I started so I'll need to read up on this
no problem ๐
Yes okay, so the price.id would correspond to the Price IDs you see in the dashboard that are configured for subscriptions.
Does that address your question?
I'm happy we got it resolved ๐