#pro-pooja_api

1 messages · Page 1 of 1 (latest)

gilded currentBOT
honest loomBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

gilded currentBOT
#

đź‘‹ 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/1240932864120455238

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

weary karma
#

hello! gimme a while to take a look

#

Like what the error message mentions : "Nothing to invoice for subscription", I took a look at that customer and there are no pending invoice items for it. Can you share what you were expecting it to invoice for?

lavish cliff
#

As there is subscription changed event - evt_1PGjD1EhHWWFzWaM0Fyp1uDN, we need to charge customer for that and create an invoice

gilded currentBOT
carmine moat
#

Then you'd pay the in_xxx ID from the latest_invoice field on that customer.subscription.updated event. That is automatically generated to reflect the changes made on the subscription: in_1PAc4oEhHWWFzWaM0OQwpuO1

lavish cliff
#

We need to create invoice manually due to some csutom requirements

carmine moat
#

Which custom requirements exactly?

lavish cliff
#

For the current subscription cycle if user's invoice amount reaches above maximum amount what they had paid when they upgrade/degrade subscription, then they should be charged otherwise not.

carmine moat
#

Sorry, I don't understand the use case. Can you share some example objects that demonstrate the behaviour?

lavish cliff
#

No worries, Please explain me what is wrong with this post request - req_W3TeHd2nZZo21Z

#

In testing mode same post request with params is working fine - req_pbsfr9bHpSBE4e

carmine moat
#

I'd recommend reading about the subscription parameter which should explain the issue:

The ID of the subscription to invoice, if any. If set, the created invoice will only include pending invoice items for that subscription. The subscription’s billing cycle and regular subscription events won’t be affected.
https://docs.stripe.com/api/invoices/create#create_invoice-subscription

#

There are no pending items for sub_1OzNHvEhHWWFzWaM93vwQ7XC

lavish cliff
#

I am trying to create the invoice for the customer, of course, there will be no pending invoice

carmine moat
#

Then omit the subscription parameter

lavish cliff
#

Then how come same scenario is working in test mode for this request - req_YWEbZazyZqQ8g4

carmine moat
#

The subscription in that scenario most have pending items that you've added

lavish cliff
#

Same code is running to create the invoice for this request - req_Ge2sH0dOanlzxt
It is throwing error when we try to create the invoice it self, inoive items are attached later, when the inoive created

carmine moat
#

I'm not sure how else I can explain it to be honest. When you pass the subscription parameter, it attempts to create an Invoice using any pending invoice items attached to that Subscription. If there aren't any, then it errors

gilded currentBOT
lavish cliff
#

Same code is creating invoice successfully -
req_YWEbZazyZqQ8g4
While for this request it is failing - req_jFPnmXrSfneVL. Can you please give me insights what is wrong here?

alpine wraith
#

Hey! Taking over for my colleague. Let me catch up.

lavish cliff
#

Hey you there?

alpine wraith
#

While for this request it is failing - req_jFPnmXrSfneVL. Can you please give me insights what is wrong here?
I wasn't able to open this request

#

Can you double check the request Id ?

lavish cliff
#

Can you please check this -
req_Ge2sH0dOanlzxt ?

alpine wraith
#

Thanks, checking I managed to inspect this one

#

The error message:

Nothing to invoice for subscription
I think the error message is quiet explciite

#

However for the other subscription sub_1PHMTPGVCe8mF8QWjPlVsk3M there was

lavish cliff
#

Subscription "sub_1P4MZoEhHWWFzWaMGWawiHZM" is also associated with this request - req_Ge2sH0dOanlzxt

alpine wraith
#

Yes, if there is no pending item then no invoice will be generated

#

And the customer has no invoice.

#

What are you trying to achieve exactly ? why you are forcing the generation of an invoice from a Subscription ?

lavish cliff
#

Due to some custom requirements, we need to charge the user manually and create an invoice.

The sequence is as follows first we create an invoice for the subscription and then attach the invoice item to that invoice. But for this request - "req_Ge2sH0dOanlzxt" api is throwing an error at a time of creating invoice, so there is no invoice items attached.

honest loomBOT
alpine wraith
#

Due to some custom requirements, we need to charge the user manually and create an invoice.
For what exactly ? pay in advance a billing period or one time payments ?

lavish cliff
#

One-time payment, if the user upgrades the subscription

gilded sandal
#

you're using an old API version so the Invoices API works differently for you than is described in the docs

#

