#luke_api

1 messages ¡ Page 1 of 1 (latest)

violet sandalBOT
#

👋 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.

peak dew
#

hi! you have to finalize it so that is picked up for payment. Can you say more about your use case?

gusty crag
#

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.

gusty crag
peak dew
#

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)

gusty crag
#

Ahhh, I see. Thank you. I will test and get back to you

gusty crag
#

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?

echo pumice
#

hi! I'm taking over this thread.