#gracine

1 messages · Page 1 of 1 (latest)

sturdy dirgeBOT
stuck lantern
#

Hi @turbid drift

#

Could you share your code in this thread instead? Thanks!

turbid drift
#

Hi, here is the code I use

#

Stripe::SubscriptionSchedule.create({
customer: stripe_customer.id,
start_date: DateTime.now.to_i,
default_settings: {
billing_cycle_anchor: 'phase_start'
},
end_behavior: 'release',
phases: [
{
items: [
{
price: premium_monthly_price.stripe_id,
quantity: 1
},
],
iterations: 12,
coupon: COUPON_CODE_12_MONTH_PREMIUM_FREE,
},
{
items: [
{
price: premium_monthly_price.stripe_id,
quantity: 1
},
],
iterations: 1,
}
],
})

sharp heron
turbid drift
#

ah, actually i was using a past date also

#

account.created_at.to_i,

#

I just changed DateTime.now to test since it was failing

sharp heron
#

You really shouldn't use DateTime.now, you should use the string now instead.

#

As in start_date: 'now', in your code.

turbid drift
#

Ah, I am trying to backdate since the code is part of a migration to stripe process

#

datetime.now was only a test

#

account.created_at.strftime('%FT%T%z') or account.created_at.to_i does not work

sharp heron
#

Ah, so you're trying to backdate the Subscription Schedule itself? If so, the start_date can be in the past, but all of the phases you specify must end in the future (meaning you can't specify a phase that ended in the past).

turbid drift
#

ok, maybe I can take a step back and explain what I am trying to do

#

We started at the begining of the year with free premium and no subscription feature, basically all users are considered premium

#

Now I integrated Stripe to our platform but I need to migrate existing users to our Stripe premium product subscription plan

#

I am trying to subscribe them at 0$ for X months left to their subscription (hence the account.created_at + 12 months after), and then start to charge the full price

#

this is what i am trying to do with the 2 phases in the subscription schedule

#

I tried to implement the Free aspect with a coupon that I removed after X month

#

depending on how many months are left for each user

sharp heron
turbid drift
#

ah the from_subscription must be followed by a subscriptionschedule.update

sharp heron
#

Yep.

turbid drift
#

I tried the from_subscription but it was always throwing because I had phases, start_date etc... params in the body

sharp heron
#

Ah, yeah, that won't work. 🙂

turbid drift
#

yeah ok

#

I will give another try, thank you

#

How does it work if I still have questions after I leave

#

is their any way to resume this conversation

#

there*

sharp heron
#

This thread will remain open for a little while, but if you come back and find it's been closed and locked you can ask a new question in #dev-help.

turbid drift
#

ok

#

got it, thx

#

have a good day

sharp heron
#

You too!

turbid drift
#

back!

#

The goal is to make this process transparent to the user

#

when i create a subscription i get this

#

subscription = Stripe::Subscription.create({
customer: stripe_customer.id,
backdate_start_date: account.created_at.to_i,
items: [
{
price: premium_monthly_price.stripe_id,
quantity: 1,
}
],
coupon: COUPON_CODE_12_MONTH_PREMIUM_FREE,
})

#

I don't want the user to have a payment method for the initial subscription which is free