#madmac_api
1 messages · Page 1 of 1 (latest)
đź‘‹ 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/1364706349631410240
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
One possible way is to create adhoc one-time price when creating or updating subscription using add_invoice_items.price_data parameter: https://docs.stripe.com/api/subscriptions/create#create_subscription-add_invoice_items-price_data
You will ask user for the amount, then set in the field mentioned above.
So this method won't create a price in Stripe each time?
This is similar to what chatgpt suggested:
First invoice (immediate charge)
When you call stripe.subscriptions.create(...), include an inline invoice item via add_invoice_items (no dashboard Price needed):
// assume you’ve already calculated amountForFees = Math.round(basePrice * 0.04)
const sub = await stripe.subscriptions.create({ customer: cus_123, items: [{ price: price_ABC }], metadata: { cover_fees: 'true' }, add_invoice_items: [{ price_data: { currency: 'usd', product: prod_FEE, // a generic “Fee contribution” product you create once unit_amount: amountForFees, }, quantity: 1 }], // … });
That will tack on a one-off line item for the contribution on the very first invoice
Subsequent renewals
By default, Stripe generates renewal invoices in DRAFT for about an hour before finalizing. If you listen for the invoice.created webhook (status draft), you can add another invoice item to that same invoice:
// (inside your webhook handler)
if (event.type === 'invoice.created') { const inv = event.data.object; // only for subscriptions where cover_fees = true const sub = await stripe.subscriptions.retrieve(inv.subscription); if (sub.metadata.cover_fees === 'true') { // compute 4% of inv.subtotal (in cents) const tipAmt = Math.round(inv.subtotal * 0.04); await stripe.invoiceItems.create({ customer: inv.customer, invoice: inv.id, amount: tipAmt, currency: inv.currency, description: 'Contribution towards processing fees', }); } }
Because the invoice is still in DRAFT, your extra line-item will be merged in before payment is attempted
So this method won't create a price in Stripe each time?
This will not create a permanent price with Stripe every time. This price will only be one-time use.
The solution on first invoice on using add_invoice_items is correct.
For the subsequent subscription renewal, I'd recommend using price_data on stripe.invoiceItems.create() to create adhoc one-time price for the additional amount you would like to collect from the user, rather than using amount and currency directly: https://docs.stripe.com/api/invoiceitems/create#create_invoiceitem-price_data
This will maintain the consistency between your first subscription sign up and recurring renewal on how the adhoc price is created.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.