#luanvdw-invoice metadata
1 messages Β· Page 1 of 1 (latest)
hi, I'm trying to understand your use case to be able to better help you
do you mind me asking why do you need the metadata on the invoice?
Thank you for the response,
Here is a more detailed walk through,
When creating a subscription for a user, it will always be a "free" / $0 subscription. Only when they upgrade will the subscription be updated with billable line items
So there are 2 invoice scenarios, the first $0 invoice that is created when creating the subscription and then another when the subscription is updated resulting in an immediate charge with a prorated amount
Reason for adding the metadata: The invoice is for a subscription but does not detail which project of a user the subscription is for... so I want to add additional metadata to the invoice such that when a user receives their invoice, they can see which of their projects the particular invoice is for
could you share a snippet of your code
const updatedInvoice = await stripe.invoices.update(invoice.id, {
custom_fields: [
{
name: 'Project',
value: project.displayName,
},
],
})
ah apologies, I realised I referred to custom_fields as meta_data when indeed I meant custom_fields
Hope this makes more sense now?
ok so you can't actually change custom_fields on a created invoice but you can change the invoice_settings.custom_fields on . the customer object before creating the sunbscription
Mmmmh ok ok, I will investigate that route, thank you very much!
So if I were to add this under invoice settings, it will be used on every invoice and I would not need to add this on a webhook each time?
right
That sounds perfect, thanks!
The second part of the invoice update would have been to update the line items and how they are displayed on the invoice
The subscription consists of 4 price Items which are all "grouped" under a single product
When the invoice is generated, it only shows the product name 4 times...
So I would like to update the text of the invoice line item essentially, so that it will read something like
Product name: price item nickname (for example)
- Would I need to do this through the webhook
invoice.createdfor every invoice - Would this be an "allowed" update on a finalised invoice
- Is there another way similar to the scenario above whereby this could be done as a config before hand to avoid needing to do it on a per invoice basis?
did you try using the description field on the line item object when creating the subscription?
appologies I was mistaken
const subscription = await stripe.subscriptions.create({
customer: 'cus_123',
items: [
{price: 'price_123'},
],
});
The item object does not accept description as a param,
prices descriptions are not client facing
Yea unfortunately, else that would have definitely helped here
yes I agree
so I don't think there's a way of doing what you are trying to achieve
Is it not possible through webhooks?
Line items on an invoice can be updated? I think it is just a matter of knowing when exactly this change will be allowed?
no unfortunately you can't update line items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Is there no way to keep an invoice in draft mode, and finalize it through code once the updates are complete?
so the only way to achieve this is to have multiple products instead of multiple prices
regardless of whether the invoice is finalized or not, today we don't support changing line item description
this is inherited from the product itself
so basically if you want the description or the name to be changed you'll have to create multiple products
Ok thanks! I'll investigate that route π
Just circling back to the original question around custom fields. If the user has more than one project and there have more than one subscription what would be the best way to differentiate which subscriptions' invoices should get which custom field?
As each subscriptions' invoices should have the respective project name on it
Project 1
-> subscription
-> invoice: custom_field: project 1
Project 2
-> subscription
-> invoice: custom_field: project 2
I'm trying to replicate this to give you a clear answer
Thank you kindly! π
Honestly there's no easy way of doing that to be honest
π is there a tricky way?
since the invoice custom fields are inherited from the customer you can't actually create two projects with different custom fields for the same customer
the only way I could think of is creating different customers for each project
and having your database link all Stripe customer Ids to your customer
I honestly don't see a workaround
Thats going to be too messy
So at which point can one actually update an invoice then?
Is there no way to keep an invoice from being auto advanced and then updating even just the description / "Memo" of an invoice and then finalizing it with code
I know and I'm terribly sorry for that. I'm trying to ask my colleagues if there's any other way of solving this
to be honest I don't really have any other idea for you for the moment, but I'm checking if there are any stones unturned π
Thank you for your effort, it is greatly appreciated.
I think a lot of this will be solvable through code as soon as we can figure out how to make updates to an invoice and in order to do so it seems that it needs to remain in draft mode
so I think the questions start with... how do we keep automated invoices in draft mode?
ok so finally a stone unturned was found
Thats good news!
I don't know if you're familiar with our gates system
but there are some features that you could ask to opt-in
and one gate for subscriptions is called pay_immediately: false which gives you the ability to leave the invoice in a draft mode for an hour after creation
Have not seen this before? Would this entail some sort of beta features?
It's not beta features but it's not a public feature. This gate is only given after careful consideration of the use case
ah ok, I thought this was default behaviour as indicated here on the docs
https://stripe.com/docs/billing/invoices/subscription#adding-draft-invoice-items
The idea is that the invoice (the way we see it) is immutable and canβt be changed
I take it this is the idea for Stripe generated invoices and manually created invoices is where the default / public customization takes place
How would I go about achieving this gated pay_immediately: false feature?
Or is this something you will need to activate from your side on our account?
https://stripe.com/docs/billing/invoices/subscription#adding-draft-invoice-items
this is when the subscription is renewed
I see, thanks! So what would be the process to activate the pay_immediately feature?
I'm looking for an alternate solution as well
sorry it's taking me some time to verify this and get back to you with an answer
Thanks! Your effort is really appreicated
the pay_immediately gate should really be a last resort
There's another way you could get a draft for an hour with collection_method: "send_invoice" parameter on the subscription
I am trying this as we speak
but this means that your customer will receive an email with instructions on how to proceed with payment
which might not suite your use case
no
becasue the collection_method means how are we collecting the payment for the subscription
either by automatically charging the user's default payment method for invoices or by sending them an invoice to settle
so IMO you have two options
You could either use Subscription Schedules https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases which is a bit hectic but would generate a draft invoice for an hour and would still automatically charge the user. Or you should contact our support https://support.stripe.com/?contact=true to ask them whether it's possible to give you access to the pay_immediately gate, but you should really state your case because it's given only when there's no other way around.
Okay, thanks! Appreciate the help. I'll investigate both options with my team and then make a decision on a way forward.
Thanks!
Sure. let me know if you need any more help.
Will do thanks!