feat: restrict donations via stripe card (#51598)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Ahmad Abdolsaheb
2023-09-18 19:42:11 +03:00
committed by GitHub
parent 47ad1be0bd
commit 88b36d08b8
3 changed files with 31 additions and 7 deletions

View File

@@ -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({