#2clutch - checkout subscriptions

1 messages ยท Page 1 of 1 (latest)

ocean mantle
#

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

normal token
#

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

ocean mantle
#

You can't, just make an API request to create the subscription session directly and run through the flow using a test card

normal token
#

i'm using Checkout though

#

so Stripe is handling everything.

ocean mantle
#

yes, i mean create a checkout session with the API in subscription mode

#

then follow the url to complete the session

normal token
#

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?

ocean mantle
#

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?

normal token
#

in the stripe dashboard, when creating a subscription, each plan got its own url

#

happy to send a screenshot if you'd like

ocean mantle
#

Sure, that might help

normal token
#

I created a subscription production with 3 plans. really 2 since the free is basically useless.

#

each plan has a payment link

#

as you can see, the button at the bottom reads, Subscribe

#

is this what you mean by checkout with subscription mode on?

ocean mantle
#

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

#

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

normal token
#

is there a way to test this with the stripe cli?

spark tree
#

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

normal token
#

i'm sorry but i don't understand. do you mind rephrasing?

spark tree
#

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

normal token
#

so when testing, you can do it with live events. you have to manually trigger using the stripe trigger command.

willow shuttle
#

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

normal token
#

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?

gritty pagoda
normal token
#

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.

gritty pagoda
#

Ah I see, did not fully read what you said. Sounds good to me, happy to answer any questions that you run in to

normal token
#

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?

severe goblet
#

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.

tranquil arrow
#

Okay so what's the current state of your question?

normal token
#

price.id would the same as one of the API ID correct?

tranquil arrow
#

This thread was archived before I started so I'll need to read up on this

normal token
#

no problem ๐Ÿ™‚

tranquil arrow
#

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?

normal token
#

yes sir. that clarifies everything for me.

#

thank you so much!

tranquil arrow
#

I'm happy we got it resolved ๐Ÿ™‚