#moez-checkout
1 messages · Page 1 of 1 (latest)
Hello! What specifically is the issue? Is there anything logged in your catch block?
first the issue I published here, please take a look I pulished my code: https://github.com/stripe/stripe-node/issues/1345
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)
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?
my repo project, or my backend code you mean?
The backend code that makes the API call to Stripe using stripe-node (I assume)
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();
}
Your line_items parameter isn't following the correct API shape: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I thought that was correct, please checkout my stripe checkout response:
Looks like you're using the line_items shape from redirectToCheckout
I can't read that. Can you share your Stripe account ID? (acct_xxx)
ok, one second please
sorry I didn't figure out from where I can grub my stripe account id
Is this definitely the account you're using to make these API calls? There's no logs for API activity
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
Ok, so seemingly your Checkout Sessions are being created successfully: https://dashboard.stripe.com/test/logs/req_kQtKf02mcOaJv6
I'd still address the parameters as you're using old, deprecated parameters (line_items[0].amount, etc).
ok
Are you able to log the session variable in your client-side JS?
from checkout stripe response you mean?
From your axios call
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.
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"
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}`)
you're right paul but now the process is like pending
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