#luke_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/1240626950091968562
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi! you have to finalize it so that is picked up for payment. Can you say more about your use case?
I'm trying to generate an invoice which is automatically paid. The customer has a default payment in their account, and I can make payments using paymentIntents, but I want it to be able to generate an invoice. If I try the following:
$stripe->invoiceItems->create([
'customer' => $stripeCustomerId,
'amount' => $amountDue * 100, // Convert AED to fils
'currency' => 'aed',
'description' => "Monthly service charge for {$currentMonth->format('F Y')}"
]);
// Create and finalize an invoice automatically
$invoice = $stripe->invoices->create([
'customer' => $stripeCustomerId,
'auto_advance' => true,
'collection_method' => 'charge_automatically'
]);
I see it generated an invoice under "Pending invoice items" for the correct amount, but I also see an invoice marked as paid under "invoices" for an amount of 0.00.
I can collect the payment manually, however, I was hoping of a way to make the payment automatically.
but I also see an invoice marked as paid under "invoices" for an amount of 0.00.
yeah that's because you're using an old approach/guide
you should be creating the Invoice first and then adding the InvoiceItems to it, not the other way around. In your code, on the latest API version(which you use), you are just creating a $0 invoice and the items are not pulled in(that's related to changes in https://docs.stripe.com/upgrades#2022-08-01, you must be using a guide that doesn't take that into account and does things the old way were you had to create pending items first)
you should use the guide https://docs.stripe.com/invoicing/integration?method=elements overall
Ahhh, I see. Thank you. I will test and get back to you
Brilliant, it works! Just one last question, I see that the invoice is set to open, and the payment is set to incomplete. Am I right in thinking that the system waits an hour before attempting payment?
hi! I'm taking over this thread.
no, you would need to call the Pay endpoint to try to pay the Invoice: https://docs.stripe.com/api/invoices/pay