diff --git a/api-server/server/boot/donate.js b/api-server/server/boot/donate.js index 18b48ab28d..092adb7c36 100644 --- a/api-server/server/boot/donate.js +++ b/api-server/server/boot/donate.js @@ -3,6 +3,11 @@ import debug from 'debug'; import crypto from 'crypto'; import { isEmail, isNumeric } from 'validator'; +import { + durationKeysConfig, + donationOneTimeConfig, + donationSubscriptionConfig +} from '../../../config/donation-settings'; import keys from '../../../config/secrets'; const log = debug('fcc:boot:donate'); @@ -12,19 +17,6 @@ export default function donateBoot(app, done) { const api = app.loopback.Router(); const donateRouter = app.loopback.Router(); - const durationKeys = ['year', 'month', 'onetime']; - const donationOneTimeConfig = [100000, 25000, 3500]; - const donationSubscriptionConfig = { - duration: { - year: 'Yearly', - month: 'Monthly' - }, - plans: { - year: [100000, 25000, 3500], - month: [5000, 3500, 500] - } - }; - const subscriptionPlans = Object.keys( donationSubscriptionConfig.plans ).reduce( @@ -62,7 +54,7 @@ export default function donateBoot(app, done) { function validStripeForm(amount, duration, email) { return isEmail('' + email) && isNumeric('' + amount) && - durationKeys.includes(duration) && + durationKeysConfig.includes(duration) && duration === 'onetime' ? donationOneTimeConfig.includes(amount) : donationSubscriptionConfig.plans[duration]; diff --git a/client/src/components/Donation/components/DonateForm.js b/client/src/components/Donation/components/DonateForm.js index fad11f1611..5ed59af7de 100644 --- a/client/src/components/Donation/components/DonateForm.js +++ b/client/src/components/Donation/components/DonateForm.js @@ -13,6 +13,12 @@ import { Radio } from '@freecodecamp/react-bootstrap'; import { StripeProvider, Elements } from 'react-stripe-elements'; + +import { + amountsConfig, + durationsConfig, + defaultStateConfig +} from '../../../../../config/donation-settings'; import { apiLocation } from '../../../../config/env.json'; import Spacer from '../../helpers/Spacer'; import DonateFormChildViewForHOC from './DonateFormChildViewForHOC'; @@ -64,23 +70,13 @@ class DonateForm extends Component { constructor(...args) { super(...args); + this.durations = durationsConfig; + this.amounts = amountsConfig; + this.state = { processing: false, isDonating: this.props.isDonating, - donationAmount: 5000, - donationDuration: 'month', - paymentType: 'Card' - }; - - this.durations = { - year: 'yearly', - month: 'monthly', - onetime: 'one-time' - }; - this.amounts = { - year: [100000, 25000, 3500], - month: [5000, 3500, 500], - onetime: [100000, 25000, 3500] + ...defaultStateConfig }; this.getActiveDonationAmount = this.getActiveDonationAmount.bind(this); diff --git a/config/donation-settings.js b/config/donation-settings.js new file mode 100644 index 0000000000..245c6a8237 --- /dev/null +++ b/config/donation-settings.js @@ -0,0 +1,39 @@ +// Configuration for client side +const durationsConfig = { + year: 'yearly', + month: 'monthly', + onetime: 'one-time' +}; +const amountsConfig = { + year: [100000, 25000, 3500], + month: [5000, 3500, 500], + onetime: [100000, 25000, 3500] +}; +const defaultStateConfig = { + donationAmount: 5000, + donationDuration: 'month', + paymentType: 'Card' +}; + +// Configuration for server side +const durationKeysConfig = ['year', 'month', 'onetime']; +const donationOneTimeConfig = [100000, 25000, 3500]; +const donationSubscriptionConfig = { + duration: { + year: 'Yearly', + month: 'Monthly' + }, + plans: { + year: [100000, 25000, 3500], + month: [5000, 3500, 500] + } +}; + +module.exports = { + durationsConfig, + amountsConfig, + defaultStateConfig, + durationKeysConfig, + donationOneTimeConfig, + donationSubscriptionConfig +};