#davidstanton_api

1 messages ยท Page 1 of 1 (latest)

next heathBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1334858572097523762

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

oak cipher
#

I don't really think that's possible with Checkout today unfortunately. You can't pass metadata to the sub/invoice to display on PDFs etc

oak prawn
#

not even with a invoice template? seems like that is actual what "invoice templates" are for. i'm tried setting custom field, no go, tried setting metadata, no go

oak cipher
#

Yes if you create a Customer object ahead of Checkout and assign the template to the customer (and use it with Checkout)

#

I think that will work

#

But you can't create them programmatically so manual work :/

oak prawn
#

but how you set the custom_field?

#

i got it working with metadata on the payments:Description
Adysis Floors for Prebid - Monthly, Domain for this subscription is: wethere.com but juts not invoices, which just dont make sense, it should flow throw from one to the other

#

this dont work: body: new URLSearchParams({
'invoice_settings[rendering_options][template]': TEMPLATE_ID, // Replace with your template ID
'invoice_settings[custom_fields][0][name]': 'Domain',
'invoice_settings[custom_fields][0][value]': domain,
}),

oak cipher
#

On which API/object?

oak prawn
#

if (event.type === 'customer.subscription.created') {

#

i get a success, but its a NO SHOW in invoices etc:const domain = subscription.metadata.domain;

            // โœ… Assign Invoice Template to Customer
            await fetch(`https://api.stripe.com/v1/customers/${customerId}`, {
                method: 'POST',
                headers: {
                    Authorization: `Bearer ${STRIPE_SECRET_KEY}`,
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: new URLSearchParams({
                    'invoice_settings[rendering_options][template]': TEMPLATE_ID, // Replace with your template ID
                    'invoice_settings[custom_fields][0][name]': 'Domain',
                    'invoice_settings[custom_fields][0][value]': domain,
                }),
            });

            console.log(`Customer ${customerId} updated with invoice template and custom field: Domain = ${domain}`);
            return new Response(JSON.stringify({ message: "Customer updated with invoice template and custom field." }), { status: 200 });
oak cipher
#

Well yes because at that point the initial invoice has created so setting the invoice settings will only apply to future invoices

#

Like I said, you want to create the Customer object before the Checkout Session, pass the cus_xxx ID to customer param. Then the invoices should inherit whatever invoice settings you set

oak prawn
#

{
"id":
"cus_RgflfP7LEFPcUc"
,
"object":
"customer",
"address":
null,
"balance":
0,
"created":
1738322997
,
"currency":
"usd",
"default_source":
null,
"delinquent":
false,
"description":
null,
"discount":
null,
"email":
"davidstanton@spormeon.com",
"invoice_prefix":
"2889B91B",
"invoice_settings": {
"custom_fields": [
"0": {
"name":
"Domain",
"value":
"wethere.com",
},
],
"default_payment_method":
null,
"footer":
null,
"rendering_options": {
"amount_tax_display":
null,
"template":
"inrtem_1QnFufE7dsAdGvZeM3N25ss0",
},
},
"livemode":
false,
"metadata": {},
"name":
null,
"phone":
null,
"preferred_locales": [],
"shipping":
null,
"tax_exempt":
"none",
"test_clock":
null,
}
Request POST body
{
"invoice_settings": {
"custom_fields": {
"0": {
"name":
"Domain",
"value":
"wethere.com",
},
},
"rendering_options": {
"template":
"inrtem_1QnFufE7dsAdGvZeM3N25ss0",
},
},
}

oak cipher
oak prawn
#

right ok, i think i see, its seems to be after /v1/checkout/sessions

oak cipher
oak prawn
#

still not liking it, im getting it there now, before /checkout/sessions but its not showing on invoices, it shows the custom_field that has been setup in the actual invoice template

oak cipher
next heathBOT
oak prawn
#

ye, but we are setting the custom_fields in the api now, dont it "override" the ones set in the template?, i they need to be deleted out the template?

oak cipher
#

Yes, the custom fields on the template take precedence over the invoice settings on the customer. See 3 and 4

oak prawn
#

so, just delete the custom field out the tempalte?

oak cipher
#

Sure, I guess. Whatever gives you the extensibility you need

oak prawn
#

yay at last!, cheers for the help

#

how about getting it to here, possible? tried numerious things again, and got zip

sullen plover
#

I guess it's the description of the Invoice? So you could modify it to add the URL.

oak prawn
#

na, tried that

sullen plover
#

Could you please share this Invoice ID?

oak prawn
#

in_1QnKNZE7dsAdGvZerfFCcLu4

#

it sets on the payment , just cant get it to add it to the end of the subscription description

#

also tried setting a 0 price line item, with "Domain this subscription relates to: blar.com", didn't work

sullen plover
#

I see you updated the description on the PaymentIntent - "Adysis Floors for Prebid - Monthly, Domain for this subscription is: get.com". I suspect it didn't help?

oak prawn
#

ye, never showed in custome portal, i treied loads of things

#

best log i got on one was "cant update finaziled invoice" or something like that

sullen plover
#

Which request was that?

oak prawn
#

no clue there been so many now

#

this is one:POST
/v1/invoices/in_1Qn59ME7dsAdGvZeCPrDVpk9
Request ID
HTTP status code
400
Time
30 Jan 2025, 22:20:47
IP address
108.162.245.212
API version
2024-12-18.acacia
Default
Idempotency key
7accc685-d862-4cf9-ae49-1ff661b26b30
User agent
No user agent information
API key
Error insight
Finalized invoices can't be updated in this way
Was this useful?
Yes
No
Response body
{
"error": {
"message":
"Finalized invoices can't be updated in this way",
"param":
"description",
"request_log_url":
"https://dashboard.stripe.com/test/logs/req_0rNmW8xB8XueY9?t=1738275647",
"type":
"invalid_request_error",
},
}
Request POST body
{
"description":
"Subscription domain: N/A",

#

req_0rNmW8xB8XueY9

sullen plover
#

I suspect you need to set the description before the Invoice is finalized. Have you tried it?

oak prawn
#

ye sure i did

sullen plover
#

I don't think there's any other way to update it unfortunately.

oak prawn
#

here is an eventID where i managed to get the description in there, but it didn't show in the user portal:evt_3Qmyw0E7dsAdGvZe1TvSvmB2

#

actually sorry, i think thats on the payment, where it does work

next heathBOT
crisp fiber
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

oak prawn
#

same question still, as in how can someone get a "extra" dewcription onto the end of a subscription description?

crisp fiber
oak prawn
#

do you know what invoice events fire to me before that then, as i'm trying with a webhook, get event, change, send in

#

all the ones i tried, just never got it working

#

this works at checkout-session, but its only getting it on the payments description

crisp fiber
#

the invoice.create

#

I'm not sure I understand