#omri-subscriptions

1 messages · Page 1 of 1 (latest)

fierce lotus
turbid pewter
#
        schedule.id,
        {
          end_behavior: 'cancel',
          phases: [
              {
              plans: [
                  {
                      price: price,
                      quantity: 1
                  },
              ],
              iterations: iterations,
              },
          ],
        }, {stripe_account: stripe_uid})``` like that?
fierce lotus
#

seems like a reasonable attempt, what happened when you ran that in test mode?

turbid pewter
#

I will try now

#

error: The subscription schedule update is missing at least one phase with a start_date to anchor end dates to

fierce lotus
#

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

turbid pewter
#

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

fierce lotus
#

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?

turbid pewter
#

yes

#

req_x0OJniXMPV3gun

fierce lotus
#

looking

turbid pewter
#

please look on that also req_umisHrb0yOFLTI

fierce lotus
#

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

turbid pewter
#

yes, it's a bit painful

fierce lotus
#

yep!

turbid pewter
#

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

fierce lotus
#

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

turbid pewter
#

how do you see 2027?

fierce lotus
#

"end_date":1808743095

turbid pewter
#

ok thank you

turbid pewter
#

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

heady dove
#

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.

turbid pewter
#

I need that metadata in the webhook payment_completed, how I get that metadata?

heady dove
#

Can you double check the type of event that you're listening for, I'm not aware of a payment_completed event type?