#inquisitive_code
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/1232655586944880772
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, let me help you with this.
You need to set the Invoice ID when creating an Invoice Item
should I create invoice item first or invoice first, which is the correct approach?
yes i have already tried by adding "invoice" field with invoice id while creating invoice items, but it is throwing error nothing to invoice for customer while creating invoice for the first time.
Could you please share the Request ID req_xxx? https://support.stripe.com/questions/finding-the-id-for-an-api-request
You create an Invoice first.
$invoice = $this->stripe->invoices->create([
'customer' => $stripeCustomer->id,
'collection_method' => 'send_invoice',
'days_until_due' => 7,
'metadata' => [
'user_group_id' => $customBillingDto->userGroup->id,
'invoice_type' => 'custom_pricing',
'include_registration_fee' => $customBillingDto->includeRegistrationFee
],
]);
//add subscription invoice item
$this->stripe->invoiceItems->create([
'customer' => $stripeCustomer->id,
'amount' => 750 * 100, //multiplying it to convert to cents
'currency' => 'USD',
'description' => '6-Month Fill Finish Project Subscription',
'invoice' => $invoice->id,
]);
//add registration invoice item
if($customBillingDto->includeRegistrationFee){
$this->stripe->invoiceItems->create([
'customer' => $stripeCustomer->id,
'price' => config('services.stripe.base_plan_api_id'),
'description' => 'One Time Registration Fee',
'invoice' => $invoice->id,
]);
}
//finalize invoice
$this->stripe->invoices->finalizeInvoice($invoice->id);
// Retrieve the updated invoice to see the final status
$invoice = $this->stripe->invoices->retrieve($invoice->id);
on this code I am getting this error: Nothing to invoice for customer
Could you please share the Request ID req_xxx? https://support.stripe.com/questions/finding-the-id-for-an-api-request
Looking at it...
Ok, it's an API version issue. In the recent versions this setting is exclude by default: https://docs.stripe.com/api/invoices/create#create_invoice-pending_invoice_items_behavior
This way you can create an empty Invoice. Are you able to set it as exclude excplicitly when creating an Invoice?
I think the setting was added only in 2022: https://docs.stripe.com/changelog#march-1,-2022
But you're using version 2020-03-02
$invoice = $this->stripe->invoices->create([
'customer' => $stripeCustomer->id,
'collection_method' => 'send_invoice',
'days_until_due' => 7,
'metadata' => [
'user_group_id' => $customBillingDto->userGroup->id,
'invoice_type' => 'custom_pricing',
'include_registration_fee' => $customBillingDto->includeRegistrationFee
],
'pending_invoice_items_behavior' => 'exclude'
]);
//add subscription invoice item
$this->stripe->invoiceItems->create([
'customer' => $stripeCustomer->id,
'amount' => 750 * 100, //multiplying it to convert to cents
'currency' => 'USD',
'description' => '6-Month Fill Finish Project Subscription',
'invoice' => $invoice->id
]);
//add registration invoice item
if($customBillingDto->includeRegistrationFee){
$this->stripe->invoiceItems->create([
'customer' => $stripeCustomer->id,
'price' => config('services.stripe.base_plan_api_id'),
'description' => 'One Time Registration Fee',
'invoice' => $invoice->id,
]);
}
should this fix? right ? By the way how can I confirm which api is it using, it was working fine on my local, on local I was using different stripe account, on staging it was giving issue to me.
This request uses your default Stripe API version, so you can find it in your Dashboard -> Developers,
You need to test to see if this works, I can't predict it.
But you can force an API version for a specific request, to test it on local, without deploying to production: https://docs.stripe.com/libraries/set-version?lang=php
in case if I did not set api version which is the current case, what could be determining it to use different api version?
If you use different Stripe accounts on local and on prod, the reason could be that you created them at a different time and a different default API version was set.