2020-06-11 12:05:40 +03:00
|
|
|
import Service from '@ember/service';
|
|
|
|
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;
|
2021-06-29 09:49:20 +03:00
|
|
|
@service feature;
|
2020-06-11 12:05:40 +03:00
|
|
|
|
2021-05-21 20:22:01 +03:00
|
|
|
get isMembersEnabled() {
|
|
|
|
return this.settings.get('membersSignupAccess') !== 'none';
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-05-18 15:59:47 +03:00
|
|
|
// Button / Icon helpers ---------------------------------------------------
|
|
|
|
|
|
|
|
get defaultButtonIcons() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
icon: 'portal-icon-1',
|
|
|
|
value: 'icon-1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'portal-icon-2',
|
|
|
|
value: 'icon-2'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'portal-icon-3',
|
|
|
|
value: 'icon-3'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'portal-icon-4',
|
|
|
|
value: 'icon-4'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'portal-icon-5',
|
|
|
|
value: 'icon-5'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
get defaultIconKeys() {
|
|
|
|
return this.defaultButtonIcons.map(buttonIcon => buttonIcon.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
get buttonIcon() {
|
|
|
|
return this.settings.get('portalButtonIcon') || this.defaultIconKeys[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plan helpers ------------------------------------------------------------
|
|
|
|
|
|
|
|
get isFreeChecked() {
|
|
|
|
const allowedPlans = this.settings.get('portalPlans') || [];
|
|
|
|
return !!(this.settings.get('membersSignupAccess') === 'all' && allowedPlans.includes('free'));
|
|
|
|
}
|
|
|
|
|
|
|
|
get isMonthlyChecked() {
|
|
|
|
const allowedPlans = this.settings.get('portalPlans') || [];
|
|
|
|
return !!(this.isStripeConfigured && allowedPlans.includes('monthly'));
|
|
|
|
}
|
|
|
|
|
|
|
|
get isYearlyChecked() {
|
|
|
|
const allowedPlans = this.settings.get('portalPlans') || [];
|
|
|
|
return !!(this.isStripeConfigured && allowedPlans.includes('yearly'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Portal preview ----------------------------------------------------------
|
|
|
|
|
|
|
|
getPortalPreviewUrl(overrides) {
|
|
|
|
const {
|
|
|
|
disableBackground = false,
|
2021-01-28 21:41:03 +03:00
|
|
|
page = 'signup',
|
2021-05-18 16:34:46 +03:00
|
|
|
button = this.settings.get('portalButton'),
|
2021-05-18 15:59:47 +03:00
|
|
|
buttonIcon = this.buttonIcon,
|
|
|
|
isFreeChecked = this.isFreeChecked,
|
|
|
|
isMonthlyChecked = this.isMonthlyChecked,
|
|
|
|
isYearlyChecked = this.isYearlyChecked,
|
2021-01-28 21:41:03 +03:00
|
|
|
monthlyPrice,
|
|
|
|
yearlyPrice,
|
2021-05-18 15:59:47 +03:00
|
|
|
portalPlans = this.settings.get('portalPlans'),
|
2021-06-21 11:51:48 +03:00
|
|
|
portalProducts = this.settings.get('portalProducts'),
|
2021-05-18 15:59:47 +03:00
|
|
|
currency,
|
|
|
|
membersSignupAccess = this.settings.get('membersSignupAccess')
|
|
|
|
} = overrides;
|
2021-01-28 21:41:03 +03:00
|
|
|
|
|
|
|
const baseUrl = this.config.get('blogUrl');
|
|
|
|
const portalBase = '/#/portal/preview';
|
|
|
|
const settingsParam = new URLSearchParams();
|
|
|
|
const signupButtonText = this.settings.get('portalButtonSignupText') || '';
|
2021-05-18 15:59:47 +03:00
|
|
|
const allowSelfSignup = membersSignupAccess === 'all' && (!this.isStripeEnabled || isFreeChecked);
|
2021-01-28 21:41:03 +03:00
|
|
|
|
2021-05-18 16:34:46 +03:00
|
|
|
settingsParam.append('button', button);
|
2021-01-28 21:41:03 +03:00
|
|
|
settingsParam.append('name', this.settings.get('portalName'));
|
2021-02-10 21:40:27 +03:00
|
|
|
settingsParam.append('isFree', isFreeChecked);
|
|
|
|
settingsParam.append('isMonthly', isMonthlyChecked);
|
|
|
|
settingsParam.append('isYearly', isYearlyChecked);
|
2021-01-28 21:41:03 +03:00
|
|
|
settingsParam.append('page', page);
|
|
|
|
settingsParam.append('buttonIcon', encodeURIComponent(buttonIcon));
|
|
|
|
settingsParam.append('signupButtonText', encodeURIComponent(signupButtonText));
|
2021-05-18 15:59:47 +03:00
|
|
|
settingsParam.append('membersSignupAccess', membersSignupAccess);
|
2021-04-27 20:35:05 +03:00
|
|
|
settingsParam.append('allowSelfSignup', allowSelfSignup);
|
2021-01-28 21:41:03 +03:00
|
|
|
|
2021-05-04 18:43:31 +03:00
|
|
|
if (portalPlans) {
|
|
|
|
settingsParam.append('portalPrices', encodeURIComponent(portalPlans));
|
|
|
|
}
|
|
|
|
|
2021-06-29 09:49:20 +03:00
|
|
|
if (portalProducts && this.feature.get('multipleProducts')) {
|
2021-06-21 11:51:48 +03:00
|
|
|
settingsParam.append('portalProducts', encodeURIComponent(portalProducts));
|
|
|
|
}
|
|
|
|
|
2021-01-28 21:41:03 +03:00
|
|
|
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()}`;
|
|
|
|
}
|
2021-10-18 12:01:29 +03:00
|
|
|
|
|
|
|
getOfferPortalPreviewUrl(overrides) {
|
|
|
|
const {
|
|
|
|
disableBackground = false,
|
|
|
|
name,
|
|
|
|
code,
|
2021-10-19 10:38:31 +03:00
|
|
|
displayTitle = 'Display title',
|
|
|
|
displayDescription = '',
|
2021-10-18 12:01:29 +03:00
|
|
|
type,
|
|
|
|
cadence,
|
|
|
|
amount = 0,
|
|
|
|
duration,
|
|
|
|
durationInMonths,
|
|
|
|
currency = 'usd',
|
|
|
|
status,
|
|
|
|
tierId
|
|
|
|
} = overrides;
|
|
|
|
|
|
|
|
const baseUrl = this.config.get('blogUrl');
|
|
|
|
const portalBase = '/#/portal/preview/offer';
|
|
|
|
const settingsParam = new URLSearchParams();
|
|
|
|
|
|
|
|
settingsParam.append('name', encodeURIComponent(name));
|
|
|
|
settingsParam.append('code', encodeURIComponent(code));
|
|
|
|
settingsParam.append('display_title', encodeURIComponent(displayTitle));
|
|
|
|
settingsParam.append('display_description', encodeURIComponent(displayDescription));
|
|
|
|
settingsParam.append('type', encodeURIComponent(type));
|
|
|
|
settingsParam.append('cadence', encodeURIComponent(cadence));
|
|
|
|
settingsParam.append('amount', encodeURIComponent(amount));
|
|
|
|
settingsParam.append('duration', encodeURIComponent(duration));
|
|
|
|
settingsParam.append('duration_in_months', encodeURIComponent(durationInMonths));
|
|
|
|
settingsParam.append('currency', encodeURIComponent(currency));
|
|
|
|
settingsParam.append('status', encodeURIComponent(status));
|
|
|
|
settingsParam.append('tier_id', encodeURIComponent(tierId));
|
|
|
|
|
|
|
|
if (disableBackground) {
|
|
|
|
settingsParam.append('disableBackground', 'true');
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${baseUrl}${portalBase}?${settingsParam.toString()}`;
|
|
|
|
}
|
2020-06-11 12:05:40 +03:00
|
|
|
}
|