in your old version you have to create the Invoice Items first , and then create the Invoice(the opposite of what's in the docs).

lavish cliff
#

Can you please redirect me to the correct apis?

gilded sandal
lavish cliff
#

Can you please help me find both the API , the new one and the old one?

gilded sandal
#

it's the same APIs, just they behave differently.

lavish cliff
#

No, I was reading this -

#

Same api with same params is behaving diffrently in test mode and live mode, you mean that?

gilded sandal
#

no, I mean API versions.

lavish cliff
#

FYI, I am creating the invoice first and then attaching the invoice items. But API is throwing an error while creating an Invoice.

Default is 'exclude' -pending_invoice_items_behavior="exclude" , right?
Sorry, little confused here. Stripe accounts are on different api versions or you are referring to documents?

#

I mean the test account and live account

gilded sandal
#

FYI, I am creating the invoice first and then attaching the invoice items
yep , I explained why

#

that doesn't work on old API versions before the 2022 , unless you also pass `pending_invoice_items_behavior="exclude"

#

on old API versions (like yours) either you pass that parameter, or you create the items first, and then the Invoice.

#

Default is 'exclude' -pending_invoice_items_behavior="exclude" , right?
for you, no, it's not. That's the default in the current API version so that's what the docs say. On old API versions the default was include_and_require

#

it's nothing to do with test versus live mode

lavish cliff
#

For me the api version is -
2020-08-27. And the doc says .
Defaults to exclude if the parameter is omitted.

#

This api doc is for the "2020-08-27" version, right?

gilded sandal
#

no

#

the API docs is always for for the current version, only. It does not change itself to match your own API version, we don't keep the old versions of the docs.

lavish cliff
#

Okay

#

So, it is working as expected on test mode as its version 2024-04-10 and not on live mode cause its version is "2020-08-27", right?

gilded sandal
#

if by "test mode" you mean a specific Stripe account you're using for testing, and by "live mode" you mean a different Stripe account you use for production, then sure, yes

lavish cliff
#

Yes, we are using two different account for testing and live.

Thanks a lot, you saved my day.

lavish cliff
#

For latest api it is sating -

You may only specify one of these parameters: pending_invoice_items_behavior, subscription.

Request id - req_I9vE3yIVeREgki

#

How can I make it work for both the API versions?

gilded sandal
#

can you clarify why you're passing subscription?

lavish cliff
#

I need one-off invoice for that subscription

gilded sandal
#

where would the items for that invoice come from?

lavish cliff
#

attaching it to the invoice after invoice is created? Manual adding the items

gilded sandal
lavish cliff
#

How the invoice items and invoice will be linked, do I need to pass any parameter?

gilded sandal
lavish cliff
gilded sandal
#

either you pass a price object ID or you use unit_amount.

lavish cliff
gilded sandal
lavish cliff
#

Would it charge customer immediately?

gilded sandal
#

no

lavish cliff
#

If the customers default card is attached we need to charge them immediately. Then what can be done?

gilded sandal
lavish cliff
#

But we are not creating payment intent, so don't have payment intent id

#

Why invoice pay is not working as expected?

gilded sandal
#

there is a PaymentIntent in the Invoice, as the docs I linked also explain. Try it in testmode and you'll see.

gilded sandal
lavish cliff
#

$stripe->invoices->pay($invoice->id, []);
This was working when I was first creaing the invoice and then attaching the invoice items to it.
Now, The invoices are showing Pending invoice items and not paid

gilded sandal
#

sorry that doesn't make sense, you need to share some code/example IDs.

lavish cliff
#

Are you saying about this payment_intent param which is there in the response for this reuqest -
req_OtzPiXEECDbDfe

#

If yes, it is null for me

gilded sandal
#

it's null if you haven't finalized the invoice yet.

lavish cliff
#

I was following this steps

`$invoice = $this->stripe->invoices->create([
'customer' => $customerId,
'collection_method' => 'charge_automatically'
'subscription' => $subscription->id,

        ]);

        $this->stripe->invoiceItems->create([
            'customer' => $customerId,
            'subscription' => $subscription->id,
            'invoice' => $invoice->id,
            'amount' => $amount,
            'description' =>  'Subscription Updated',
        ]);


        $this->stripe->invoices->pay($invoice->id, []);`

To create and charge automatically.

#

It was working fine with new api. But not with old api

gilded sandal
#

ok well anyway, what is your current blocking issue?

lavish cliff
#

Now I have changed the sequnce , First creating the line item and then creating the invoice and pay invoice. But pay invoice not working

gilded sandal
#

if you'd like to get efficient help, please never say "not working", say what specific error message you got and include the request ID/stack trace 🙂

#

I have to leave, my colleague will take over. Note we've been chatting with you for over 4 hours now so I'd encourage you to take some to go and test things and read all the docs shared.

lavish cliff
#

Got it. It is creating draft invoice

gilded sandal
#

yep which is why I explained you have to finalize the draft invoice before it can be paid, check the docs and information provided to you.