#ali-raza_code
1 messages ¡ Page 1 of 1 (latest)
đ 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/1319279985898557481
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- ali-raza_code, 38 minutes ago, 47 messages
hi there!
Coded all logic for updating stripe product price update.
the code you shared is creating a new price, not updating an existing one.
My Use case is:
Amigo community
Community Creation flow
-
User can create or join multiple community with single email/account.
-
When user creates a community he is
community creator, only one! -
When user joins a community he is
community members, more than one. -
Each user when registering on Amigo, is also registered on Stripe - CustomerID is associated to that user.
-
When a community is created a product is created on Stipe.
-
Each member will use priceID and purchase subscription for that Product.
Edge case
- When user updates the price of community.
- It should effect incomming user not the currently subscribed user. On next billing cycle they should be charged for new/updated price
Question
- Please check my code if I am on write track or not.
Steps I have taken
- Check if the community exists
- Create new prices for the product
- Deactivate the old prices
- Update the product with the new price
- Fetch all subscriptions for the product
- Update community in the database
NOTE: Should I share the code if you have understood the query
There will be 2 type of prices.
- Monthly
- Yearly
But for now focus on monthly
I'm sorry but we can't review code for you. have you tried your code in test mode? do you see any errors?
or do you have a specific question?
Steps
Check if the community exists
Create new prices for the product
Deactivate the old prices
Update the product with the new price
Fetch all subscriptions for the product
Update community in the database
Can you tell me if I am in correct direction ?
what's your end goal? change the price of a subscription?
Yes.
at a high level you need to create a new Price object, and then update the Subscription (https://docs.stripe.com/billing/subscriptions/upgrade-downgrade).
I recommend testing this in test mode. and you can use Test Clocks for this: https://docs.stripe.com/billing/testing/test-clocks
Ali pays 20$/mo on 19-Dec-2024
subscription price updated on 23-Dec-2024 ( $30 )
now Ali should be charged $30 on 19-Jan-2025
but any person joining on 25-dec-2024 should be charge $30
This is tmy end goal
can you try your code in test mode with Test Clocks, and see if it works?
For this I did.
- Create a new price for that product
- Archieve old price
- fetch all subscription by the price id
- and then update all subsctiptions with new priceID.
Is this correct?
Are you there?
This is the main part on which I need clarification
// Step 5: Fetch all subscriptions for the product
const subscriptions = await stripe.subscriptions.list({
price: community.stripe_monthly_price_id,
});
// Step 6: Update all subscriptions with the new price
for (const subscription of subscriptions.data) {
await stripe.subscriptions.update(subscription.id, {
items: [
{
id: subscription.items.data[0].id,
price: monthlyPriceId?.id,
},
],
});
}
yes that looks correct. but like I said multiple times, you need to try your code in test mode to see if it works or not.
I will test it surely, It is just that I need confirmation if I am on the right track or not
yes you seem on the right track