Skip to content
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

fix(donate): handle missing stripe keys #37847

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions client/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ exports.createPages = function createPages({ graphql, actions, reporter }) {
);
}
}

if (!env.stripePublicKey || !env.servicebotId) {
if (process.env.FREECODECAMP_NODE_ENV === 'production') {
throw new Error(
'Stripe public key and Servicebot id are required to start the client!'
);
} else {
reporter.info(
'Stripe public key or Servicebot id missing or invalid. Required for' +
' donations.'
);
}
}
const { createPage } = actions;

return new Promise((resolve, reject) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class DonateFormChildViewForHOC extends Component {
this.handleSubmit = this.handleSubmit.bind(this);
this.postDonation = this.postDonation.bind(this);
this.resetDonation = this.resetDonation.bind(this);
this.hideAmountOptions(false);
}

getUserEmail() {
Expand Down Expand Up @@ -226,7 +227,6 @@ class DonateFormChildViewForHOC extends Component {
reset: this.resetDonation
});
}
this.hideAmountOptions(false);
return this.renderDonateForm();
}
}
Expand Down
11 changes: 6 additions & 5 deletions client/src/pages/donate.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ export class DonatePage extends Component {

handleStripeLoad() {
// Create Stripe instance once Stripe.js loads
console.info('stripe has loaded');
this.setState(state => ({
...state,
stripe: window.Stripe(stripePublicKey)
}));
if (stripePublicKey) {
this.setState(state => ({
...state,
stripe: window.Stripe(stripePublicKey)
}));
}
}

enableDonationSettingsPage(enableSettings = true) {
Expand Down
10 changes: 8 additions & 2 deletions config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ const locations = {

module.exports = Object.assign(locations, {
locale,
stripePublicKey,
servicebotId,
stripePublicKey:
!stripePublicKey || stripePublicKey === 'pk_from_stripe_dashboard'
? null
: stripePublicKey,
servicebotId:
!servicebotId || servicebotId === 'servicebot_id_from_servicebot_dashboard'
? null
: servicebotId,
algoliaAppId:
!algoliaAppId || algoliaAppId === 'Algolia app id from dashboard'
? null
Expand Down