mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-28 23:01:57 -04:00
feat: restrict donations via stripe card (#51598)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -217,6 +217,7 @@ export async function createStripeCardDonation(req, res, stripe) {
|
||||
* if user is already donating and the donation isn't one time only,
|
||||
* throw error
|
||||
*/
|
||||
|
||||
if (user.isDonating && duration !== 'one-time') {
|
||||
throw {
|
||||
message: `User already has active recurring donation(s).`,
|
||||
@@ -224,6 +225,18 @@ export async function createStripeCardDonation(req, res, stripe) {
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* card donations is blocked for new users
|
||||
*/
|
||||
|
||||
const threeChallengesCompleted = user.completedChallenges.length >= 3;
|
||||
if (!threeChallengesCompleted) {
|
||||
throw {
|
||||
message: `Donate using another method`,
|
||||
type: 'MethodRestrictionError'
|
||||
};
|
||||
}
|
||||
|
||||
let customerId;
|
||||
try {
|
||||
const customer = await stripe.customers.create({
|
||||
|
||||
Reference in New Issue
Block a user