#xzel_customerportal-upgrade

1 messages ยท Page 1 of 1 (latest)

green leafBOT
#

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

narrow prairie
#

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 ?

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?

narrow prairie
#

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)

stuck mango
#
{"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

narrow prairie
#

Are you sure you have the right Product and Price ids in that Configuration?

stuck mango
#

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

narrow prairie
#

Okay what exact Product and Price does your Subscription have?

stuck mango
#

The one I'm trying to upgrade is the first one to the second one.

narrow prairie
#

(looking)

stuck mango
#

Thanks!

narrow prairie
#

still debugging. Sorry this product is so hard to debug, especially when using such advanced configuration features ๐Ÿ˜ฆ

stuck mango
#

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

narrow prairie
#

no that wouldn't make any sense honestly

stuck mango
#

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

narrow prairie
#

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

stuck mango
#

Ah okay I'm very happy to be the one confusing stuff lol

narrow prairie
#

Can you try to remove flow_data for now to see what happens?

stuck mango
#

So I do have a separate call without it, just opening up the portal

narrow prairie
#

can you show me what you see when you try that?

stuck mango
#
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

narrow prairie
#

Hum

#

did you modify the Subscription I'm looking at or a different one?

stuck mango
#

hmm it combined them though haha

narrow prairie
#

(really what you're doing is absolutely not what you want :p)

stuck mango
#

sub_1Pdw02I9XpkbIXSJmuZrUW62

#

I believe you lol

narrow prairie
#

Can you go back to whatever you have so I can keep debugging? You just changed the Subscription unfortunately

stuck mango
#

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

narrow prairie
#

no but you changed the Subscription so I would need it back to exactly what it was before

stuck mango
#

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

narrow prairie
#

can you try again to confirm that you get the same error?

stuck mango
#

So still getting the incorrect info on the general portal, can't change subs

narrow prairie
#

okay

stuck mango
#

1 sec, need to revert the Db change and i'll be able to retest the flow API

narrow prairie
#

oh boy ๐Ÿ˜…

#

it's okay let's pause I'll just try to reproduce on my own account at this point, might be safer!

stuck mango
#

Thats all good, this is all local

narrow prairie
#

this looks like purely internal HTTP header.

stuck mango
#

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

narrow prairie
#

Sorry I don't really follow your train of thoughts. You were already including the Product and Price ids right?

stuck mango
#

Sorry I'm talking about including default_allowed_updates: [ 'promotion_code', 'price' ]

narrow prairie
#

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

stuck mango
#

I mean its a great API but being perfect is tough

narrow prairie
#

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 ๐Ÿ˜…

stuck mango
#

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

narrow prairie
#

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

stuck mango
#

Ah so I'd probably have to handroll that logic anyways

narrow prairie
#

yes

stuck mango
#

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

narrow prairie
stuck mango
#

Ah so is the '{{SUB_ITEM_ID}}' the value I need to pull out of the previous subscription?

narrow prairie
#

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

stuck mango
#

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?

narrow prairie
stuck mango
#

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

narrow prairie
#

๐Ÿ‘

stuck mango
#

Ah yeah this seems good

#

Thank you very much for the help, much appreciated