#mas-usequeuecom_api

1 messages ยท Page 1 of 1 (latest)

raw brambleBOT
#

๐Ÿ‘‹ 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/1354873611906846782

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

thin wasp
#

Hi! Your current solution works; are you having issues with it?

spring canyon
#

No issues, was trying to find a better and fool-proof way to add this. Also, if we add the cancel_at to be 12 months into the future (so Date.now + 12.months) this would successfully end the subscription after their last 12 month payment, right? Or will there be a proration given it's not exaclty the same cancel_at datetime?

thin wasp
#

Ignore the name - it's the model/approach you want for what you're doing here.

spring canyon
thin wasp
#

๐Ÿค”

spring canyon
#

So to make sure i understand it correctly, instead of adding a cancel_at to the subscription, we'd instead do the code below after the subscription is created. but based on the code below, how does it know which subscription to do this to? Ito only takes in the customer_id and customer could purchase more than one item.

Or

Does this modify the product price to now always be an installment? So whenever a client buys that subscription, it'll always end after 12 months automatically?

Stripe::SubscriptionSchedule.create({
  customer: '{{CUSTOMER_ID}}',
  start_date: 'now',
  end_behavior: 'cancel',
  phases: [
    {
      items: [
        {
          price: '{{PRICE_ID}}',
          quantity: 1,
        },
      ],
      iterations: 12,
    },
  ],
})
thin wasp
#

The first part. ๐Ÿ™‚

#

No effect on the product or price.

spring canyon
#

Got it!

thin wasp
#

One thing of note is that when you do that, Stripe does not automatically attempt payment of rhe first invoice immediately; it treats it like a recurring invoice and waits an hour.

spring canyon
#

Okay just checked the docs and to make it work for a specific subscription after checkout i'll need to pass in from_subscription and it'll do it to that subscription. So the code below should successfully automatically cancel the subscription after 12 months.

Stripe::SubscriptionSchedule.create({
  customer: CUSTOMER_ID,
  from_subscription: SUB_IDNUMBER,
  end_behavior: 'cancel',
  phases: [
    {
      items: [
        {
          price: PRICE_IDNUMBER,
          quantity: 1,
        },
      ],
      iterations: 12,
    },
  ],
})
spring canyon
#

Decided to go with below and seems to work exactly how we want. Thanks for the help!

cancel_at = Time.current + service_price_pay_over_month.pay_over_time_months.months
            cancel_at_unix = cancel_at.to_i
            Stripe::Subscription.update(
              subscription.id,
              {
                cancel_at: cancel_at_unix,
              }
            )
thin wasp
#

There we go. ๐Ÿ™‚ You're welcome! ๐Ÿ™‚