#hash_api

1 messages ¡ Page 1 of 1 (latest)

graceful gateBOT
#

👋 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/1410300776714338387

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

placid fractal
#

Looks like you didn't pass the start_date at the top level.

{
  end_behavior: "release",
  phases: {
    0: {
      items: {
        0: {
          price: "price_1RsYVbF8BVnhmF8JrbPZazMF",
          quantity: "1",
        },
      },
      iterations: "1",
      proration_behavior: "create_prorations",
    },
    1: {
      items: {
        0: {
          price: "price_1RsYVbF8BVnhmF8JrbPZazMF",
          quantity: "1",
        },
      },
      proration_behavior: "none",
    },
  },
}
#

I believe it should be like this:

{
  start_date: <enter_date_here>
  end_behavior: "release",
  phases: {
    0: {
      items: {
        0: {
          price: "price_1RsYVbF8BVnhmF8JrbPZazMF",
          quantity: "1",
        },
      },
      iterations: "1",
      proration_behavior: "create_prorations",
    },
    1: {
      items: {
        0: {
          price: "price_1RsYVbF8BVnhmF8JrbPZazMF",
          quantity: "1",
        },
      },
      proration_behavior: "none",
    },
  },
}
unreal geode
#

As I said the ai on the doc was saying not to pass date with iteration so it is taken care of automatically

#

Wait I'll show you. Because I need to create schedule for what I want to achieve as I was told

placid fractal
#

I recommend testing the example I provided.

unreal geode
#

what date i put? i'm having a subscription already

#
        scheduleParams := &stripe.SubscriptionScheduleParams{
            Phases:      phases,
            EndBehavior: stripe.String(string(stripe.SubscriptionScheduleEndBehaviorRelease)),
        }
        _, err := subscriptionschedule.Update(schedule.ID, scheduleParams)
        return &tempItems, err
    }
    // if there was no schedule we create a new one
    scheduleParams := &stripe.SubscriptionScheduleParams{
        FromSubscription: stripe.String(subscription.ID),
    }
    newSchedule, err := subscriptionschedule.New(scheduleParams)
    if err != nil {
        return nil, err
    }
    // Step 2: Now update the schedule with the phases
    _, err = subscriptionschedule.Update(newSchedule.ID, &stripe.SubscriptionScheduleParams{
        Phases:      phases,
        EndBehavior: stripe.String(string(stripe.SubscriptionScheduleEndBehaviorRelease)),
    })```
#

the goal is to update the subscription for the end of the month

#

all the dates are already managed by the stripe subscription. I also had problem because i couldn't update the schedule from subscriptiopn with a phase directly

    if existingItems.TotalPrice-currentMonthAmount > 300 {
        prorationBehavior = stripe.String("always_invoice")
    }
    var phases []*stripe.SubscriptionSchedulePhaseParams
    if hasNextPhase {
        phases = []*stripe.SubscriptionSchedulePhaseParams{
            {
                Items:             currentPhaseItems,
                ProrationBehavior: prorationBehavior,
                Iterations:        stripe.Int64(1),
            },
            {
                Items:             nextPhaseItems,
                ProrationBehavior: stripe.String("none"),
            },
        }
    } else {
        phases = []*stripe.SubscriptionSchedulePhaseParams{
            {
                Items:             currentPhaseItems,
                ProrationBehavior: prorationBehavior,
            },
        }
    }```
#

this is the part where i'm just adding two phase or one phase depending if the user delete some subscription element

#

the goal is that for everything added the current subscription get immediatly updated until the end of the months and if the user delete something the element is only removed for next month

placid fractal
#

You shared the docs for updating subscription schedules not creating one.

unreal geode
#

you see my code? you can't create phases with a subscription, i got error from the api

placid fractal
#

I think we need to take a step back here.

unreal geode
#

i have to update after i create the schedule

#

i've been taking a lot of step back since i started implementing this xD

#

but basically. I have a few item for subscription.
When the user add an item it gets paid for the rest of the month with proration

#

when the user remove an item, it stays active until the end of the subscription and gets deleted the next month

#

stripe is my source of truth, i was told the only way to delete later is to use the subscription schedule

graceful gateBOT
neat raven
#

Hi, taking over as my teammate needs to step away. Let me catch up.

unreal geode
#

hello

#

i'm trying this but i'm not sure

#
        phases[0].StartDate = &schedule.Phases[0].StartDate
        scheduleParams := &stripe.SubscriptionScheduleParams{
            Phases:      phases,
            EndBehavior: stripe.String(string(stripe.SubscriptionScheduleEndBehaviorRelease)),
        }
        _, err := subscriptionschedule.Update(schedule.ID, scheduleParams)
        return &tempItems, err
    }
    // if there was no schedule we create a new one
    scheduleParams := &stripe.SubscriptionScheduleParams{
        FromSubscription: stripe.String(subscription.ID),
    }
    newSchedule, err := subscriptionschedule.New(scheduleParams)
    if err != nil {
        return nil, err
    }
    // Step 2: Now update the schedule with the phases
    phases[0].StartDate = &newSchedule.Phases[0].StartDate
    _, err = subscriptionschedule.Update(newSchedule.ID, &stripe.SubscriptionScheduleParams{
        Phases:      phases,
        EndBehavior: stripe.String(string(stripe.SubscriptionScheduleEndBehaviorRelease)),
    })```
neat raven
unreal geode
#

but in the documentation it was also said not to use the date and let it be done automatically with the iteration

#

tho i do read now iteration is deprecated as well

#

but then from what i understand in that part of the doc i should instead put the duration on the second phase actually?

graceful gateBOT
neat raven
#

You want to add it on the first phase

Where in the document are you referring to here?

unreal geode
#

i want the first phase to have the prorated amount added with the new items. And then the next phase when the first month of the subscription ends to have the new phase item being applied to it

#

and it was in the subscription schedule

#

but right now from what i read with the doc you gave me before which isn't really aligned with what that assistant says. the iteration is actually to set date for how the phase itself will last?

#

if i have one phase with a start and end date does that mean that after the end date the subscription won't have the items carried out to the next cycle?

#

it was there "stripe recommand the usage of iteration to avoid setting start_date and end_date manually

#

but my question is if i make a schedule update with one phase and put a start and end date to it. Will the next month still happen with the updated objects of that phase?

neat raven
unreal geode
#

yeah there are a lot of different response too. Sometime that ai part was getting correct part of the doc but sometime it does weird thing and some part of the subscription plan is using deprecated element too