I am trying to attach a payment to a invoice. This can only be done to invoices not in status "draft", "paid" or "canceled". When I create the Invoice via API on a customer with a working payment method, finalising the invoice will always go to state paid immediately. The option "collection_method":"send_invoice"
would send a email, which I don't want, because I want to connect a already finished payment intent using attach via API.
When creating a invoice in the dashboard, there is a option "don't send invoice to customer". This doesn't seem to be available in the API, is that right?
So the issue for me was that finalizing the invoice was going directly to status "paid" because there were no items or line items attached and the amount of the invoice was 0. (docs)
I was able to attach the already successfully paid paymentIntent following these Steps in the Stripe Shell:
stripe invoices create --customer="cus_SeZtpMBgo8yzKm" --collection-method="charge_automatically" --auto-advance=false
stripe invoice_items create --amount=6900 --invoice="in_1RjgdIPt62ypWkCOW16BTf5C" --customer="cus_SeZtpMBgo8yzKm"
stripe invoices finalize_invoice in_1RjgdIPt62ypWkCOW16BTf5C --auto-advance=false
stripe invoices attach_payment in_1RjgdIPt62ypWkCOW16BTf5C --payment-intent="pi_3RjcWOPt62ypWkCO0vElthm5"