#nugax_invoice-php

1 messages ยท Page 1 of 1 (latest)

civic quartzBOT
#

๐Ÿ‘‹ 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.

fast lichenBOT
#

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.

late hearth
#

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,
    ]); ```
daring kernel
#

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?

late hearth
#

here is the error i get

daring kernel
#

Also minor but the save() method in stripe-php was deprecated like 5 years ago. You really should migrate off of this!

late hearth
#

how do you archive a product?

#

Ok, have a draft invoice

#

it has products attached with prices.

daring kernel
#

sorry sorry please pause

late hearth
#

I am going to move it to open status

daring kernel
#

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

late hearth
#

Ok, the error is this:

#

I have a draft invoice created. The invoice contains products, with price ids attached

daring kernel
#

(please do try to write a clear summary all in one message and not press return every sentence)

late hearth
#

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?

daring kernel
#

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

#

nugax_invoice-php

late hearth
#

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.

daring kernel
#

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.

late hearth
#

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'

daring kernel
late hearth
#

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.

daring kernel
#

I really don't want to read the whole code sorry.

late hearth
#
$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'],

    ]);
daring kernel
#

Sure and that's a PHP variable and it's likely null/empty in some cases

late hearth
#

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.

daring kernel
#

I'm confident it's empty, or something else in your code calls the same API elsewhere with an empty variable.

late hearth
#

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.

daring kernel
#

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.

late hearth
#

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.

daring kernel
#

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

late hearth
#

So, you are telling me the issue is on product creation?

civic quartzBOT
daring kernel
#

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

late hearth
#

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.

daring kernel
#

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.

late hearth
#

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.

daring kernel
#

I know I keep telling you the same thing and you haven't said what your issue is

late hearth
#

Here is the error. I am now going to try to move the draft invoice i just created from DRAFT to OPEN status

daring kernel
#

you say

Here is the error. I
but then there's no error

late hearth
#

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();
} ````
daring kernel
#

Look at your logs in the Dashboard. You will see you do this

  1. Create Product
  2. Create Price
  3. Create InvoiceItem
  4. Update Product
  5. Create Product again with an empty name and that one is failing
late hearth
#

ok i see that.

daring kernel
#

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

late hearth
#

What is the timestap of the failing one?

daring kernel
#

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

late hearth
#

timestamp

#

ooooh

daring kernel
#

I have to run, I'll defer to @normal iris who is replacing me!

late hearth
#

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

normal iris
#

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

late hearth
#

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.

normal iris
#

You got it!

late hearth
#

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.