#masterwolfx

1 messages · Page 1 of 1 (latest)

plush sluiceBOT
pulsar niche
#

hi!

If i create some endpoints on my api to get products and prices and render them client-sid
sounds good
if i update the prices
update them how? it's not possible to change the amount or other meaningful details of existing Price objects ,you have to create new ones.
think there might be issues since old prices doesnt get deleted if they were used
yes, changing or adding new Prices doesn't have any effect on existing Subscriptions that are running using the old Prices, unless or until you manually update those Subscriptions. I think that's what you're describing?

clever oracle
#

I saw a yt tutorial doing this: "create some endpoints on my api to get products and prices and render them client-side", then making the request to stripe using that data client side, is this bad?

#

I was wondering if something can go wrong with this approach, like messing up with prices

pulsar niche
#

not sure I can say, I don't know what specific APIs or requests it would make

clever oracle
#
router.get('/products', async (req, res) => {
    const products = await stripe.products.list();
    res.status(200).json(products);
});

router.get('/prices', async (req, res) => {
    const prices = await stripe.prices.list();
    res.status(200).json(prices);
});
pulsar niche
#

seems like a normal enough thing, maybe a bit unrefined but it could work

clever oracle
#

then sending the priceId to this endpoint:

router.post('/payment', async (req, res) => {
    const { priceId } = req.body;
    try {
        const session = await stripe.checkout.sessions.create({
            line_items: [
                {
                    price: priceId,
                    quantity: 1,
                }
            ],
            mode: 'subscription',
            success_url: `${process.env.FRONTEND_URL}/profile`,
            cancel_url: `${process.env.FRONTEND_URL}`,
        })

        return res.status(200).json({
            url: session.url,
        });
    } catch (err) {
        return res.status(400).json({
            success: false,
            error: {
                message: "Invalid Price ID",
            }
        });
    }
});
pulsar niche
#

if I was doing this I would have logic/configuration to identify which specific Prices I want to use and my customers to use, instead of sending everything to the frontend, but it all works

pulsar niche
#

especially since you're giving the client all your Price IDs

clever oracle
pulsar niche
#

so I could easily use a browser extension/devtools and just send the ID of a Price that is cheaper than what you want, if you have one on your account

clever oracle
#

correct, so i came up with this solution "create some static endpoint like "billing/plan1", "billing/plan2" and manage the prices id server side."

pulsar niche
#

so on reflection yes, this is a pretty poor way to integrate

clever oracle
#

But i would have to hardcode priceIds on my endpoint

#

So i was thinking if there is a better way to do that

pulsar niche
#

have a database and store the IDs there and have other routes(that require admin access) or an internal dashboard for updating those database tables

#

or have a config file your server reads at runtime and you can edit/deploy changes to that file

clever oracle
#

ok sounds good

#

And what if (like you said before) a client buys a subscription A for 5 EUR but then i change it to 10 EUR

#

will he still pay 5 EUR?

pulsar niche
#

note you can not change an existing Price

#

the API just doesn't allow it, a Price price_xxx is immutable

clever oracle
#

yes my bad i mean, create a new one

#

which i want to be the default one

pulsar niche
#

adding new Prices doesn't have any effect on existing Subscriptions that are running using the old Prices, unless or until you manually update those Subscriptions

clever oracle
#

so there is a way to automatically do upgrades, right?

pulsar niche
#

depends what you mean by automatic, it's not really automatic, it's more that you would call the API for each of your existing subscriptions and change them to use the new Price