#ruben_php-syntax-errors
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/1333472918365274152
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello.
Im receiving next error:
cart.html:836 Error: SyntaxError: Unexpected token '<', "<br />
<b>"... is not valid JSON
this is my code function before calling PHP one:
function initiateStripeCheckout(elements) {
var stripe = Stripe('pk_live_51QcEtTF1BXEd9C58ACRtObJpyQgFlcxFbPnKvdT2Ke2lkw2baz0Qm2iwnzFYkPmXcC8i9iyOJOdty6CXYganXjlb00YgFapkZ3');
var successUrl = 'https://www.dennis-snk.com/index.html?checkout=success';
var cancelUrl = 'https://www.dennis-snk.com/index.html?checkout=fail';
var userInfoApp = JSON.parse(localStorage.getItem("userInfo"));
var name = userInfoApp.name;
var email = userInfoApp.email;
console.log("Elements to Stripe: ", elements);
fetch('create-checkout-session.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(elements)
})
.then(function (res) {
return res.json();
})
.then(function (session) {
console.log("Atributos sesion: ", session);
return stripe.redirectToCheckout({ sessionId: session.id });
})
.then(function (result) {
if (result.error) {
console.error(result.error.message);
}
})
.catch(function (error) {
console.error('Error: ', error);
})
}
Input parameter "elements" brings array of objects considering "price" and "quantity" inside of it as follows:
Are you seeing any API errors in your server-side logs or Stripe logs?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
also redirectToCheckout is a deprecated function - https://docs.stripe.com/js/deprecated/redirect_to_checkout
You should use server-side redirect approach instead - https://docs.stripe.com/checkout/quickstart?lang=php
I cant use a server-side approach
because i will deploy my website and prices are higher if using server-side approach
Sorry I've not heard of anyone charging more for server-side redirect..
Anyways, the other option would be to manually set the URL to the checkout session URL by modifying window.location.href within your javascript.
no
this is not helping sorry.
I need to use my redirectToCheckout, as in other of my websites, that is working currently
the thing is, why am I receiving this
cart.html:836 Error: SyntaxError: Unexpected token '<', "<br />
<b>"... is not valid JSON
from the PHP create-checkout-session.php file
Have you tried debugging the code you have in that file? Like I mentioned above, are you seeing any API errors in your server/Stripe log?
no errors in Stripe log ๐ฆ
I cant debug my PHP file im my F12 dev console on Chrome
right?
At least I cannot see that file :S
Hi ๐
I'm stepping in as my colleague needs to go. Unfortunately we expect and require the developers we assist to be familiar with the relevant debugging techniques for their chosen programming language. I recommend you review some tutorials on writing/debugging PHP. That way we can be more helpful with our advice.
I mean, debugging this PHP is not possible apart from filling out of echo
guess thats not the solution to the problem
and its not giving any additional advice about the possible issue
Well it appears you are not passing valid JSON somewhere in you file I would recommend printing out the variables you are passing prior to whatever line of code throws that error on line 836
Havent you faced any similar issue to this previously?