#neha_api
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/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.
- neha_webhooks, 1 day ago, 23 messages
- neha_best-practices, 1 day ago, 63 messages
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?
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)
okay but the API portal configuration does not have a way to include the retention coupon
can you please confirm?
What do you mean?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
this feature is lacking in the API
as far as i can tell
Where do you find that in your Dashboard?
Using the subscription_update_confirm flow you can optionally apply a coupon to the update for your customer to confirm: https://docs.stripe.com/customer-management/portal-deep-links#create-a-flow
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
no this isn't on update
this is on cancel
Ah gotcha
Ok yes i see that, you can offer this in the cancel flow too: https://docs.stripe.com/api/customer_portal/sessions/create#create_portal_session-flow_data-subscription_cancel-retention
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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 -
- rate-limited for updating subscription
- regular customer portal for everything else
do you think it makes sense to use a flow + custom config for #1?
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
okay let me give it a go
please don't close this thread!
i'm just working in the bg
Sure keep me posted ๐
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
For context on that, please see here: https://stripe.com/blog/introducing-stripes-new-api-release-process
and how this works with our SDKs: https://docs.stripe.com/sdks/versioning
But, you don't need to adopt the latest version to get flows if you don't want, they've been supported for some time ๐
10.x sounds like ... stripe-node?
Which SDK are you using?
yeah
stripe-node
i was on this.stripe = new Stripe(SK_KEY, { apiVersion: "2022-08-01" });
Looks like support for flow_data was added back in 13.x: https://github.com/stripe/stripe-node/blob/master/CHANGELOG.md#1330---2023-08-24
So if you update just to the latest version of 13 you should have this in your SDK
is previous_attributes not available anymore
on this event: "customer.subscription.updated"
can't find anything in the changelog
It is -- in what context are you looking for this?
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
Can you share a specific example event ID you're looking at?
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
It probably only knows the top level structure, not that details of the specific event type
oh ok
i was using this
before
but it said itw asn't needed after 13.11.x
hmm
i'll try 14.x.
oh, thats a third party type library, i have no idea what it includes or doesnt
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
Great to hear!
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
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.
sorry i'm not sure i follow the metadata solution
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?
what exactly are you imagining for the metadata
You pass an ID to track the credits you're referring to
sorry i think i wasn't clear enough
Can you clarify please?
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
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.
you mean when i go into the UI and update their subscription?
the Stripe UI
is there a particular webhook for that?
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.
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
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"
yeah, there is not much more to that.
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?
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.