New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): add charge-stripe endpoint #54545
base: main
Are you sure you want to change the base?
feat(api): add charge-stripe endpoint #54545
Conversation
if (user) req.user = user; | ||
} | ||
} catch { | ||
return send401(reply, TOKEN_INVALID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I need to return an error or not here since we are just checking if user is authorized and pass the user object.
}) | ||
} | ||
} | ||
schema: schemas.addDonation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a clean up.
const { id: customerId } = await stripe.customers.create({ | ||
email, | ||
name | ||
}); | ||
|
||
// TODO(Post-MVP) stripe has moved to a paymentintent flow, the create call should be updated to reflect this | ||
const paymentMethod = await stripe.paymentMethods.attach(token.id, { | ||
customer: customerId | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current api, card has been passed directly when creating the customer. The current api works but the card definition has been removed from the ar types. As a result, I create the customer and then attach the payment method to it.
I will update current api to the new pattern as well.
return reply.send({ | ||
type: 'success', | ||
isDonating: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current api returns the whole subscription, but that is not used in the client.
I returned isDonating for consistency.
if ( | ||
!isEmail(email) || | ||
!donationSubscriptionConfig.plans[duration].includes(amount) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved the validation slightly to check existing for plan.
email, | ||
name | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should figure out if this might benefit from being done before creating the customer.
const { id: paymentMethodId } = await stripe.paymentMethods.create({ | |
type: 'card', | |
card: { token: token.id } | |
}); | |
blocked by #54668 |
Checklist:
Update index.md
)main
branch of freeCodeCamp.Closes #51294