2020-06-11 12:05:40 +03:00
|
|
|
import Service from '@ember/service';
|
2021-01-28 21:41:03 +03:00
|
|
|
import {ICON_MAPPING} from 'ghost-admin/components/modal-portal-settings';
|
2020-06-11 12:05:40 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class MembersUtilsService extends Service {
|
2020-06-29 20:37:11 +03:00
|
|
|
@service config;
|
2021-01-28 21:41:03 +03:00
|
|
|
@service settings;
|
2020-06-11 12:05:40 +03:00
|
|
|
|
2020-06-11 15:46:04 +03:00
|
|
|
get isStripeEnabled() {
|
2020-06-29 20:37:11 +03:00
|
|
|
const stripeDirect = this.config.get('stripeDirect');
|
2020-06-11 17:45:45 +03:00
|
|
|
|
2020-06-29 20:37:11 +03:00
|
|
|
const hasDirectKeys = !!this.settings.get('stripeSecretKey') && !!this.settings.get('stripePublishableKey');
|
|
|
|
const hasConnectKeys = !!this.settings.get('stripeConnectSecretKey') && !!this.settings.get('stripeConnectPublishableKey');
|
2020-06-11 17:45:45 +03:00
|
|
|
|
2020-06-29 20:37:11 +03:00
|
|
|
if (stripeDirect) {
|
|
|
|
return hasDirectKeys;
|
|
|
|
}
|
2020-06-11 17:45:45 +03:00
|
|
|
|
2020-06-29 20:37:11 +03:00
|
|
|
return hasConnectKeys || hasDirectKeys;
|
2020-06-11 12:05:40 +03:00
|
|
|
}
|
2021-01-28 21:41:03 +03:00
|
|
|
|
|
|
|
getPortalPreviewUrl(args) {
|
|
|
|
let {
|
|
|
|
disableBackground,
|
|
|
|
buttonIcon,
|
|
|
|
page = 'signup',
|
|
|
|
isFree = true,
|
|
|
|
isMonthly = true,
|
|
|
|
isYearly = true,
|
|
|
|
monthlyPrice,
|
|
|
|
yearlyPrice,
|
|
|
|
currency
|
|
|
|
} = args;
|
|
|
|
|
|
|
|
if (!buttonIcon) {
|
|
|
|
const defaultIconKeys = ICON_MAPPING.map(icon => icon.value);
|
|
|
|
buttonIcon = this.settings.get('portalButtonIcon') || defaultIconKeys[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
const baseUrl = this.config.get('blogUrl');
|
|
|
|
const portalBase = '/#/portal/preview';
|
|
|
|
const settingsParam = new URLSearchParams();
|
|
|
|
const signupButtonText = this.settings.get('portalButtonSignupText') || '';
|
|
|
|
|
|
|
|
settingsParam.append('button', this.settings.get('portalButton'));
|
|
|
|
settingsParam.append('name', this.settings.get('portalName'));
|
|
|
|
settingsParam.append('isFree', isFree);
|
|
|
|
settingsParam.append('isMonthly', isMonthly);
|
|
|
|
settingsParam.append('isYearly', isYearly);
|
|
|
|
settingsParam.append('page', page);
|
|
|
|
settingsParam.append('buttonIcon', encodeURIComponent(buttonIcon));
|
|
|
|
settingsParam.append('signupButtonText', encodeURIComponent(signupButtonText));
|
|
|
|
|
|
|
|
if (this.settings.get('accentColor') === '' || this.settings.get('accentColor')) {
|
|
|
|
settingsParam.append('accentColor', encodeURIComponent(`${this.settings.get('accentColor')}`));
|
|
|
|
}
|
|
|
|
if (this.settings.get('portalButtonStyle')) {
|
|
|
|
settingsParam.append('buttonStyle', encodeURIComponent(this.settings.get('portalButtonStyle')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (monthlyPrice) {
|
|
|
|
settingsParam.append('monthlyPrice', monthlyPrice);
|
|
|
|
}
|
|
|
|
if (yearlyPrice) {
|
2021-02-09 11:52:14 +03:00
|
|
|
settingsParam.append('yearlyPrice', yearlyPrice);
|
2021-01-28 21:41:03 +03:00
|
|
|
}
|
|
|
|
if (currency) {
|
|
|
|
settingsParam.append('currency', currency);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disableBackground) {
|
|
|
|
settingsParam.append('disableBackground', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${baseUrl}${portalBase}?${settingsParam.toString()}`;
|
|
|
|
}
|
2020-06-11 12:05:40 +03:00
|
|
|
}
|