#masterwolfx
1 messages · Page 1 of 1 (latest)
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 theamountor 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?
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
not sure I can say, I don't know what specific APIs or requests it would make
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);
});
seems like a normal enough thing, maybe a bit unrefined but it could work
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",
}
});
}
});
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
that's fine but note anyone could call that endpoint with any Price ID they want
especially since you're giving the client all your Price IDs
Yes thats what i was "scared" about
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
correct, so i came up with this solution "create some static endpoint like "billing/plan1", "billing/plan2" and manage the prices id server side."
so on reflection yes, this is a pretty poor way to integrate
sounds good
But i would have to hardcode priceIds on my endpoint
So i was thinking if there is a better way to do that
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
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?
note you can not change an existing Price
the API just doesn't allow it, a Price price_xxx is immutable
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
so there is a way to automatically do upgrades, right?
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