#omri-subscriptions
1 messages · Page 1 of 1 (latest)
hi there! you'd call https://stripe.com/docs/api/subscription_schedules/update#update_subscription_schedule-phases and need to pass in the full details of the existing phases, while setting iterations on each one to what you want
schedule.id,
{
end_behavior: 'cancel',
phases: [
{
plans: [
{
price: price,
quantity: 1
},
],
iterations: iterations,
},
],
}, {stripe_account: stripe_uid})``` like that?
seems like a reasonable attempt, what happened when you ran that in test mode?
I will try now
error: The subscription schedule update is missing at least one phase with a start_date to anchor end dates to
yep, because you need to pass the full details of the phase. It's exactly the same as the API call you'd use to create the schedule initially, you have to pass all the same parameters
it's a bit painful to work with unfortunately
this is how I create: subscription = Stripe::SubscriptionSchedule.create({ customer: customerId, start_date: 'now', end_behavior: 'cancel', phases: [ { plans: [ { price: price.id, quantity: 1 }, ], iterations: occurrences, }, ], }, stripe_account: entity_stripe_uid) this start_date is out of the phases
hmm, seems ok then. can you share the request ID req_xxx of the failed request or the ID of the schedule or something so I can look at your logs?
looking
please look on that also req_umisHrb0yOFLTI
basically you need to pass the existing start_date of the phase , again, on the update
I don't have a ruby example but for example in PHP I do this :
$sched = \Stripe\SubscriptionSchedule::create([
"from_subscription" => $subscription->id
]);
$sched = \Stripe\SubscriptionSchedule::update($sched->id, [
'phases' => [
[
'start_date' => $sched->phases[0]->start_date,
'plans' => [
[
'price' => $subscription->items->data[0]->price->id,
'quantity' => $subscription->items->data[0]->quantity
],
],
"iterations" => 60
]
]
])
you can see how you pass the existing start_date from the phase when updating it
yes, it's a bit painful
yep!
it is work without errors, but I do not see the iterations on the return object
"id": "sub_sched_1Ksnf3KqSkWKDAjfifYAtdoM",
"object": "subscription_schedule",
"canceled_at": null,
"completed_at": null,
"created": 1650976713,
"current_phase": {"end_date":1808743095,"start_date":1650976695},
"customer": "cus_LZxZ7WtM61TjGz",
"default_settings": {"application_fee_percent":null,"automatic_tax":{"enabled":false},"billing_cycle_anchor":"automatic","billing_thresholds":null,"collection_method":"charge_automatically","default_payment_method":"pm_1KsnejKqSkWKDAjftAwcOBwM","default_source":null,"invoice_settings":{"days_until_due":null},"transfer_data":null},
"end_behavior": "cancel",
"livemode": false,
"metadata": {},
"phases": [
{"add_invoice_items":[],"application_fee_percent":null,"billing_cycle_anchor":null,"billing_thresholds":null,"collection_method":null,"coupon":null,"default_payment_method":null,"default_tax_rates":[],"end_date":1808743095,"invoice_settings":null,"plans":[{"billing_thresholds":null,"plan":"price_1KsneTKqSkWKDAjfTI6xvW94","price":"price_1KsneTKqSkWKDAjfTI6xvW94","quantity":1,"tax_rates":[]}],"prorate":true,"proration_behavior":"create_prorations","start_date":1650976695,"tax_percent":null,"transfer_data":null,"trial_end":null}
],
"released_at": null,
"released_subscription": null,
"renewal_interval": null,
"status": "active",
"subscription": "sub_1KsnelKqSkWKDAjfq2BDLVGF",
"test_clock": null```
req_o0gpNt80YbglDs
yeah, iterations is not actually a field of the schedule
basically it's only a parameter, what it changes is the end_date on the phase , it's a kind of shortcut
you can see the end_date is now 2027 for instance
how do you see 2027?
"end_date":1808743095
1808743095 is the unix timestamp of Monday, 26 April 2027 12:38:15
https://www.epochconverter.com/
ok thank you
hey
I need to pass metadata to the charge object, how I'm doing that?
I try to do it like that: schedule_updated = Stripe::SubscriptionSchedule.update( schedule.id, { metadata: metadata, end_behavior: 'cancel', phases: [ { plans: [ { price: schedule.phases.first.plans.first.price, quantity: 1 }, ], iterations: params[:occurrences], start_date: schedule.phases.first.start_date }, ], }, {stripe_account: @direct_debit.entity.stripe_uid})
but in the webhook the charge object did not have the metadata
HI 👋 metadata does not move from one object to another automatically, in that snippet you're adding metadata to the Subscription Schedule object so that is where the data will be available.
I need that metadata in the webhook payment_completed, how I get that metadata?
Can you double check the type of event that you're listening for, I'm not aware of a payment_completed event type?