#Illes - PHP invalid request
1 messages ยท Page 1 of 1 (latest)
Hello, thank you
No problem
The invalid request has to be coming from a specific api request to the stripe API
Do you know which api request is causing this error?
And, if so, can you provide a request ID to that specific request: https://support.stripe.com/questions/finding-the-id-for-an-api-request?
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
I'll need a request ID to help you debug the error further
Ok I see the problem. One moment while I gather some resources for you
Here is the response for that request:
error: {
message: "You must specify either `product` or `product_data` when creating a price.",
type: "invalid_request_error"
}
}
So, since you are specifying price_data and not the price, you will need to either specify product: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product or product_data: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
If you don't have a product created then you can just pass in product_data
So this is the current body of your request to create the checkout session (in your server-side PHP code):
line_items: {
0: {
price_data: {
unit_amount: "0",
currency: "huf"
},
quantity: "1"
}
},
mode: "payment",
success_url: "http://localhost:8081/stripe-test/payment-success.php?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "http://localhost:8081/stripe-test/payment-cancel.php"
}```
You have price_data specified
Which is fine if you don't have a price object
However, you need to additionally pass in a product or product_data (as seen in my above 2 links)
That code looks different than what's used in the request you shared (notice the different unit_amount values)
this is strange
i got the same log
even though in my code is different
maybe I should restart XAMPP
Have you changed the code recently?
in the last half hour
all files are saved
I restarted the server
but it is still not good
maybe I should logout an login stripe again
Add some log lines in that try block
makes sure that code is the code that's actually being run when you are making the request
Just to confirm your web server is using the latest code
I logged out from Stripe, but there is 2 factor authentication, and the client didn't respond to my sms
(I asked him to send me the code)
Ok that's fine
Still add some of those log statements in your code and run it
We just need to verify that the code running on your server is actually the latest
I succeeded to re-login with the backup code
I restarted the server
still the same errror message
Did you add log statements in that try block?
That is how we can know if you're deploying the latest code
Ok
From the requests being made it's clear that the code you're looking at isn't the code that's making the requests
Try adding print statements
Just basic ones in that try block
Then check the server logs to see if you see those print statements
when you create the checkout session you should see whatever you're printing out. if not, then that confirms that you're just deploying wrong.
I don't see what I print out
Ok then you aren't deploying your latest code correctly
This isn't a stripe issue
But rather a code deployment issue, so you need to spend time debugging that on your own
$stripeToken could not be the problem?
No
If you aren't even seeing the print statements you're making then you aren't deploying the code correctly
This isn't a stripe issue, so we really can't assist further here
But don't you have any ideas what may be the reason?
It doesn't have to do with stripe code, so no. It has to do with your code deployment
CHECKOUT_SESSION_ID
This is undefined
it says
may this be the cause?
Undefined constant 'CHECKOUT_SESSION_ID'.intelephense(1011)
@light parrot CHECKOUT_SESSION_ID is not a variable you can print out - that's something we insert into the success and cancel URLs automatically, so you should remove that specific log line. Even logging/printing a simple string like "test" would be enough.
As @gritty widget already said, the core issue here is that the code you are looking at (which you have added print statements to) is not the same code that is currently running and making requests. We don't have any insight or control over how you're deploying or running your code so this is really something you need to look at yourself and debug.
I don't know if that'll work since we have no idea what you're doing on your end, but you're welcome to try it. Please take the time to try some things out and see what you can get working.