#ruben_php-syntax-errors

1 messages ยท Page 1 of 1 (latest)

maiden ruinBOT
#

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

woven fiber
#

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:

quartz hazel
woven fiber
#

I cant use a server-side approach

#

because i will deploy my website and prices are higher if using server-side approach

quartz hazel
#

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.

maiden ruinBOT
woven fiber
#

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

quartz hazel
#

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?

woven fiber
#

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

cobalt nimbus
#

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.

woven fiber
#

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

cobalt nimbus
#

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

woven fiber
#

Havent you faced any similar issue to this previously?

cobalt nimbus
#

I have...and I fixed them by logging the data is was passing, which is what I am telling you to do

#

And, these errors are highly dependent on exactly how you have written your code

#

So that is what you need to review/fix