#ilyoTheHorrid (Endstream)

1 messages · Page 1 of 1 (latest)

distant marlinBOT
kindred ruin
#

Not without either:

  • Manually amending the initial invoice to include the additional amount via a line item.
  • Updating the price_xxx object part way through the subscription, using a schedule.
wooden locust
#

Thank you, the first solution seems easier, if that's correct can you point me to the right docs?

kindred ruin
#

How you do it would depend on how you integrate and create subscriptions today?

wooden locust
#

I am using CardElement and this on the backend:

  const subscription = {
    customer: customerId,
    items: [{ price: price.id }],
    cancel_at: payment.dueDate,
    proration_behavior: 'none'
  }
kindred ruin
wooden locust
#

OK thank you, how would I get the ID of the first invoice to amend?

kindred ruin
wooden locust
#

I don't see any field with ii_... in the return object of the subscription

kindred ruin
wooden locust
#

I don't see in_ either in the subscription object, what is the field name?

kindred ruin
#

latest_invoice. Can you share the sub_xxx ID you're looking at?

wooden locust
#

I was looking for it in the example, I haven't yet created the subscription

#

Do I use retrieve like this?

stripe.subscription.retrieve('sub_XXX', {
  expand: ['invoice']
});
kindred ruin
#

Sure that'll work if you have a pre-existing Subscription

wooden locust
#

great, thanx!

kindred ruin
#

But you can just pass expand on your .create call too

#

No need to then retrieve it again after creation

kindred ruin
wooden locust
#

ah, great, thank you

#

actually, how do I pass the extand to create?

kindred ruin
wooden locust
#

thank you!

wooden locust
#

How do I get ii_ from in_?

#

The response from the subscription is

latest_invoice: {
    id: 'in_1MKjFjDvJEUYbQTxa1EaXhZj',
harsh cliff
#

You can either retrieve the Invoice and then step through the data in lines.data, which contains the invoice line items for the Invoice, including a invoice_item field that points to their Invoice Item:
https://stripe.com/docs/api/invoices/object#invoice_object-lines-data

Alternatively you can use this function to retrieve just the line items of the Invoice:
https://stripe.com/docs/api/invoices/invoice_lines

wooden locust
#

Thank you, for some reason I don't have the invoice_item in the response:

{
  object: 'list',
  data: [
    {
      id: 'sub_1MKjhcDvJEUYbQTxKb0OB9sG',
      object: 'line_item',
      amount: 112500,
      amount_excluding_tax: 112500,
      currency: 'usd',
      description: null,
      discount_amounts: [],
      discountable: true,
      discounts: [],
      livemode: false,
      metadata: {},
      period: [Object],
      plan: [Object],
      price: [Object],
      proration: false,
      proration_details: [Object],
      quantity: 1,
      subscription: null,
      subscription_item: 'si_N4tUvFzBxktTC0',
      tax_amounts: [],
      tax_rates: [],
      type: 'subscription',
      unique_id: 'il_1MKjhdDvJEUYbQTxkcfy5Nyx',
      unique_line_item_id: 'sli_17b2aeDvJEUYbQTxe6bfdbc9',
      unit_amount_excluding_tax: '112500'
    }
  ],
  has_more: false,
  url: '/v1/invoices/in_1MKjhdDvJEUYbQTxKo4tvL9d/lines'
}
#
    const lineItems = await stripe.invoices.listLineItems(subscription.latest_invoice.id, { limit: 5 })
harsh cliff
#

Hm, I think that might be because you're using an older API version, so the structure of objects that you're seeing may be different from what is currently listed in our spec.

wooden locust
#

I see. Is there a way around it without upgrading the API?

harsh cliff
#

There is an approach that allows you to use a different API version on a per-request basis (as long as you're not working in a strongly-typed language), but trying to use mix-matched API versions in a single integration can get tricky.
https://stripe.com/docs/api/versioning

Our API reference doc tries to provide warnings about fields that have changed between the API version set on your account, and the current default API version. Though I'm not sure if that goes back far enough to cover the API version that you're using.

Here is an example of that since the test account I'm logged into is currently on 2020-08-27:

#

Do you see any of those warning icons beside fields in the Invoice or Invoice Items section of the API ref? They may be able to provide some pointers.