#Jose13

1 messages · Page 1 of 1 (latest)

fading smeltBOT
limpid parcel
#

Hello 👋
Not sure I completely follow the usecase here, do you have an example in mind?

knotty pilot
#

basically on a subscription that is set by a create checkout session, how can I add a late fee on a missed or failed payment? not sure if that makes more sense or not

#

this is my code attempt so far

`else if (eventType === 'invoice.payment_failed' && data.object.attempt_count === 1) {
try {
const invoiceObj = data.object;
const invoice = await stripe.invoices.retrieve(invoiceObj.id);

            if (invoice.metadata.lateFeeAdded === 'true') {
                return;
            }
            
            const lateFee = await stripe.invoiceItems.create({
                customer: invoice.customer,
                amount: 3500,
                currency: 'usd',
                description: "Late Fee",
            });
            console.log(lateFee);
            
            const updatedInvoice = await stripe.invoices.create({
                customer: invoice.customer,
                metadata: { lateFeeAdded: "true" },
                description: "Invoice with Late Fee",
                auto_advance: true,
            });
            
            await stripe.invoiceItems.create({
                invoice: updatedInvoice.id,
                price: lateFee.price.id,
            });
            
            const paymentIntent = await stripe.paymentIntents.retrieve(
                invoice.payment_intent
            );
            console.log('paymentIntent', paymentIntent);

        } catch (error) {
            console.log(`Error adding late fee invoice item: ${error}`);
            return res.status(500).send(error.message);
        }
    }`
limpid parcel
#

Okay, let me summarize to make sure I didn't miss anything.

1/ You're creating subscriptions using Checkout (which charges users payment method automatically)
2/ You're attaching it to a schedule
3/ In case an invoice fails payment,

you'd either like to add a one-time fee to the next invoice OR charge the users payment method separately?

knotty pilot
#

points 1-3 are correct yes. as for your last statement, if that is the only way to do it sure, but i was wondering if it was at all possible to add the fee to the current invoice that has failed? granted i read that finalized invoiced can not be updated.

limpid parcel
#

You'd want to create that when you receive invoice.payment_failed

knotty pilot
#

Ok, thank you very much. Will reach out again if i have more questions