#gracine
1 messages · Page 1 of 1 (latest)
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,
}
],
})
Hello! I think the issue is that you're using DateTime.now.to_i. If you want the start_date to be now you can supply the string 'now' as the value: https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-start_date
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
You really shouldn't use DateTime.now, you should use the string now instead.
As in start_date: 'now', in your code.
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
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).
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
Gotcha. What I recommend for that scenario is to first read our docs on backdating Subscriptions, then do the following for each Subscription:
- Create a backdated Subscription
- Create a Subscription Schedule from that Subscription: https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-from_subscription
- Modify the Subscription Schedule to have a phase that transitions them from free to paid at the desired date
ah the from_subscription must be followed by a subscriptionschedule.update
Yep.
I tried the from_subscription but it was always throwing because I had phases, start_date etc... params in the body
Ah, yeah, that won't work. 🙂
Have a look at the second code snippet in this section: https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing
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*
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.
You too!
back!
The goal is to make this process transparent to the user
when i create a subscription i get this
Error: This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority.
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