#dragonlord_api

1 messages ยท Page 1 of 1 (latest)

pastel hatchBOT
#

๐Ÿ‘‹ 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.

blissful meadow
#
$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

lucid cedarBOT
hard olive
#

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.

blissful meadow
#

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

Create your usage-based pricing model with Stripe Billing

#

Am I doing something wrong

hard olive
#

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.

blissful meadow
#

okay I was trying to follow the doc to do Credit burndown model

#

and those were steps it showed

#

you are right

#

I was following the documentation wrong

#

sorry my code was wrong