#Adi - customer portal

1 messages ยท Page 1 of 1 (latest)

languid vale
#

Hello. One moment while I catch up with threads here

#

Is this because some customers will have both an INR plan and a USD plan and you want them to be separate?

neon tide
#

yes

#

stripe has limitation that Indian customers cannot pay in USD (I have business registered in India)

#

I am able to accept payment from all the countries except India for that I am doing this

limber radish
#

@neon tide A Stripe customer can only accept payments in a single currency (the same customer wouln't be able to have both a INR and a USD subscription). You'd need to have them as two separate customers, and so you'd have separate customer portal sessions for them

neon tide
#

but how can I create separate portal session? On stripe dashboard I dont see any option to create new customer portal for adding INR products separately and USD products separately

#

sorry my bad actually even if we add INR and USD on stripe dashboard it works fine. Stripe has that intelligence to automatically separate that

#

Thanks for help and support

limber radish
#

๐Ÿ‘ glad to hear it works! I was just about to ask if you had tried this all out ๐Ÿ™‚

neon tide
#

from stripe customer billing portal once payment is success why does it not redirect to my application page?
check this code:

router.post('/create-customer-portal-session', isAuth, async (req, res) => {
    const sessionData = req.body;

    // Authenticate your user.
    const session = await stripe.billingPortal.sessions.create({
        customer: sessionData.customerId,
        return_url: 'http://localhost:3000/upgrade',
    });

    res.send({ url: session.url });
});

I have added return url http://localhost:3000/upgrade

limber radish
#

That rerturn URL is specifically for when a customer clicks the "<-- Return to <account name>" link on the portal - we don't redirect to that URL when paymetn is succesful

neon tide
#

ok got it

#

yeah that works

neon tide
#

if someone wants to switch from USD to INR then he must first cancel USD subscription and then only he can switch INR and vice versa is that correct understanding??

limber radish
#

If a customer wants to switch from USD to INR you need to create a whole new Customer object for them - Stripe Customers are tied to a specific currency, which can't be changed

neon tide
#

for free plan I will have to use O INR and $0 each is that correct?? for USD and INR separate payments?

limber radish
#

correct

neon tide
#

can I also maintain any metadata for billing portal session?
code:

router.post('/create-customer-portal-session', isAuth, async (req, res) => {
    try {
        const user_id = req.userId;
        const sessionData = req.body;

        // Authenticate your user.
        const session = await stripe.billingPortal.sessions.create({
            customer: sessionData.customerId,
            return_url: 'http://localhost:3000/upgrade'
        });

        res.send({ url: session.url });
    } catch (error) {
        console.error("create-customer-portal-session error: ", error)
        next(createError(400, "Failed to create stripe customer billing portal"));
    }
});
flint skiff
#

Hello ๐Ÿ‘‹
I'm stepping in for @limber radish .

I don't see any metadata being used in this code snippet. What are you trying to achieve?

neon tide
#

I tried this:

   const session = await stripe.billingPortal.sessions.create({
            customer: sessionData.customerId,
            return_url: 'http://localhost:3000/upgrade',
            metadata: {
                user_id: user_id,
                price_id: priceId,
            }
        });

got bad request

flint skiff
#

You can see the supported parameters here

neon tide
#

why I was looking for metadata because I wanted to update my database user with new subscription_id and price_id

#

this I will do in customer.subscription.updated event

#

on updating subscription customer id will also change or not?

flint skiff
#

That makes much more sense. The customer will stay the same

neon tide
#

ok then got it. I will query DB based on customer id and then update rest of the details

flint skiff
#

That sounds like a sensible workflow.

neon tide
#

Thanks a lot for help and support ๐Ÿ™‚ ๐Ÿ™