#dragonlord_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/1304189000424226917
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
$stripe->invoices->create([
'description' => 'Alpaca AI Credits',
'customer' => '{{CUSTOMER_ID}}',
'collection_method' => 'charge_automatically',
]);
$stripe->invoiceItems->create([
'customer' => '{{CUSTOMER_ID}}',
'currency' => 'usd',
'unit_amount' => 10000000,
]);
trying to write this code with php sdk but the old way of writing
I have the latest php sdk installed
Hi there ๐ in the code you shared initially, you're trying to pass collection_method in a request to create an Invoice Item, which isn't supported. Only Invoice creation requests accept that parameter.
I am trying to do this
$stripe->invoices->create([
'description' => 'Alpaca AI Credits',
'customer' => '{{CUSTOMER_ID}}',
'collection_method' => 'charge_automatically',
]);
$stripe->invoiceItems->create([
'customer' => '{{CUSTOMER_ID}}',
'currency' => 'usd',
'unit_amount' => 10000000,
]);
like stated in the documentation found here https://docs.stripe.com/billing/subscriptions/usage-based/pricing-models?dashboard-or-api=api&shell=true&api=true&resource=invoices&action=create#credit-burndown-model
Am I doing something wrong
That's different from what you shared in your initial post:
'description' => 'Credits',
'customer' => $customer_id, // Replace with actual customer ID
'collection_method' => 'charge_automatically',
]);```
That snippet is for creating an Invoice Item (the second part of the snippet you shared above).
The endpoint to create an Invoice Item doesn't accept the `collection_method` parameter:
<https://docs.stripe.com/api/invoiceitems/create>
That is instead provided when you create an Invoice by calling this endpoint:
<https://docs.stripe.com/api/invoices/create#create_invoice-collection_method>
I also think the code in that doc is missing some pieces.
It's not a flow I've personally walked through, but if you're creating the Invoice first and then creating Invoice Items, you'll want to provide the ID of the Invoice in the Invoice Item creation request:
https://docs.stripe.com/api/invoiceitems/create#create_invoiceitem-invoice
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.