#neha_api

1 messages ยท Page 1 of 1 (latest)

spiral snowBOT
#

๐Ÿ‘‹ 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/1398289035432296559

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

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

lost lagoon
#

maybe what i actually want is a combination

#

a customer portal FLOW for updating subscription... seems like i can pass a config here (so after i create the config via the API, it will have a unique ID that i reference after?) seems a bit weird.

and the regular customer portal for everything else, using the default config defined via the Dashboard?

pulsar nest
#

hey there!

#

yes, you could create multiple portal configurations (via the API)

#

You can use one to offer invoice review, payment method management, cancelation etc, whatever normal features you want all the time

#

then you can also use flows or a second configuration to offer subscription updates (upgrade/downgrade)

lost lagoon
#

okay but the API portal configuration does not have a way to include the retention coupon

#

can you please confirm?

pulsar nest
#

What do you mean?

lost lagoon
#

this feature is lacking in the API

#

as far as i can tell

pulsar nest
#

Where do you find that in your Dashboard?

lost lagoon
#

no this isn't on update

#

this is on cancel

pulsar nest
#

Ah gotcha

lost lagoon
#

ok so it's defined at the flow level

#

not the customer portal config level

#

maybe we can take a step back
for my use case -

  1. rate-limited for updating subscription
  2. regular customer portal for everything else

do you think it makes sense to use a flow + custom config for #1?

pulsar nest
#

Yes, i think you'll have to because the portal otherwise doesn't enforce a rate limit of any kind on the updates

#

i think you can use the dashboard config for everything except update (including the retention coupons for cancel) and just use flows for upgrade/downgrade

lost lagoon
#

okay let me give it a go

#

please don't close this thread!

#

i'm just working in the bg

pulsar nest
#

Sure keep me posted ๐Ÿ™‚

lost lagoon
#

i was on a really old version of stripe - 10.x.x

#

and it didn't have this customer flow feature

#

is 16.12.x the latest stable?

#

not sure what acacia and basil mean

pulsar nest
#

10.x sounds like ... stripe-node?

#

Which SDK are you using?

lost lagoon
#

yeah

#

stripe-node

#

i was on this.stripe = new Stripe(SK_KEY, { apiVersion: "2022-08-01" });

pulsar nest
#

So if you update just to the latest version of 13 you should have this in your SDK

lost lagoon
#

thank you

#

one sec

spiral snowBOT
lost lagoon
#

is previous_attributes not available anymore

#

on this event: "customer.subscription.updated"

#

can't find anything in the changelog

pulsar nest
#

It is -- in what context are you looking for this?

lost lagoon
#

