#xzel_customerportal-upgrade
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/1263614950312513647
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
xzel_customerportal-upgrade
The CustomerPortal (also called BillingPortal) is definitely what you should use. What it allows you to do is render the details about the Customer's current Subscription(s) and you can configure it it to support cancellation or upgrades.
It would definitely not create a brand new Subscription. It expects a Customer id mostly and then we do things for you
Does that make sense @stuck mango ?
Sorry went afk for a second
That is what I initally was trying to do, maybe I don't have my billing configuration set up correctly?
Like I said, we currently have them modeled as two products
It seems like using the billing portal flow it wants it wants a new subscrption
export const billingConfiguration: Stripe.BillingPortal.ConfigurationCreateParams = {
business_profile: {
privacy_policy_url: 'https://nectarblocks.com/privacy-policy/',
terms_of_service_url: 'https://nectarblocks.com/terms-and-conditions/'
},
features: {
customer_update: {
allowed_updates: [ 'address', 'tax_id' ],
enabled: true
},
invoice_history: {
enabled: true
},
payment_method_update: {
enabled: true
},
subscription_cancel: {
cancellation_reason: {
enabled: true,
options: [
'too_expensive',
'missing_features',
'switched_service',
'unused',
'other'
]
},
enabled: true,
mode: 'at_period_end',
proration_behavior: 'none'
},
subscription_update: {
default_allowed_updates: [ 'promotion_code' ], // disabled when empty
enabled: true,
proration_behavior: 'always_invoice',
products: [
{
product: STRIPE_PRODUCT_ID,
prices: [ STRIPE_PRICE_ID ]
},
{
product: STRIPE_AGENCY_PRODUCT_ID,
prices: [ STRIPE_AGENCY_PRICE_ID ]
},
]
}
}
}
const session = await stripeClient.billingPortal.sessions.create({
configuration: STRIPE_BILLING_CONFIGURATION,
customer: user.stripeCustomerId,
return_url: `${LOCAL_HOSTNAME}/licenses`,
flow_data: {
type: 'subscription_update',
subscription_update: {
subscription: key.subscriptionId
}
}
});
Iirc I'm getting an error about there only being one price available
The other option I see would be using the subscription_update_confirm and I could create a subscrption to the second product/priceID pair?
It seems like using the billing portal flow it wants it wants a new subscrption
it does not though, you pass a specific Subscription id in that Session (though you don't have to)
{"message":"The subscription cannot be updated because there is no price in the portal configuration available to change to and the quantity cannot be changed.","request_log_url":"https://dashboard.stripe.com/test/logs/req_yYzFUhBysz4Cwg?t=1721341229","type":"invalid_request_error"
That is the response I'm currently getting while using the subscription_update flow
Are you sure you have the right Product and Price ids in that Configuration?
Let me double check
{
"business_profile": {
"privacy_policy_url": "https://nectarblocks.com/privacy-policy/",
"terms_of_service_url": "https://nectarblocks.com/terms-and-conditions/"
},
"features": {
"customer_update": {
"allowed_updates": [
"address",
"tax_id"
],
"enabled": true
},
"invoice_history": {
"enabled": true
},
"payment_method_update": {
"enabled": true
},
"subscription_cancel": {
"cancellation_reason": {
"enabled": true,
"options": [
"too_expensive",
"missing_features",
"switched_service",
"unused",
"other"
]
},
"enabled": true,
"mode": "at_period_end",
"proration_behavior": "none"
},
"subscription_update": {
"default_allowed_updates": [
"promotion_code"
],
"enabled": true,
"proration_behavior": "always_invoice",
"products": [
{
"product": "prod_QKTB74wiR9Hxiz",
"prices": [
"price_1PToEzI9XpkbIXSJ5xzabioU"
]
},
{
"product": "prod_QKUSbYJQUHX6hH",
"prices": [
"price_1PTpTsI9XpkbIXSJ27eJ9kML"
]
}
]
}
}
}
so that is the config that I'm updating on right now
is the error log
Okay what exact Product and Price does your Subscription have?
The one I'm trying to upgrade is the first one to the second one.
(looking)
Thanks!
still debugging. Sorry this product is so hard to debug, especially when using such advanced configuration features ๐ฆ
No worries. My guess on the documentation and trying to do this manually at the same time
is that I need to create a whole new subscription, and then use the other flow, subscription_update_confirm
I'm trying to do this via stripeClient.subscriptions.update at the same time as a back up right now
no that wouldn't make any sense honestly
ah
ah well the subscrptions.update want sa new sub_item_id instead of the productID
I agree that wouldn't make any sense either lol
yeah you're mixing all the concepts together. A SubscriptionItem is completely separate
I mean you're welcome to try in parallel. But it has to be something about your Configuration that is incorrect. I just don't know what yet and I'm trying to narrow it down
Ah okay I'm very happy to be the one confusing stuff lol
Can you try to remove flow_data for now to see what happens?
So I do have a separate call without it, just opening up the portal
can you show me what you see when you try that?
const session = await stripeClient.billingPortal.sessions.create({
configuration: STRIPE_BILLING_CONFIGURATION,
customer: user.stripeCustomerId,
return_url: `${LOCAL_HOSTNAME}/licenses`
});
o wow it looks like my manual attempt might have worked
I just removed the id it was asking for
hmm it combined them though haha
(really what you're doing is absolutely not what you want :p)
Can you go back to whatever you have so I can keep debugging? You just changed the Subscription unfortunately
Apologies yeah let me see if I can remove that, did the number of the sub itself change as well?
No doesn't look liek it did
no but you changed the Subscription so I would need it back to exactly what it was before
Will refunding the invoice work?
Eh sorry I should've been using a diffeent subscription to test with myself
Okay I removed that product from the subscrption
can you try again to confirm that you get the same error?
So still getting the incorrect info on the general portal, can't change subs
okay
1 sec, need to revert the Db change and i'll be able to retest the flow API
oh boy ๐
it's okay let's pause I'll just try to reproduce on my own account at this point, might be safer!
this looks like purely internal HTTP header.
Its the fastify log dumping the error
Possibly I need to include price in my config?
That me to believe just switching between priceIDs which I did not want to include, since I'm looking to allow upgrades between ProductIDs + PriceIDs
Sorry I don't really follow your train of thoughts. You were already including the Product and Price ids right?
Sorry I'm talking about including default_allowed_updates: [ 'promotion_code', 'price' ]
oh lol duh
yeah nice catch it's exactly the issue
FYI I spent 10 minutes because I passed enabled: false myself and a colleague had to catch my mistake
I don't get why our API don't explicitly error if you pass incompatible params
I mean its a great API but being perfect is tough
yeah okay my colleague said "it's to make toggling on and off much easier"
which is fair, but such a damn easy way to lose an hour ๐
Yep that was it lol
I am so sorry for not catching that, I would love that parameter not to be price lol
Is there a way to block directions so that people can only go up and not down?
I might be asking for too much at this point haha
I am so sorry for not catching that
that's not on you. It's my job to know those APIs inside out and I completely missed it ๐
Is there a way to block directions so that people can only go up and not down?
no we don't support this today unfortunately
Ah so I'd probably have to handroll that logic anyways
yes
lol
speaking of wasting time
This will be good short term, I'd why anyone would want to do that at the moment, so will be a future thing
I'll be replacing the billing panel in a few months I'm sure
but could you give me the right strategy for doing the upgrade with only the API
https://docs.stripe.com/billing/subscriptions/upgrade-downgrade is the best doc for this and walks you through all the detail
What you did earlier was update the Subscription to add an extra Price instead of replace the existing one which the doc covers
Ah so is the '{{SUB_ITEM_ID}}' the value I need to pull out of the previous subscription?
yes
I mean the way you frame it is worrying again. It's the same Subscription id sub_123. And same SubscriptionItem id si_123
Sorry previous is incorrect, since im updating it
I'm pretty sure I've got it though
I'll have to clean up my webhooks to make all this work correctly since we hadn't had upgrades but all should be good
Other thing that I find weird and this is somewhat of a question, we started using the Stripe Elements, but that seems to create an inactive subscription everytime someone is about to checkout, so I had to move our key creation logic etc to invoice paid etc. With the embedded form it doesn't seem to do that until they hit pay. Does that make sense / is true?
yes it makes sense and is true though there are way around it. You can create the Subscription later in the flow, once the customer is ready to pay, see https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=subscription which is a different integration path
Ty
yeah we canned that for the short term b/c we had a lot of issues with getting tax etc
Don't have the time right now to implement yet another API for taxes
๐