#inquisitive_code

1 messages ¡ Page 1 of 1 (latest)

neat warrenBOT
#

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

frail prawnBOT
fallow falcon
#

Hi, let me help you with this.

#

You need to set the Invoice ID when creating an Invoice Item

raw latch
#

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.

fallow falcon
raw latch
#

$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

fallow falcon
raw latch
#

request id: req_OKGlLmx1Oa8vZl

#

@fallow falcon did you find it?

fallow falcon
#

Looking at it...

raw latch
#

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

fallow falcon
#

This request uses your default Stripe API version, so you can find it in your Dashboard -> Developers,

fallow falcon
raw latch
#

in case if I did not set api version which is the current case, what could be determining it to use different api version?

fallow falcon
#

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.