#rubberduckies_best-practices
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/1279063103010504716
đ 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.
- rubber_portal-delete, 14 hours ago, 22 messages
- rubberduckies_best-practices, 1 day ago, 65 messages
Can you be more specific. What specifically do you need help with?
hi
sure, i'll try
i'm pretty sure i'm almost there but still have some doubts
basically, on how to build the features.subscription_update.products
i'll give you a scenario
each of this "products" have 2 prices, one for monthly and one for yearly
i want to create a customer portal configuration for each of the products
where a customer can upgrade to the higher products
and be avle to choose yearly or monthly, independently of his current situation
these are the docs
but i can't figure out exactly how to construct my features.subscription_update.products object
So if you look underneath each param, it tells you the data type it needs to be, so features.subscription_update.products needs to be an array of objects. And within each object in that array you'll have prices, which needs to be an array of strings and product which is just a string
What language are you using?
javascript, nodejs
i get that, but i see products.product and products.prices are on the same level, in the docs, shouldn't prices be nested into products?
No they're at the same level
You'll have a product/prices pair for each element in your products array
So like this structure: products: [{prices: [], product:""}]
like this?
{
features: {
subscription_update: {
enabled: true,
products: [{
product: 'prod_Qj40USG6Qhq2XW',
prices: ['price_1PrbsG009aFOms2RBaXuPZ6P', 'price_1PrbsG009aFOms2RBaXuPZ6P']
}]
}
}
}
looks right to me
that would be an array of objects
so this would work:
{
...
features: {
subscription_update: {
enabled: true,
products: [{
product: 'prod_Qj40USG6Qhq2XW',
prices: ['price_1PrbsG009aFOms2RBaXuPZ6P', 'price_1PrbsG009aFOms2RBaXuPZ6P']
}, {
product: 'prod_Qj40USG6Qhq2XW',
prices: ['price_1PrbsG009aFOms2RBaXuPZ6P', 'price_1PrbsG009aFOms2RBaXuPZ6P']
}],
proration_behavior: 'create_prorations'
}
}
...
}
Well you're passing the same product id and price over and over which doesn't make sense
But the structure looks correct
yes i know
Try it to see if it works
give me a moment then, please
should i set "default_allowed_updates" to false?
so this is the object i'm using for trying to create:
{
"business_profile": {
"headline": "Agency Starter"
},
"default_return_url": null,
"features": {
"customer_update": {
"allowed_updates": ["email", "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": false,
"mode": "at_period_end",
"proration_behavior": "none"
},
"subscription_pause": {
"enabled": false
},
"subscription_update": {
"default_allowed_updates": false,
"enabled": true,
"products": [
{
"product": "prod_Qhw89PtPzonlTr",
"prices": ["price_1PqWHY009aFOms2R2Hwhjqie", "price_1PqWGh009aFOms2Rf1MWyFTT"]
},
{
"product": "prod_QhwA5yYbfhXra6",
"prices": ["price_1PqWJm009aFOms2RLV1r7nJL", "price_1PqWIW009aFOms2Rk4V3eoWP"]
}
],
"proration_behavior": "create_prorations"
}
}
}
But i'm getting the error Invalid Array
Can you share the error message and which line specifically it's being thrown on
Please share the line of your code it's being thrown on
this is the whole stacktrace i'm getting
this is the code:
import { Stripe } from 'stripe';
import { paymentPlans } from 'misc/payment-plans';
import object from './object.json';
const { STRIPE_SECRET_KEY } = process.env;
const stripe = new Stripe(STRIPE_SECRET_KEY);
const portalConfig = await stripe.billingPortal.configurations.create(object);
console.log(portalConfig);
process.exit(0);
You can see that's where it's erroring in the error message
Oh missed that
Ok. Try removing just subscription_update from the object
Does it work then?
You need to narrow down where it's happening specifically
Just use debugging to narrow down exactly where this is occurring
i'll try
yup, it worked
so, the problem is somehow here:
"subscription_update": {
"default_allowed_updates": false,
"enabled": true,
"products": [
{
"product": "prod_Qhw89PtPzonlTr",
"prices": ["price_1PqWHY009aFOms2R2Hwhjqie", "price_1PqWGh009aFOms2Rf1MWyFTT"]
},
{
"product": "prod_QhwA5yYbfhXra6",
"prices": ["price_1PqWJm009aFOms2RLV1r7nJL", "price_1PqWIW009aFOms2Rk4V3eoWP"]
}
],
"proration_behavior": "create_prorations"
}
I'll give you a hint
Look at the type for this param: https://docs.stripe.com/api/customer_portal/configurations/create#create_portal_configuration-features-subscription_update-default_allowed_updates
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, before you sent me that hint, i tried changing false to an empty array and i got "parameter missing"
Yeah you need to pass something
the possible enums are price, quantity and promotion code
Yes, and what are you wanting customers to update?
i don't want the user to change any of that, only to "upgrade" to a different product
so, should i just use price?
with: "default_allowed_updates": ["price"], it worked
but i'm not sure exactly what that means in terms of the final result
i'll use this configuration for now
and when i start creating billing portal sessions, i'll see if it's what i want. If not, i'll come back for a different chat