From 6a3ae748c5404dfc286ee588eb705b3b682ef759 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 +++++++++++++++++++
.../components/modal-disconnect-stripe.hbs | 13 +++++++
.../app/components/modal-disconnect-stripe.js | 24 +++++++++++++
4 files changed, 93 insertions(+), 2 deletions(-)
create mode 100644 ghost/admin/app/components/modal-disconnect-stripe.hbs
create mode 100644 ghost/admin/app/components/modal-disconnect-stripe.js
diff --git a/ghost/admin/app/components/gh-members-lab-setting.hbs b/ghost/admin/app/components/gh-members-lab-setting.hbs
index e53d6cb639..b948f123a8 100644
--- a/ghost/admin/app/components/gh-members-lab-setting.hbs
+++ b/ghost/admin/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.membersStripeOpen "Close" "Expand"}}
+ {{#if this.stripeConnectIntegration}}
+ Disconnect
+ {{else}}
+ {{if this.membersStripeOpen "Close" "Expand"}}
+ {{/if}}
@@ -368,6 +377,16 @@
{{/unless}}
+{{#if this.showDisconnectStripeConnectModal}}
+
+{{/if}}
+
{{#if this.showMembersModalSettings}}
-{{/if}}
\ No newline at end of file
+{{/if}}
diff --git a/ghost/admin/app/components/gh-members-lab-setting.js b/ghost/admin/app/components/gh-members-lab-setting.js
index c54028fe2a..134a95557f 100644
--- a/ghost/admin/app/components/gh-members-lab-setting.js
+++ b/ghost/admin/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/ghost/admin/app/components/modal-disconnect-stripe.hbs b/ghost/admin/app/components/modal-disconnect-stripe.hbs
new file mode 100644
index 0000000000..f1a368db71
--- /dev/null
+++ b/ghost/admin/app/components/modal-disconnect-stripe.hbs
@@ -0,0 +1,13 @@
+
+{{svg-jar "close"}}Close
+
+
+ You're about to disconnect your Stripe account ({{this.stripeConnectIntegration.name}}) from this site. This will automatically turn off paid memberships on this site.
+
+
+
diff --git a/ghost/admin/app/components/modal-disconnect-stripe.js b/ghost/admin/app/components/modal-disconnect-stripe.js
new file mode 100644
index 0000000000..4a886a527d
--- /dev/null
+++ b/ghost/admin/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()
+});