#moez-checkout

1 messages · Page 1 of 1 (latest)

dusty nexus
#

Hello! What specifically is the issue? Is there anything logged in your catch block?

lunar holly
#

now is 500 error:

Error: Request failed with status code 500
    at createError (bundle.js:7148:15)
    at settle (bundle.js:7169:12)
    at XMLHttpRequest.onloadend (bundle.js:7500:7)
dusty nexus
#

Ok, that implies to me that there's an error in your server code that's creating the Checkout Session (the axios call to http://127.0.0.1:3000/api/v1/bookings/checkout-stripe/${travelId})

#

Can you share that code?

lunar holly
#

my repo project, or my backend code you mean?

dusty nexus
#

The backend code that makes the API call to Stripe using stripe-node (I assume)

lunar holly
#

any way this my repo project : https://github.com/moezbenrebah/goAheadTravel
and below is my backend code:

exports.getCheckoutStripe = async (req, res, next) => {
  try {
    const travel = await Travel.findById(req.params.travelId);

    if (!travel) {
      return next(new ErrHandlingClass('No Travel exist with this name', 404));
    }

    // 2) Create checkout session
    const session = await stripe.checkout.sessions.create({
      // Information about the checkout session
      payment_method_types: ['card'],
      success_url: `${req.protocol}://${req.get('host')}`,
      cancel_url: `${req.protocol}://${req.get('host')}/travel/${travel.slug}`,
      customer_email: req.user.email,
      client_reference_id: req.params.travelId,

      // Information about the travel
      line_items: [
        {
          name: `${travel.name} Travel`,
          description: travel.summary,
          images: [`https://www.goaheadtravel.dev/img/tours/${travel.imageCover}`],
          amount: travel.price * 100, // the amount is expected to be in cent 1.00$
          currency: 'usd',
          quantity: 1
        }
      ]
    });

    // 3) Create session as response
    res.status(200).json({
      status: 'success',
      session
    });
  } catch (error) {
    console.log(error)
  }    //next();
}
GitHub

A travel booking web application build with Node.js, Express.js, MongoDB, JavaScript, PUG, CSS - GitHub - moezbenrebah/goAheadTravel: A travel booking web application build with Node.js, Express.js...

dusty nexus
lunar holly
#

I thought that was correct, please checkout my stripe checkout response:

dusty nexus
#

Looks like you're using the line_items shape from redirectToCheckout

lunar holly
dusty nexus
#

I can't read that. Can you share your Stripe account ID? (acct_xxx)

lunar holly
#

ok, one second please

#

sorry I didn't figure out from where I can grub my stripe account id

dusty nexus
lunar holly
#

acct_1IsimKHX7QKTmOPq

#

sorry it's my first my to deal with stripe

dusty nexus
#

Is this definitely the account you're using to make these API calls? There's no logs for API activity

lunar holly
#

acct_1KOktUA1H3VpG3Rz

#

ah sorry I created a new profile in my account for the app dev purposes

#

the second id is from my new account

dusty nexus
dusty nexus
#

Are you able to log the session variable in your client-side JS?

lunar holly
#

from checkout stripe response you mean?

dusty nexus
#

From your axios call

lunar holly
#

no still 500 error

#

this is the same url that I used to create the session

keen wind
#

500 doesn't tell us anything

#

what are the logs on your serverside?

#

i.e. presumably you run your server with something like npm start or similiar, in a terminal window, what logs are emitted to that terminal? If you're not seeing anything, you should add console.log lines throughout your getCheckoutStripe function and see which ones are printed so you can debug where the code might be crashing.

lunar holly
#

my server error is:

ErrHandlingClass [Error]: Can't find /bundle.js.map on this server!
    at /home/moez/Desktop/Go_ahead_travel/app.js:89:8
    at Layer.handle [as handle_request] (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:137:13)
    at next (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:131:14)
    at next (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:131:14)
    at next (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:131:14)
    at next (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:131:14)
    at next (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:131:14)
    at next (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:131:14)
    at Route.dispatch (/home/moez/Desktop/Go_ahead_travel/node_modules/express/lib/router/route.js:112:3) {
  statusCode: 404,
  status: 'fail',
  isOperational: true
}
GET /bundle.js.map 404 148.215 ms - 1409
GET /api/v1/bookings/checkout-stripe/$%7BtravelId%7D 500 77.249 ms - 802
#

I used npm start to run this script:
"start": "NODE_ENV=development nodemon server.js"

median halo
#

Your problem is in this line:

const session = await axios('http://127.0.0.1:3000/api/v1/bookings/checkout-stripe/${travelId}')
#

You are trying to use template strings but used regular string syntax '' rather than template strings:

const session = await axios(`http://127.0.0.1:3000/api/v1/bookings/checkout-stripe/${travelId}`)
lunar holly
#

you're right paul but now the process is like pending

median halo
#

You'll need to debug this further. I recommend adding console.log's in your code as @keen wind suggested. Check that the route is being hit correctly and that the returned session is what you're actually expecting