#b33fb0n3_event-plan

1 messages Β· Page 1 of 1 (latest)

ornate starBOT
#

πŸ‘‹ 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/1280902635360358431

πŸ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

distant gust
#

Hello, so you are both trying to understand how to deep link properly and also if there is a way to change what the customer portal says about the trial?

grand hound
#

No, I am looking for a way to have a subscription id (for the deep links) wihtout the customer ever noticed, that he already have a subscription at stripe. It should work in the background

distant gust
#

We have individual settings for finalized invoices, successful payments, failed payments, and trial invoices so you may need to turn multiple/all of those off depending on the exact behavior that you are looking for.

grand hound
grand hound
#

I mean it's ok, if the email is something like "hey your test started" or whatever, but not "your subscription for 0€ started". That would be confusing for the customer

distant gust
#

Unfortunately that is an account-wide setting, so it is for all of the subscriptions on the account.

#

I just reread your description. Is there a reason you are using a 0€ instead of our trial functionality? Trials can be set for an arbitrary amount of time and the wording on the email would likely be clearer.

grand hound
distant gust
#

If you haven't already, I would recommend checking out our API explorer, it can guide you through building a request and can print out the node code for the request
https://docs.stripe.com/workbench/shell
Based on what you have described, it sounds like you would want to set a trial_end that is when you want the subscription to actually start and a cancel_at for when you want the subscription to end.

I couldn't find both for trails
What does "trails" mean here? That is not immediately ringing a bell for me

grand hound
grand hound
#

Why was the plan inside the webhook event was removed?

            case "customer.subscription.created":
                const subscription = event.data.object;
                const metadata = event.data.object.metadata;


                const priceId = subscription.plan.id;
distant gust
#

Whoops I really should have caught on to "trials" = "trails". Busy morning.
Yes, we typically recommend using our trial functionality. You can actually customize what your subscriptions do if they get to the end without a payment method. I forget if the customer portal can change plans on trialing subscriptions, I would reccommend trying it out in test mode to confirm what happens there
https://docs.stripe.com/api/subscriptions/create#create_subscription-trial_settings-end_behavior-missing_payment_method

grand hound
#

Whoops I really should have caught on to "trials" = "trails". Busy morning.
Happens the best πŸ™‚

distant gust
#

Do you have the ID of the event where you are not seeing plan? My initial guess is the API version of your webhook endpoint. That is what mostly determines what fields are available and how objects are rendered.

ornate starBOT
grand hound
#

Sure give me some minutes to find it…

grand hound
sudden citrus
#

It looks like plan is in that webhook Event. Do you have another one that doesn't have plan?

grand hound
#

I am using this version

"stripe": "^16.9.0",
sudden citrus
#

I thought the issue was that you wanted plan to be in the Event. Can you resummarize the issue for me?

grand hound
sudden citrus
#

Ah, so Typescript is looking for an old attribute to verify it's present in the Event. I don't think Typescript supports plan right out of the box, so you would need to update it to expect that value, or ignore the lines that validate the lines in the payload that look for plan

grand hound
#

Or are there others ways to get the price id, when I just have the subscription?

sudden citrus
#

I think that because the Typescript was implemented after we made the switch to Prices (which replaced Plans) it wasn't included. You can see here that, on the Subscription object, which is what you get as the payload for Events like the example you gave, that there is no plan attribute for Typescript to look for: https://github.com/stripe/stripe-node/blob/master/types/Subscriptions.d.ts

You can either add it yourself, or ignore the lines that look for it in your code

grand hound
sudden citrus
#

The Price ID is included in the Plan attribute. It's there in the payload, it's just that Typescript isn't aware of it

grand hound
sudden citrus
#

Wait, let's back up a second. How are you accessing the Plan in your code? Like, the code from your screenshot that's cut off. What's the line that's getting cut off?

grand hound
# sudden citrus Wait, let's back up a second. How are you accessing the Plan in your code? Like,...

The code itself shows that I trying to access the value subscription.plan.id and setting it to the variable priceId.

In pseudocode its:
If the event type is equal to "customer.subscription.created"
Set subscription to the value of the object property within the event.data object
Set metadata to the value of the metadata property within the subscription object (assuming it exists)
Set priceId to the value of the id property within the plan property of the subscription object

So I just try to setting a variable that comes from the subscription.plan.id.
After the code (switch (priceId) { ... }) I switch the priceId. So if the priceId equal to Y (some price id) then do X (in my case setting up stuff the user is allowed to do).

sudden citrus
#

Okay, but the plan isn't in subscription.plan.id, it's in subscription.items.data[0].plan

ornate starBOT
round quiver
#

b33fb0n3_event-plan

#

πŸ‘‹ just to clarify a bit the plan property maps to the Plan object https://docs.stripe.com/api/plans which was deprecated multiple years ago as we replaced it with the Price object https://docs.stripe.com/api/prices/object
They are fully compatible and we recommend that all new code only looks at price and never plan which is why it's been removed from types for multiple years now

grand hound
round quiver
#

It's there for backwards compatibility. We haven't deleted the Plan API (and won't) and lots of code relies on it. But it's discouraged. So really ignore plan and Plan entirely and focus on Price

grand hound
round quiver
#

Is it really this subscription.items.data[0].plan
No that is the Plan object
You want subscription.items.data[0].price

grand hound
#

ahhh there is the price with the price id. Thanks a lot πŸ‘