case "customer.subscription.updated": {
const { object: data, previous_attributes: prevData } = event.data;
const oldPriceId = prevData?.?.items?.data[0]?.price.id;

#

that's my old code but it's complaining

#
  namespace Stripe {
    namespace Event {
      interface Data {
        /**
         * Object containing the API resource relevant to the event. For example, an `invoice.created` event will have a full [invoice object](https://stripe.com/docs/api#invoice_object) as the value of the object key.
         */
        object: Data.Object;

        /**
         * Object containing the names of the updated attributes and their values prior to the event (only included in events of type `*.updated`). If an array attribute has any updated elements, this object contains the entire array. In Stripe API versions 2017-04-06 or earlier, an updated array attribute in this object includes only the updated array elements.
         */
        previous_attributes?: Data.PreviousAttributes;
      }

      namespace Data {
        interface Object {}

        interface PreviousAttributes {}
      }```
#

because in the typings, PreviousAttributes are empty

pulsar nest
#

Can you share a specific example event ID you're looking at?

lost lagoon
#

this is just my webhook so it's the typings

#

not an actual event

#

it's strange the annotation is

#

Object containing the names of the updated attributes and their values prior to the event (only included in events of type *.updated). If an array attribute has any updated elements, this object contains the entire array. In Stripe API versions 2017-04-06 or earlier, an updated array attribute in this object includes only the updated array elements.

#

but the type is empty obj

pulsar nest
#

It probably only knows the top level structure, not that details of the specific event type

lost lagoon
#

oh ok

#

i was using this

#

before

#

but it said itw asn't needed after 13.11.x

#

hmm

#

i'll try 14.x.

pulsar nest
#

oh, thats a third party type library, i have no idea what it includes or doesnt

lost lagoon
#

yeah it was adding better types

#

for stripe

#

needed back in 2022

#

but they say not anymore

#

yeah fixed in 14.13.0

#

ok trying that

#

okay finally at the point where i can test

#

okay amazing

#

i think this is what i want

#

so because i can't see my portal configs via the stripe website, am i just supposed to note the IDs somewhere

neon pilot
#

Great to hear!

lost lagoon
#

okay i have one follow-up question

#

i want to allocate credits to a user alongside their subscription cycle
my plan is -
monthly subscriptions, create one entry in my table (valid_period_start = now, valid_period_end = 1 month)
yearly subscriptions, create 12 entries (same idea but over 12 months)

right now i'm using the "invoice.paid" webhook to do this but i don't love it because if i change a user's subscription via the Stripe Site, it doesn't get triggered. on the other hand, "customer.subscription.updated" gets called so often, it feels dicey

#

credits aren't user facing, they're just on my end to monitor abuse

neon pilot
#

If there is not a payment, you do not get invoice.paid. You only get that event if there has been a payment.

You can just track these via metadata, https://docs.stripe.com/metadata and map that on your end to keep track of these since it's internal only.

lost lagoon
#

sorry i'm not sure i follow the metadata solution

neon pilot
#

When a customer update's the subscription, you can the pass a metadata to the subscription and then use that data to track the credits on your end

#

Is that clearer?

lost lagoon
#

what exactly are you imagining for the metadata

neon pilot
#

You pass an ID to track the credits you're referring to

lost lagoon
#

sorry i think i wasn't clear enough

neon pilot
#

Can you clarify please?

lost lagoon
#

so the subscription starts 1/1
i want to add 1000 credits (i have my own table for this) - valid from 1/1 - 2/1
renews 2/1
i want to add 1000 more credits - valid from 2/1 to 3/1
and so on

i'm currently using "invoice.paid" to allocate

but the issue with this event is, when i update a user one-off via the stripe site, that webhook doesn't hit
so i have to manually allocate the credits to the user as part of this same manual flow

#

so i'm wondering if there's a more reliable event

#

i'm scared to use customer.subscription.updated bc it can happen due to almost anything

neon pilot
#

I see, since you're making that request one-off, would not you be able to track that when you make this request?

Since you're already making these requests one-off, it makes more sense to just track that at this time.

lost lagoon
#

you mean when i go into the UI and update their subscription?

#

the Stripe UI

#

is there a particular webhook for that?

neon pilot
#

Yes, when you update that subscription

You then will on your database track these credits. This is where I'm saying you can use the metadata. You make a request to update the subscription to add the 1000 credits.

lost lagoon
#

so you're saying, for example
update the subscription via the stripe UI - manually
add some metadata to the subscription - manually - like "needs_credits: true"
and then in the customer.subscription.updated hook, look for that metadata and allocate (if and only if) ?

#

seems kinda hacky so just trying to understand

neon pilot
#

Option 1:
pdate the subscription via the stripe UI - manually
You then just track the credits on your own database as you're manually updating it

Option 2:
Same flow + add some metadata to the subscription - manually - like "needs_credits: true"

lost lagoon
#

ok got it

#

so option 1 is what i'm doing already

neon pilot
#

yeah, there is not much more to that.

lost lagoon
#

so usually it happens if the user selects the wrong free trial

#

now that i am using flows for updating subscriptions

#

presumably there's a way to detect the user is still in their trial, switch them free of charge, and trigger an invoice?

neon pilot
#

Sure you can. I think you should test this flow entirely on your end and decide that would work best.

#

If you have questions from the specific subscriptions we can further help

#

This can get complex and trying this out in Sandbox is going to give you the best way to help decide what works best for your specific flow.

lost lagoon
#
          enabled: true,
          default_allowed_updates: ["price"],
          products: ...
          proration_behavior: "none",
        },
      },```
#

But when it's "none"

#

There's no invoice.

#

Or am I missing something

#

This is the customer portal config ^

#

Okay i think I can figure this out

#

Thanks for your help