#nerder
1 messages · Page 1 of 1 (latest)
Hi 👋
That depends on how you configure the invoice to advance
Finalize Invoice takes a Draft invoice and finalizes it
If you have auto_advance set to False it will not attempt to charge the customer though
in that case you would make the call to pay the invoice to either charge automatically if the user has a saved payment method or send the invoice as an email
i was thinking about something like this
await this.stripe.invoiceItems.create(
{
customer: customerId,
price: priceId,
},
{
stripeAccount: stripeAccountId,
},
);
let invoice = await this.stripe.invoices.create(
{
customer: customerId,
application_fee_amount: 10,
auto_advance: true,
},
{
stripeAccount: stripeAccountId,
},
);
invoice = await this.stripe.invoices.finalizeInvoice(
invoice.id,
{
expand: ['payment_intent'],
},
{
stripeAccount: stripeAccountId,
},
);
not sure if it make sense
but if i understand correctly finalizeInvoice is not needed right? it will be done automatically when i create the invocie with auto_advance?
SInce auto_advance is set to true the invoice will finalize as long as it has all the necessary information.
ok, since I need to get the payment intent back to the frontend (I'm using flutter_stripe)
and complete the payment in the frontend using the client_secret
Okay so in that case (where there isn't a payment method already attached) it will finalize itself and be in a state of requires_payment_method. You can get the Payment Intent client secret directly if you include the expand parameter in your invoice creation.
Ok i see, so i'll remove finalizeInvoice and add expand in the create method
await this.stripe.invoiceItems.create(
{
customer: customerId,
price: priceId,
},
{
stripeAccount: stripeAccountId,
},
);
let invoice = await this.stripe.invoices.create(
{
customer: customerId,
application_fee_amount: 10,
auto_advance: true,
expand: ['payment_intent'],
},
{
stripeAccount: stripeAccountId,
},
);
auto_advance should be the default so i can remove
Then, once you add the payment method on the client, the invoice will automatically process the payment
cool
invoiceItems is mandatory instead right?
or can i squeeze this into the create invoice method?
No, you do need to create them separately