#pro-pooja_api
1 messages · Page 1 of 1 (latest)
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.
- pro-pooja_webhooks, 1 day ago, 25 messages
- pro-pooja_webhooks, 2 days ago, 7 messages
- pro-pooja_webhooks, 3 days ago, 5 messages
- pro-pooja_subscription-created-event, 3 days ago, 8 messages
đź‘‹ 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.
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?
As there is subscription changed event - evt_1PGjD1EhHWWFzWaM0Fyp1uDN, we need to charge customer for that and create an invoice
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
We need to create invoice manually due to some csutom requirements
Which custom requirements exactly?
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.
Sorry, I don't understand the use case. Can you share some example objects that demonstrate the behaviour?
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
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
There are no pending items for sub_1OzNHvEhHWWFzWaM93vwQ7XC
I am trying to create the invoice for the customer, of course, there will be no pending invoice
Then omit the subscription parameter
Then how come same scenario is working in test mode for this request - req_YWEbZazyZqQ8g4
The subscription in that scenario most have pending items that you've added
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
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
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?
Hey! Taking over for my colleague. Let me catch up.
Hey you there?
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 ?
Can you please check this -
req_Ge2sH0dOanlzxt ?
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
Subscription "sub_1P4MZoEhHWWFzWaMGWawiHZM" is also associated with this request - req_Ge2sH0dOanlzxt
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 ?
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.
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 ?
One-time payment, if the user upgrades the subscription
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).
Can you please redirect me to the correct apis?
or you should pass https://docs.stripe.com/api/invoices/create#create_invoice-pending_invoice_items_behavior pending_invoice_items_behavior=exclude" and then the rest of the code works and you have the behaviour of the current API version.
Can you please help me find both the API , the new one and the old one?
it's the same APIs, just they behave differently.
you are reading/using https://docs.stripe.com/invoicing/integration , correct?
No, I was reading this -
Same api with same params is behaving diffrently in test mode and live mode, you mean that?
no, I mean API versions.
you are using a 2020 API version. The API changed in 2022 : https://docs.stripe.com/upgrades#2022-08-01 which changes how invoices and items work.
like I said — if you want this to work:
- in your old version you have to create the Invoice Items first , and then create the Invoice
- or you should pass https://docs.stripe.com/api/invoices/create#create_invoice-pending_invoice_items_behavior pending_invoice_items_behavior="exclude" and then the rest of the code works and you have the behaviour of the current API version
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
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 wasinclude_and_require
it's nothing to do with test versus live mode
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?
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.
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?
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
Yes, we are using two different account for testing and live.
Thanks a lot, you saved my day.
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?
can you clarify why you're passing subscription?
I need one-off invoice for that subscription
where would the items for that invoice come from?
attaching it to the invoice after invoice is created? Manual adding the items
then I'd say the options are
- create the InvoiceItems first and explicitly attach them to the Subscription(https://docs.stripe.com/api/invoiceitems/create#create_invoiceitem-subscription), and then create the Invoice with the
subscriptionparameer - or , create the Invoice + InvoiceItems and do not use the
subscriptionparameter.
How the invoice items and invoice will be linked, do I need to pass any parameter?
they're linked because you create the InvoiceItems with subscription:sub_xx and then you pass subscription:sub_xx when creating the Invoice and then as the docs say "the created invoice will only include pending invoice items for that subscription"
https://docs.stripe.com/api/invoices/create#create_invoice-subscription
Okay, Got it.
I am creatimg invoice for the one-off payment and price - https://docs.stripe.com/api/invoiceitems/create#create_invoiceitem-price, is required params
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
either you pass a price object ID or you use unit_amount.
It is showing invoice under
Pending invoice items,
Using this api to pay invoice after created- https://docs.stripe.com/api/invoices/pay
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
you can use that API, but generally the recommendation is one of the options from https://docs.stripe.com/invoicing/integration?method=send-invoice#accept-invoice-payment .
Would it charge customer immediately?
no
If the customers default card is attached we need to charge them immediately. Then what can be done?
you can call https://docs.stripe.com/api/payment_intents/confirm on the invoice->payment_intent
But we are not creating payment intent, so don't have payment intent id
Why invoice pay is not working as expected?
you will.
there is a PaymentIntent in the Invoice, as the docs I linked also explain. Try it in testmode and you'll see.
what does that mean?
$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
sorry that doesn't make sense, you need to share some code/example IDs.
in any case, we don't recommend using ->pay because it doesn't handle 3D Secure. use the approaches I told you ( https://docs.stripe.com/invoicing/integration?method=send-invoice#accept-invoice-payment , or confirming the Invoice's PaymentIntent on the backend) please
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
it's null if you haven't finalized the invoice yet.
again, the guide for working with one-off invoices is https://docs.stripe.com/invoicing/integration?method=elements and finalizing the invoice is in step 5 before paying it.
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
ok well anyway, what is your current blocking issue?
Now I have changed the sequnce , First creating the line item and then creating the invoice and pay invoice. But pay invoice not working
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.
Got it. It is creating draft invoice
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.