#nugax_invoice-php
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/1234624500516262012
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- nugax_invoice-email, 2 days ago, 104 messages
Hi there koop!
So my issue is: I create an invoice in draft form, add invocie items to it. Works fine. When I move to open i get the above name error with the api. However, I archive the products after I add them to the invoice (draft) so I assume they cannot be archived prior to being set to open?
Add an invoice item code in php:
$invoiceItem = \Stripe\InvoiceItem::create([
'invoice' => $invoice_item['stripe_invoice_id'],
'price' => $price->id,
'description' => $invoice_item['item_desc'],
'customer' => $invoice_item['stripe_customer_id'],
'quantity' => $invoice_item['item_qty'],
]);
//Archive The Product Created | ** Cleans up the products area code in Stripe
$product->active = false;
$product->save(); ```
there thats better
Price:
$price = \Stripe\Price::create([
'product' => $product->id,
'unit_amount' => $amount_in_cents,
'currency' => $currency,
]); ```
When I move to open i get the above name error with the api.
I don't know what that sentence mean. What about name error?
here is the error i get
Also minor but the save() method in stripe-php was deprecated like 5 years ago. You really should migrate off of this!
how do you archive a product?
Ok, have a draft invoice
it has products attached with prices.
sorry sorry please pause
I am going to move it to open status
You're writing really short sentences and jumping around! Can you try and summarize the exact question you are asking? You were in the middle of giving me the error but then didn't
Ok, the error is this:
I have a draft invoice created. The invoice contains products, with price ids attached
(please do try to write a clear summary all in one message and not press return every sentence)
I am trying to change status to OPEN on draft. When I execute the code which I can provide to you, it get the following here and I will follow up with a ref id of the error as I execute it right now.
Error:
Error creating invoice item: You passed an empty string for 'name'. We assume empty values are an attempt to unset a parameter; however 'name' cannot be unset. You should remove 'name' from your request or supply a non-empty value.
Ref: req_LWuzNn5OwicyF9
Would you like to see the code for how I am utilizing the api to move from draft status to open in php?
Sorry to be a pain but can you please make sure to spend a few minutes writing a clear summary all in one message and not press return every sentence
Okay so you wrote code, you get an API error with a clear error message. That API error should also contain the exact URL in the Dashboard for the request failing which is https://dashboard.stripe.com/test/logs/req_LWuzNn5OwicyF9
if you look at it you can see it's the Create Product API https://docs.stripe.com/api/products/create where you are passing only one parameter: name: "" which is not allowed.
So you need to fix your code to pass a proper name when creating the Product in the API
nugax_invoice-php
It is creating a name when creating the product.
I will attach the response for the product that was created. So you can see the name created properly.
I'm sorry, you quickly replied a short sentence but did you look at what I shared first? There's the exact request your own code is making causing the issue at least.
I see that, but that is returned not from creating the product but from moving the invoice from draft status to open status.
Here is the response from creating the product where you can clearly see a name => 'Test 123'
I mean that request is totally unrelated, it's a call to the Update Product API https://docs.stripe.com/api/products/update which you do with that save() call I mentioned being deprecated
Let me check the code for creating the product. Please wait a moment. I am fairly certain I have a name field being passed.
ok, I will attach the entire code that adds a invoiceitem, product, and price to a draft invoice when created.
I really don't want to read the whole code sorry.
$publish_key = $_SESSION["stripe_publish_key"];
$secret_key = $_SESSION["stripe_secret_key"];
//Set API Key
\Stripe\Stripe::setApiKey($secret_key);
// Create the invoice item
try {
//Create The Product Object
$product = \Stripe\Product::create([
'name' => $invoice_item['item_desc'],
]);
// Create a price for the product
$price = \Stripe\Price::create([
'product' => $product->id,
'unit_amount' => $amount_in_cents,
'currency' => $currency,
]);
//Get the invoice item
$invoice = \Stripe\Invoice::retrieve($invoice_item['stripe_invoice_id']);
//Create The InvoiceItem Object
$invoiceItem = \Stripe\InvoiceItem::create([
'invoice' => $invoice_item['stripe_invoice_id'],
'price' => $price->id,
'description' => $invoice_item['item_desc'],
'customer' => $invoice_item['stripe_customer_id'],
'quantity' => $invoice_item['item_qty'],
]);
//Archive The Product Created | ** Cleans up the products area code in Stripe
$product->active = false;
$product->save();
// Invoice Item created successfully
//Return To Invoice To Edit/Save
$stripe_invoice_id = $_POST['stripe_invoice_id_given'];
$url_return = "edit_invoice.php?account_id_given=$account_id_given&stripe_invoice_id_given=$stripe_invoice_id";
header("location:$url_return");
} catch (Exception $e) {
// Handle any errors that occur during the creation of the invoice item
echo 'Error creating invoice item: ' . $e->getMessage();
}
}
You can see here, I create the product with the name attribute.
$product = \Stripe\Product::create([
'name' => $invoice_item['item_desc'],
]);
Sure and that's a PHP variable and it's likely null/empty in some cases
but i do archive that product at the end of the code, could that be causing it?
its not empty because I see it displayed when I pull the list of invoices. Its printed on the view_invoice
Thats how we know it is not empty.
As well as the price object being created properly.
I'm confident it's empty, or something else in your code calls the same API elsewhere with an empty variable.
it creates a product id, a price id and saves in the account. I can retrieve the invoice and get the name identifier. How would that variable be empty? It doesn't call the api anywhere else other than the code i have provided. The product is saved. I mean I can literally show you in the dashboard that it has a product description which, if I am not incorrect, what NAME is providing. Is that accurate?
You can clearly see the NAME item which was saved.
Our Create Product API requires a valid name. You are hitting an error saying you don't provide a name. You gave me a request id going with the error, I showed you where in the Dashboard it showed that exact request with an empty name.
Right now I'm focused on the only error you shared with me and that's the exact issue you have.
It's possible you have another issue, with another error or problem but you haven't mentioned that yet unfortunately.
Which, for this exact error, I provided a valid name. You are saying I did not and I have providedmultiple examples in which i did. The error doesnt occur on creating the product. It occurs when trying to change invoice status to open. You understand that part, correct?
In addition, the invoice in draft form, with the item attached to it, shows a valid name in the stripe dashboard.
And I was able to finialize the invoice in the dashboard.
The error doesnt occur on creating the product. It occurs when trying to change invoice status to open. You understand that part, correct?
You are convinced it's that but it's impossible so that's not what is happening. The error you have about the empty name is exactly what I showed you in your Dashboard and is completely unrelated to the Invoice finalization
So, you are telling me the issue is on product creation?
I am telling you that right now the only real error you shared is on Product creation. I can see you create real Product successfully with a name too. So I feel like you're looking in the wrong direction but you haven't been able to find what is causing some issue or say what the issue is yet
How can the issue be with product creationg, when the product we are discussing is in the dashboard products list?
Ill do this, I will create a product using the API and name it koopa. If it is on product creation, it will not create.
One moment.
You are too far down the rabbit hole right now and aren't really following what I am explaining. You found one error that's likely totally unrelated to your flow and you shared that and I explained what that error meant.
For now you haven't explained once what error you get or what you are trying to solve other than this specific error that is unrelated.
Please look at the top and you will see the dashboard =having created the product with the name KOOPAJAH
I believe that proves the issue is not related to product creation, at least on the draft invoice.
I know I keep telling you the same thing and you haven't said what your issue is
Here is the error. I am now going to try to move the draft invoice i just created from DRAFT to OPEN status
you say
Here is the error. I
but then there's no error
I recieve this error: Error creating invoice item: You passed an empty string for 'name'. We assume empty values are an attempt to unset a parameter; however 'name' cannot be unset. You should remove 'name' from your request or supply a non-empty value.
{
"error": {
"code": "parameter_invalid_empty",
"doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-empty",
"message": "You passed an empty string for 'name'. We assume empty values are an attempt to unset a parameter; however 'name' cannot be unset. You should remove 'name' from your request or supply a non-empty value.",
"param": "name",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_LWuzNn5OwicyF9?t=1714428349",
"type": "invalid_request_error"
}
} ```
Now please let me show you the code executed that created that error.
$account_id_given = $_POST['account_id_given'];
$stripe_invoice_id_given = $_POST['stripe_invoice_id_given'];
}
//Run Changing Invoice Status In Stripe
try {
// Retrieve the invoice object by its ID
$invoice = \Stripe\Invoice::retrieve($stripe_invoice_id_given);
// Update the invoice status to "open"
$invoice->status = 'open';
$invoice->save();
} catch (\Stripe\Exception\ApiErrorException $e) {
echo 'Stripe Error: ' . $e->getMessage();
die();
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
die();
} ````
Look at your logs in the Dashboard. You will see you do this
- Create Product
- Create Price
- Create InvoiceItem
- Update Product
- Create Product again with an empty name and that one is failing
ok i see that.
My guess is #5 is unrelated to the code you shared before and you are focused on that error for some reason but there's no other error in the account
What is the timestap of the failing one?
I also really don't get why you do $invoice->status = 'open', that's not really a thing, you're supposed to use our Finalize Invoice API https://docs.stripe.com/api/invoices/finalize
But conceptually we're still at the same stage: you want to move the Invoice to open but haven't shared one error about the code doing this that I can see
I have to run, I'll defer to @normal iris who is replacing me!
I bet that is the issue.
how two-shoes
hi*
Changing the code as he provided.
one moment.
try {
// Retrieve the invoice object by its ID
$stripe = new \Stripe\StripeClient($secret_key);
// Update the invoice status to "open"
$stripe->invoices->finalizeInvoice($stripe_invoice_id_given, []);
} catch (\Stripe\Exception\ApiErrorException $e) {
echo 'Stripe Error: ' . $e->getMessage();
die();
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
die();
} ```
Thats what I have now
OMG
THe issue was a </form> tag
he was right and I was wrong. wow
I did get a new error though.
Stripe Error: When automatic_tax[enabled]=true, enough customer location information must be provided to accurately determine tax rates for the customer.
Tax location status
Unrecognized location
So are you unblocked now?
That sounds like a pretty self-explanatory error, so you should be able to dig a bit and unblock yourself
i think i just got it to work
yes it did.
tell him he was right and I was wrong and I apologize! the issue was a </form> tag that was causing it to try to run a add product without entering name. He was completely right. I am a big enough man to say I was wrong! ๐
And that I appreciate his help.
You got it!
Please let him know. I feel like a jerk. lol
it was a simple oversight, but he was right
I should have scoured my code.
boom just worked exactly as it should
from creation of invoice to draft, to open, to pay, to void. and delete works
you guys rock and koopa was right on target. thank you.
IM all good now.
Thank you.