Ghost/ghost/admin/app/components/gh-launch-wizard/connect-stripe.js
Kevin Ansfield 63c1f2060c Added stripe connection to launch site wizard
refs https://github.com/TryGhost/Team/issues/450

- duplicated and refactored/updated direct and connect settings UI from labs to the "connect stripe" step of the launch site wizard
- updated wizard buttons to be right-aligned
2021-01-19 22:31:59 +00:00

68 lines
2.0 KiB
JavaScript

import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
export default class GhLaunchWizardConnectStripeComponent extends Component {
@service config;
@service ghostPaths;
@service settings;
@tracked stripeConnectTestMode = false;
@tracked stripeConnectError = null;
get stripeConnectAuthUrl() {
const mode = this.stripeConnectTestMode ? 'test' : 'live';
return `${this.ghostPaths.url.api('members/stripe_connect')}?mode=${mode}`;
}
willDestroy() {
// clear any unsaved settings changes when going back/forward/closing
this.settings.rollbackAttributes();
}
@action
setStripeDirectPublicKey(event) {
this.settings.set('stripeProductName', this.settings.get('title'));
this.settings.set('stripePublishableKey', event.target.value);
}
@action
setStripeDirectSecretKey(event) {
this.settings.set('stripeProductName', this.settings.get('title'));
this.settings.set('stripePublishableKey', event.target.value);
}
@action
toggleStripeConnectTestMode() {
this.stripeConnectTestMode = !this.stripeConnectTestMode;
}
@action
setStripeConnectIntegrationToken(event) {
this.settings.set('stripeProductName', this.settings.get('title'));
this.settings.set('stripeConnectIntegrationToken', event.target.value);
this.stripeConnectError = null;
}
@task
*saveAndContinue() {
if (this.settings.get('stripeConnectIntegrationToken')) {
try {
yield this.settings.save();
} catch (error) {
if (error.payload?.errors) {
this.stripeConnectError = 'Invalid secure key';
return false;
}
throw error;
}
}
// skip when no token supplied
this.args.afterComplete();
}
}