#kyrn0zofficiel_error

1 messages · Page 1 of 1 (latest)

drifting lagoonBOT
modern caveBOT
#

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.

drifting lagoonBOT
#

đź‘‹ 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/1222863873418330153

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

modern caveBOT
plucky laurel
#

hi! can you expand, what exact error/issue do you see and when? Is there a way for me to reproduce it?

thorny elk
#

yeah

#

but on my server i do a console.log and i get the link

#

Blocage d’une requête multiorigines (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur https://checkout.stripe.com/c/pay/cs_test_a156sKkkz8qPMV91w00DXdDPY5FRo4AS2LfxH3QhpIo1XDOqXtfoA7bLqO#fidkdWxOYHwnPyd1blpxYHZxWjA0SnBPX29HMWNvZEkwZnJgck1oZEFfQ0tkUG5cN3A9MDQ3b0BtdkRpPTNNaktEQkhwbjFgZFJPMTZ2XU1RY1doXDB8X04xTz1pVXJWfFRUMURMNUloYDA2NTV1UF9uNE1VNCcpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl. Raison : l’en-tête CORS « Access-Control-Allow-Origin » est manquant. Code d’état : 403.

#
router.post('/create-checkout-session', async (req, res) => {
  const session = await stripe.checkout.sessions.create({
    line_items: [
      {
        price: "price_1OuvO0B4fjaL5cwebjtOVW8W",
        quantity: req.body.nbTshirtOrder,
      },
    ],
    mode: 'payment',
    success_url: 'https://google.fr',
  });
  console.log(session.url);
  res.redirect(303, session.url);
});

it is the way a create my checkout session

#
require('dotenv').config()
const express = require('express');
const authRoutes = require('./routes/authRoutes');
const dataRoutes = require('./routes/dataRoutes');
const uploadRoutes = require('./routes/uploadRoutes');
const stripeRoutes = require('./routes/stripeRoutes');
const webhookRoutes = require('./routes/webhookRoutes');
const cors = require('cors');

const app = express();
const port = 5000;
app.use(cors());


app.use((req, res, next) => {
    if (req.originalUrl === '/webhook') {
        next()
    } else {
      express.json()(req, res, next)
    }
});

webhookRoutes(app);
authRoutes(app);
dataRoutes(app);
uploadRoutes(app);
stripeRoutes(app);


app.use('/data-storage', express.static('data-storage'));

app.use((req, res, next) => {
    console.log(`[${new Date().toLocaleTimeString()}] Request received: ${req.method} ${req.url}`);
    next();
});

app.listen(port, () => {
    console.log(`Server listening at http://localhost:${port}`);
});
plucky laurel
#

and how does your frontend call that endpoint?

#

this is just because you can't redirect from a XMLHttpRequest really, you need to change the approach, it's a common mistake when integrating Checkout

thorny elk
#
document.getElementById("checkoutB").addEventListener("click", function() {
    const postData = {
        nbTshirtOrder: totalTshirtsOrdered
    };
    
    const fetchOptions = {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(postData)
    };
    
    fetch('http://localhost:5000/create-checkout-session', fetchOptions)
    .then(response => {
        if (response.ok) {
            window.location.href = response.url;
        } else {
            throw new Error('Erreur lors de la création de la session de paiement');
        }
    })
    .catch(error => {
        console.error('Erreur lors de la création de la session de paiement :', error);
        alert('Une erreur est survenue lors de la création de la session de paiement. Veuillez réessayer.');
    });
});
``` like this
plucky laurel
#

if you're calling the backend with e.g fetch you can't redirect that, you should change the backend to return a 200 status with e.g. a JSON response that you put the session.url into and then in JS you read the JSON, take the URL, and set window.location to it.

thorny elk
#

like this :

router.post('/create-checkout-session', async (req, res) => {
  const session = await stripe.checkout.sessions.create({
    line_items: [
      {
        price: "price_1OuvO0B4fjaL5cwebjtOVW8W",
        quantity: req.body.nbTshirtOrder,
      },
    ],
    mode: 'payment',
    success_url: 'https://google.fr',
  });
  res.status(200).json(session.url);
});```
plucky laurel
#

yeah something that like. I think you need response.json() in the frontend too to parse it, but yes that's the idea

thorny elk
#

yeah i get it thanks you very much

#

and i have an other question if it's not too much

#

how can i get the id of the link that i generate to listen what event happens ?

plucky laurel
#

well session.id is the unique ID of the CheckoutSession object for instance

thorny elk
#

just to have some advice

#

I have a registration form. I receive all the information and I put them in a json file. However, I would like each registration to be linked to its payment id so that I know if the registration is valid or not. Do I receive the id at creation so that I can immediately write the id to the file or do I have to send an object to my webhook so that it writes the id to my file? I don't know if I've made myself clear.

Translated with DeepL.com (free version)

#

i use a translator to make sure that my words are clear

plucky laurel
#

it's perfectly clear don't worry

#

Do I receive the id at creation
yes, as I mentioned there's a session.id you can store in a database and look it up later when you're handling the webhooks for the successful payment. You can also add metadata to the CheckoutSession object to add your own information and references to it, that you can then check later when handling the webhook.

thorny elk
#

which event i had to listen to know if my session.id is accepted ?

plucky laurel
thorny elk
#

ok so i will get all the information i want in the event.data.object