#ilyoTheHorrid (Endstream)
1 messages · Page 1 of 1 (latest)
Not without either:
- Manually amending the initial invoice to include the additional amount via a line item.
- Updating the
price_xxxobject part way through the subscription, using a schedule.
Thank you, the first solution seems easier, if that's correct can you point me to the right docs?
How you do it would depend on how you integrate and create subscriptions today?
I am using CardElement and this on the backend:
const subscription = {
customer: customerId,
items: [{ price: price.id }],
cancel_at: payment.dueDate,
proration_behavior: 'none'
}
Then you'll want to manually update the invoice that the subscription creation generates, before you confirm the invoice payment in the front-end: https://stripe.com/docs/api/invoiceitems/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
OK thank you, how would I get the ID of the first invoice to amend?
It's returned when you create the subscription: https://stripe.com/docs/api/subscriptions/object#subscription_object-latest_invoice
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I don't see any field with ii_... in the return object of the subscription
Because they're on the Invoice object, and only the in_xx ID is returned on Subscription by default. You need to expand the invoice field if you want the full object: https://stripe.com/docs/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I don't see in_ either in the subscription object, what is the field name?
latest_invoice. Can you share the sub_xxx ID you're looking at?
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']
});
Sure that'll work if you have a pre-existing Subscription
great, thanx!
But you can just pass expand on your .create call too
No need to then retrieve it again after creation
Sorry, that'll be expand: ['latest_invoice']
Exactly the same way:
stripe.subscriptions.create({
...params,
expand: ['latest_invoice']
})
See: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#create-subscription
thank you!
How do I get ii_ from in_?
The response from the subscription is
latest_invoice: {
id: 'in_1MKjFjDvJEUYbQTxa1EaXhZj',
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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 })
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.
I see. Is there a way around it without upgrading the API?
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:
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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.