#luanvdw-invoice metadata

1 messages Β· Page 1 of 1 (latest)

trail thunder
#

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?

lofty knot
#

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

trail thunder
#

could you share a snippet of your code

lofty knot
#
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?

trail thunder
#

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

lofty knot
#

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?

trail thunder
#

right

lofty knot
#

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)

  1. Would I need to do this through the webhook invoice.created for every invoice
  2. Would this be an "allowed" update on a finalised invoice
  3. 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?
trail thunder
#

did you try using the description field on the line item object when creating the subscription?

#

appologies I was mistaken

lofty knot
#
const subscription = await stripe.subscriptions.create({
  customer: 'cus_123',
  items: [
    {price: 'price_123'},
  ],
});

The item object does not accept description as a param,

trail thunder
#

prices descriptions are not client facing

lofty knot
#

Yea unfortunately, else that would have definitely helped here

trail thunder
#

yes I agree

#

so I don't think there's a way of doing what you are trying to achieve

lofty knot
#

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?

trail thunder
#

no unfortunately you can't update line items

lofty knot
#

Is there no way to keep an invoice in draft mode, and finalize it through code once the updates are complete?

trail thunder
#

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

lofty knot
#

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

trail thunder
#

I'm trying to replicate this to give you a clear answer

lofty knot
#

Thank you kindly! πŸ™

trail thunder
#

Honestly there's no easy way of doing that to be honest

lofty knot
#

πŸ™ˆ is there a tricky way?

trail thunder
#

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

lofty knot
#

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

trail thunder
#

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 πŸ™‚

lofty knot
#

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?

trail thunder
#

ok so finally a stone unturned was found

lofty knot
#

Thats good news!

trail thunder
#

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

lofty knot
#

Have not seen this before? Would this entail some sort of beta features?

trail thunder
#

It's not beta features but it's not a public feature. This gate is only given after careful consideration of the use case

lofty knot
trail thunder
#

The idea is that the invoice (the way we see it) is immutable and can’t be changed

lofty knot
#

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?

trail thunder
lofty knot
#

I see, thanks! So what would be the process to activate the pay_immediately feature?

trail thunder
#

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

lofty knot
#

Thanks! Your effort is really appreicated

trail thunder
#

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

lofty knot
#

I am trying this as we speak

trail thunder
#

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

lofty knot
#

can this be turned off?

#

the email part to a customer

trail thunder
#

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.

Learn how to use subscription schedules.

lofty knot
#

Okay, thanks! Appreciate the help. I'll investigate both options with my team and then make a decision on a way forward.

Thanks!

trail thunder
#

Sure. let me know if you need any more help.

lofty knot
#

Will do thanks!