Skip to content

Commit

Permalink
Hardened members subscription migration against missing data
Browse files Browse the repository at this point in the history
closes #11993

We had some issues with some databases being in an unexpected state this
check for each property before using it add uses defaults when it is
missing.
  • Loading branch information
allouis committed Jul 6, 2020
1 parent f6f22fc commit 2039abc
Showing 1 changed file with 9 additions and 7 deletions.
Expand Up @@ -49,16 +49,18 @@ module.exports = {

const membersSubscriptionSettings = JSON.parse(membersSubscriptionSettingsJSON.value);

const membersFromAddress = membersSubscriptionSettings.fromAddress;
const membersAllowSelfSignup = membersSubscriptionSettings.allowSelfSignup;
const membersFromAddress = typeof membersSubscriptionSettings.fromAddress === 'string' ? membersSubscriptionSettings.fromAddress : 'noreply';
const membersAllowSelfSignup = typeof membersSubscriptionSettings.allowSelfSignup === 'boolean' ? membersSubscriptionSettings.allowSelfSignup : true;

const stripe = membersSubscriptionSettings.paymentProcessors[0];
const stripe = membersSubscriptionSettings && membersSubscriptionSettings.paymentProcessors && membersSubscriptionSettings.paymentProcessors[0];

const stripeDirectSecretKey = stripe.config.secret_token;
const stripeDirectPublishableKey = stripe.config.public_token;
const stripeProductName = stripe.config.product.name;
const stripeConfig = stripe && stripe.config || {};

const stripePlans = stripe.config.plans.map((plan) => {
const stripeDirectSecretKey = stripeConfig.secret_token || '';
const stripeDirectPublishableKey = stripeConfig.public_token || '';
const stripeProductName = stripeConfig.product && stripeConfig.product.name || 'Ghost Members';

const stripePlans = (stripeConfig.plans || []).map((plan) => {
return Object.assign(plan, {
amount: plan.amount || 0
});
Expand Down

0 comments on commit 2039abc

Please sign in to comment.