#b33f_subscription-upsell

1 messages ยท Page 1 of 1 (latest)

covert lodgeBOT
#

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

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

tropic pond
#

Hello

#

Is this to start a Subscription or to upgrade?

pastel arch
#

Hey ๐Ÿ‘‹
Relevant code:
-# configuration

    const stripe = getStripe();
    const [subscription, futurePrice] = await Promise.all([
        stripe.subscriptions.retrieve(stripeSubscriptionId),
        stripe.prices.retrieve(newSubscriptionPriceId)
    ]);

    const newPriceProduct = futurePrice.product;
    if (typeof newPriceProduct !== "string")
        return NextResponse.json({message: "Stripe Price Product not found."}, {status: 404})

    const configuration = await stripe.billingPortal.configurations.create({
        features: {
            subscription_update: {
                products: [
                    {
                        prices: [newSubscriptionPriceId],
                        product: newPriceProduct,
                    },
                ],
                enabled: true,
                default_allowed_updates: ['price'],
            },
            payment_method_update: {
                enabled: true,
            },
        },
        business_profile: {
            privacy_policy_url: getFormattedUrl(`${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/datenschutz`),
            terms_of_service_url: getFormattedUrl(`${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/agb`),
        },
    });
#

-# billing portal session

const baseReturn = getFormattedUrl(`app.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/${siteId}/plan`)
    try {
        const billingPortalSession = await stripe.billingPortal.sessions.create({
            customer: session.user.stripeCustomerId,
            return_url: baseReturn + "/available",
            configuration: configuration.id,
            flow_data: {
                type: "subscription_update_confirm",
                after_completion: {
                    type: "redirect",
                    redirect: {
                        return_url: baseReturn
                    }
                },
                subscription_update_confirm: {
                    subscription: stripeSubscriptionId,
                    items: [
                        {
                            id: subscription.items.data[0].id,
                            price: newSubscriptionPriceId,
                            quantity: 1,
                        },
                    ]
                }
            }
        });
tropic pond
#

This looks fine -- you just need to create two different Prices for that Product and list both Price IDs within features.subscription_update.products.prices

#

Then that should work fine

#

Are you seeing a particular issue at the moment?

pastel arch
tropic pond
#

Hmm I'm not sure I understand the issue you are running into still

pastel arch
#

Right now the user click a button and my server creates the configuration and the subscription update flow. However: this update flow only contains the monthly payment. But what if the user chose to pay yearly (with discount)?

tropic pond
#

Right that's because your newSubscriptionPriceId only contains 1 Price ID, right?

#

You need that to contain 2 Price IDs -- one for a monthly Price and one for a Yearly Price

pastel arch
pastel arch
tropic pond
#

Ah I see

pastel arch
covert lodgeBOT
tropic pond
#

You would need to handle that on your custom page in that case

#

So you would offer the annual option there to and then redirect to the specific Price

#

Otherwise, you don't have them choose between the two on your custom page and you let them do that on Customer Portal

pastel arch
tropic pond
#

Yep

#

Recommend testing it out!

pastel arch
#

ah got it ๐Ÿ‘ thanks ๐Ÿ™‚