From d2878483930b711e9ccef02283d3db222287dae2 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 3 Feb 2021 16:45:09 +0000 Subject: [PATCH] Fixed unsaveable Stripe direct keys in launch-site wizard refs https://github.com/TryGhost/Team/issues/460 - fixed mismatches in property naming for key fields - updated error handling to show errors for missing and invalid stripe keys --- .../gh-launch-wizard/connect-stripe.hbs | 6 +- .../gh-launch-wizard/connect-stripe.js | 55 ++++++++++++++----- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs index 25b888208b..2a5a43043c 100644 --- a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs +++ b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.hbs @@ -19,20 +19,22 @@ + {{#if this.stripePublishableKeyError}}

{{this.stripePublishableKeyError}}

{{/if}}
+ {{#if this.stripeSecretKeyError}}

{{this.stripeSecretKeyError}}

{{/if}} Find your Stripe API keys here » diff --git a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js index ed2a2b9b90..9472a72486 100644 --- a/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js +++ b/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js @@ -12,6 +12,8 @@ export default class GhLaunchWizardConnectStripeComponent extends Component { @tracked stripeConnectTestMode = false; @tracked stripeConnectError = null; + @tracked stripePublishableKeyError = null; + @tracked stripeSecretKeyError = null; get stripeConnectAuthUrl() { const mode = this.stripeConnectTestMode ? 'test' : 'live'; @@ -32,12 +34,14 @@ export default class GhLaunchWizardConnectStripeComponent extends Component { setStripeDirectPublicKey(event) { this.settings.set('stripeProductName', this.settings.get('title')); this.settings.set('stripePublishableKey', event.target.value); + this.stripePublishableKeyError = null; } @action setStripeDirectSecretKey(event) { this.settings.set('stripeProductName', this.settings.get('title')); - this.settings.set('stripePublishableKey', event.target.value); + this.settings.set('stripeSecretKey', event.target.value); + this.stripeSecretKeyError = null; } @action @@ -54,23 +58,46 @@ export default class GhLaunchWizardConnectStripeComponent extends Component { @task *saveAndContinue() { - if (this.settings.get('stripeConnectIntegrationToken')) { - try { - yield this.settings.save(); - this.pauseAndContinue.perform(); - return true; - } catch (error) { - if (error.payload?.errors) { - this.stripeConnectError = 'Invalid secure key'; - return false; - } - - throw error; + if (this.config.get('stripeDirect')) { + if (!this.settings.get('stripePublishableKey')) { + this.stripePublishableKeyError = 'Enter your publishable key to continue'; } - } else { + + if (!this.settings.get('stripeSecretKey')) { + this.stripeSecretKeyError = 'Enter your secret key to continue'; + } + + if (this.stripePublishableKeyError || this.stripeSecretKeyError) { + return false; + } + } else if (!this.settings.get('stripeConnectIntegrationToken')) { this.stripeConnectError = 'Paste your secure key to continue'; return false; } + + try { + yield this.settings.save(); + this.pauseAndContinue.perform(); + return true; + } catch (error) { + if (error.payload?.errors && error.payload.errors[0].type === 'ValidationError') { + const [validationError] = error.payload.errors; + + if (this.config.get('stripeDirect')) { + if (validationError.context.match(/stripe_publishable_key/)) { + this.stripePublishableKeyError = 'Invalid publishable key'; + } else { + this.stripeSecretKeyError = 'Invalid secret key'; + } + } else { + this.stripeConnectError = 'Invalid secure key'; + } + + return false; + } + + throw error; + } } @task