#Empress Brosephine
1 messages · Page 1 of 1 (latest)
Hi 👋 normally when calling our endpoints, you don't need to respond to the response that you receive.
I'm not familiar with the test that you're referring to and won't be able to give guidance on that.
Hey Toby
Does it look alright otherwise before I reach out to the Stripe Rep saying its broken? I mean, the response has the ID
They tend to not like when we tell them their stuff is broken lol
I'm not sure because I don't know what you believe is broken. The code that you shared doesn't make sense. You're sending a request to our server, getting a response, and then you have your code trying to respond to the response. Are you sure you aren't supposed to be returning the value instead of responding?
What do you mean by responding to the response? It pings Stripes server -> sends the response object back (as indicated by Stripes test), if it catches the error, it sends a error object as stated by Stripe
// Milestone 2: '/schedule-lesson'
// Authorize a payment for a lesson
//
// Parameters:
// customer_id: id of the customer
// amount: amount of the lesson in cents
// description: a description of this lesson
//
// Example call:
// curl -X POST http://localhost:4242/schdeule-lesson \
// -d customer_id=cus_GlY8vzEaWTFmps \
// -d amount=4500 \
// -d description='Lesson on Feb 25th'
//
// {
// Returns: a JSON response of one of the following forms:
// For a successful payment, return the Payment Intent:
// payment: <payment_intent>
// }
//
// For errors:
// {
// error:
// code: the code returned from the Stripe error if there was one
// message: the message returned from the Stripe error. if no payment method was
// found for that customer return an msg 'no payment methods found for <customer_id>'
// payment_intent_id: if a payment intent was created but not successfully authorized
// }
From you guys
try {
const paymentMethods = await stripe.paymentMethods.list({
customer: req.query.customer_id,
type: 'card'
})
const paymentIntent = await stripe.paymentIntents.create({
amount: req.query.amount,
currency: 'usd',
customer: req.query.customer_id,
payment_method: paymentMethods.data[0].id,
description: req.query.description,
confirm: false,
metadata: {
type: 'lessons-payment'
}
})
res.send({
payment: paymentIntent
})
}catch(err){
console.log('Error is: ' + err);
res.send({error: {
code: err.raw.code,
message: err.raw.message
}});
}
If thats easier for you, I refactored it
I don't think I have the full context of your prompt, but based on what you've shared it doesn't look like your code is doing what you're being asked to do. If you believe the assessment though, then I would recommend that you contact the person that you've been working with.
So you wouldn't do:
- Retrieve Payment Method
- Create a PaymentIntent
?
Sorry, but I can't advise more for this type of exam.