#ali-raza_code

1 messages ¡ Page 1 of 1 (latest)

last tokenBOT
#

👋 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.

faint kindle
#

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.

torpid oasis
#

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

  1. Check if the community exists
  2. Create new prices for the product
  3. Deactivate the old prices
  4. Update the product with the new price
  5. Fetch all subscriptions for the product
  6. Update community in the database

NOTE: Should I share the code if you have understood the query

#

There will be 2 type of prices.

  1. Monthly
  2. Yearly

But for now focus on monthly

faint kindle
#

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?

torpid oasis
#

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 ?

faint kindle
#

what's your end goal? change the price of a subscription?

torpid oasis
#

Yes.

faint kindle
torpid oasis
#

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

faint kindle
#

can you try your code in test mode with Test Clocks, and see if it works?

torpid oasis
#

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,
          },
        ],
      });
    }
faint kindle
#

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.

torpid oasis
#

I will test it surely, It is just that I need confirmation if I am on the right track or not

faint kindle
#

yes you seem on the right track