From 93720eae9715eb10183ff549d5ef3b3bf6d2e3a4 Mon Sep 17 00:00:00 2001 From: Fabien 'egg' O'Carroll Date: Tue, 23 Jun 2020 13:29:12 +0200 Subject: [PATCH] Disconnect Stripe Connect integration (#1613) no-issue Co-authored-by: Peter Zimon This adds the ability to disconnect the Stripe Connect integration from the Members settings. --- app/components/gh-members-lab-setting.hbs | 23 ++++++++++++-- app/components/gh-members-lab-setting.js | 35 ++++++++++++++++++++++ app/components/modal-disconnect-stripe.hbs | 13 ++++++++ app/components/modal-disconnect-stripe.js | 24 +++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 app/components/modal-disconnect-stripe.hbs create mode 100644 app/components/modal-disconnect-stripe.js diff --git a/app/components/gh-members-lab-setting.hbs b/app/components/gh-members-lab-setting.hbs index e53d6cb63..b948f123a 100644 --- a/app/components/gh-members-lab-setting.hbs +++ b/app/components/gh-members-lab-setting.hbs @@ -67,12 +67,21 @@ Test mode {{/unless}}

+ {{#if this.hasActiveStripeSubscriptions}} +

+ Cannot disconnect while there are members with active Stripe subscriptions. +

+ {{/if}} {{else}}

Connect to Stripe to create subscriptions and take payments

{{/if}}
- + {{#if this.stripeConnectIntegration}} + + {{else}} + + {{/if}}
@@ -368,6 +377,16 @@ {{/unless}} +{{#if this.showDisconnectStripeConnectModal}} + +{{/if}} + {{#if this.showMembersModalSettings}} -{{/if}} \ No newline at end of file +{{/if}} diff --git a/app/components/gh-members-lab-setting.js b/app/components/gh-members-lab-setting.js index c54028fe2..134a95557 100644 --- a/app/components/gh-members-lab-setting.js +++ b/app/components/gh-members-lab-setting.js @@ -222,9 +222,44 @@ export default Component.extend({ setStripeConnectIntegrationToken(key, event) { this.setStripeConnectIntegrationTokenSetting(event.target.value); + }, + + openDisconnectStripeModal() { + this.openDisconnectStripeConnectModal.perform(); + }, + + closeDisconnectStripeModal() { + this.set('showDisconnectStripeConnectModal', false); + }, + + disconnectStripeConnectIntegration() { + this.disconnectStripeConnectIntegration.perform(); } }, + openDisconnectStripeConnectModal: task(function* () { + this.set('hasActiveStripeSubscriptions', false); + if (!this.get('stripeConnectIntegration')) { + return; + } + const url = this.get('ghostPaths.url').api('/members/hasActiveStripeSubscriptions'); + const response = yield this.ajax.request(url); + + if (response.hasActiveStripeSubscriptions) { + this.set('hasActiveStripeSubscriptions', true); + return; + } + this.set('showDisconnectStripeConnectModal', true); + }).drop(), + + disconnectStripeConnectIntegration: task(function* () { + this.set('disconnectStripeError', false); + const url = this.get('ghostPaths.url').api('/settings/stripe/connect'); + + yield this.ajax.delete(url); + yield this.settings.reload(); + }), + saveStripeSettings: task(function* () { this.set('stripeConnectError', null); this.set('stripeConnectSuccess', null); diff --git a/app/components/modal-disconnect-stripe.hbs b/app/components/modal-disconnect-stripe.hbs new file mode 100644 index 000000000..f1a368db7 --- /dev/null +++ b/app/components/modal-disconnect-stripe.hbs @@ -0,0 +1,13 @@ + +{{svg-jar "close"}} + + + + diff --git a/app/components/modal-disconnect-stripe.js b/app/components/modal-disconnect-stripe.js new file mode 100644 index 000000000..4a886a527 --- /dev/null +++ b/app/components/modal-disconnect-stripe.js @@ -0,0 +1,24 @@ +import ModalComponent from 'ghost-admin/components/modal-base'; +import {alias} from '@ember/object/computed'; +import {task} from 'ember-concurrency'; + +export default ModalComponent.extend({ + // Allowed actions + confirm: () => {}, + + stripeConnectIntegration: alias('model.stripeConnectIntegration'), + + actions: { + confirm() { + this.disconnectStripe.perform(); + } + }, + + disconnectStripe: task(function* () { + try { + yield this.confirm(); + } finally { + this.send('closeModal'); + } + }).drop() +});