#rubberduckies_best-practices

1 messages ¡ Page 1 of 1 (latest)

limber tokenBOT
#

👋 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.

thin solar
#

Can you be more specific. What specifically do you need help with?

visual flare
#

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

thin solar
#

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?

visual flare
#

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?

thin solar
#

No they're at the same level

#

You'll have a product/prices pair for each element in your products array

visual flare
#

oh, i think i see it

#

give me one moment please

thin solar
#

So like this structure: products: [{prices: [], product:""}]

visual flare
#

like this?

{
  features: {
    subscription_update: {
      enabled: true,
      products: [{
        product: 'prod_Qj40USG6Qhq2XW',
        prices: ['price_1PrbsG009aFOms2RBaXuPZ6P', 'price_1PrbsG009aFOms2RBaXuPZ6P']
      }]
    }
  }
}
thin solar
#

looks right to me

visual flare
#

awesome

#

thank you so much

thin solar
#

that would be an array of objects

visual flare
#

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'
    }
  }
  ...
}
thin solar
#

Well you're passing the same product id and price over and over which doesn't make sense

#

But the structure looks correct

visual flare
#

yes i know

thin solar
#

Try it to see if it works

visual flare
#

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

thin solar
#

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

visual flare
#

this is the whole stacktrace i'm getting

thin solar
#

Yep

#

What is line 102 of RequestSender.js

visual flare
#

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);
thin solar
#

You can see that's where it's erroring in the error message

visual flare
#

RequestSender.js is from the stripe sdk, it's not mine

thin solar
#

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

visual flare
#

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"
    }
thin solar
#

I'll give you a hint

visual flare
#

ok, before you sent me that hint, i tried changing false to an empty array and i got "parameter missing"

thin solar
#

Yeah you need to pass something

visual flare
#

the possible enums are price, quantity and promotion code

thin solar
#

Yes, and what are you wanting customers to update?

visual flare
#

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