I am trying to implement stripe checkout to me store and I get an error saying:
Here is my code:
onToken = (token) => {
fetch('/save-stripe-token', {
method: 'POST',
body: JSON.stringify(token),
}).then(response => {
response.json().then(data => {
alert(`We are in business, ${data.email}`);
});
});
}
Looks like there was an error parsing the object into json. It would be helpful to know what you are calling onToken with.
Make sure to set
Content-Type
andAccept
headers withapplication/json
when making your request:Make sure to always add a catch block to deal with errors. Also I suggest you return the
response.json()
instead of dealing with right away in the same then block (this is an anti-pattern that does not help in alleviating callback hell).