2019-10-09 13:02:56 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
feature: service(),
|
|
|
|
config: service(),
|
|
|
|
mediaQueries: service(),
|
|
|
|
|
2019-11-07 13:46:02 +03:00
|
|
|
blogDomain: computed('config.blogDomain', function () {
|
|
|
|
let domain = this.config.blogDomain || '';
|
|
|
|
const host = domain.replace('https://', '').replace('http://', '').split('/');
|
|
|
|
return (host && host[0]) || '';
|
|
|
|
}),
|
|
|
|
|
2019-10-09 13:02:56 +03:00
|
|
|
subscriptionSettings: computed('settings.membersSubscriptionSettings', function () {
|
|
|
|
let subscriptionSettings = this.parseSubscriptionSettings(this.get('settings.membersSubscriptionSettings'));
|
|
|
|
let stripeProcessor = subscriptionSettings.paymentProcessors.find((proc) => {
|
|
|
|
return (proc.adapter === 'stripe');
|
|
|
|
});
|
|
|
|
let monthlyPlan = stripeProcessor.config.plans.find(plan => plan.interval === 'month');
|
|
|
|
let yearlyPlan = stripeProcessor.config.plans.find(plan => plan.interval === 'year');
|
|
|
|
monthlyPlan.dollarAmount = parseInt(monthlyPlan.amount) ? (monthlyPlan.amount / 100) : 0;
|
|
|
|
yearlyPlan.dollarAmount = parseInt(yearlyPlan.amount) ? (yearlyPlan.amount / 100) : 0;
|
|
|
|
stripeProcessor.config.plans = {
|
|
|
|
monthly: monthlyPlan,
|
|
|
|
yearly: yearlyPlan
|
|
|
|
};
|
|
|
|
subscriptionSettings.stripeConfig = stripeProcessor.config;
|
2019-10-11 11:34:39 +03:00
|
|
|
subscriptionSettings.allowSelfSignup = !!subscriptionSettings.allowSelfSignup;
|
2019-10-21 10:10:42 +03:00
|
|
|
subscriptionSettings.fromAddress = subscriptionSettings.fromAddress || '';
|
2019-10-11 11:20:30 +03:00
|
|
|
|
2019-10-09 13:02:56 +03:00
|
|
|
return subscriptionSettings;
|
|
|
|
}),
|
|
|
|
|
2019-11-13 07:01:31 +03:00
|
|
|
bulkEmailSettings: computed('settings.bulkEmailSettings', function () {
|
|
|
|
let bulkEmailSettings = this.get('settings.bulkEmailSettings') || {};
|
|
|
|
const {apiKey = '', baseUrl = '', domain = ''} = bulkEmailSettings;
|
|
|
|
return {apiKey, baseUrl, domain};
|
|
|
|
}),
|
|
|
|
|
|
|
|
hasBulkEmailConfig: computed('settings.bulkEmailSettings', function () {
|
|
|
|
let bulkEmailSettings = this.get('settings.bulkEmailSettings');
|
|
|
|
return !!bulkEmailSettings.isConfig;
|
2019-11-05 14:23:08 +03:00
|
|
|
}),
|
|
|
|
|
2019-10-09 13:02:56 +03:00
|
|
|
defaultContentVisibility: computed('settings.defaultContentVisibility', function () {
|
|
|
|
return this.get('settings.defaultContentVisibility');
|
|
|
|
}),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
setDefaultContentVisibility(value) {
|
|
|
|
this.setDefaultContentVisibility(value);
|
|
|
|
},
|
2019-11-13 07:01:31 +03:00
|
|
|
setBulkEmailSettings(key, event) {
|
|
|
|
let bulkEmailSettings = this.get('settings.bulkEmailSettings') || {};
|
|
|
|
bulkEmailSettings[key] = event.target.value;
|
|
|
|
this.setBulkEmailSettings(bulkEmailSettings);
|
|
|
|
},
|
2019-10-09 13:02:56 +03:00
|
|
|
setSubscriptionSettings(key, event) {
|
|
|
|
let subscriptionSettings = this.parseSubscriptionSettings(this.get('settings.membersSubscriptionSettings'));
|
|
|
|
let stripeProcessor = subscriptionSettings.paymentProcessors.find((proc) => {
|
|
|
|
return (proc.adapter === 'stripe');
|
|
|
|
});
|
|
|
|
let stripeConfig = stripeProcessor.config;
|
|
|
|
stripeConfig.product = {
|
|
|
|
name: this.settings.get('title')
|
|
|
|
};
|
|
|
|
// TODO: this flag has to be removed as it doesn't serve any purpose
|
|
|
|
if (key === 'isPaid') {
|
|
|
|
subscriptionSettings.isPaid = event;
|
|
|
|
}
|
|
|
|
if (key === 'secret_token' || key === 'public_token') {
|
|
|
|
stripeConfig[key] = event.target.value;
|
|
|
|
}
|
|
|
|
if (key === 'month' || key === 'year') {
|
|
|
|
stripeConfig.plans = stripeConfig.plans.map((plan) => {
|
|
|
|
if (key === plan.interval) {
|
|
|
|
plan.amount = parseInt(event.target.value) ? (event.target.value * 100) : 0;
|
|
|
|
}
|
|
|
|
return plan;
|
|
|
|
});
|
|
|
|
}
|
2019-10-11 11:34:39 +03:00
|
|
|
if (key === 'allowSelfSignup') {
|
|
|
|
subscriptionSettings.allowSelfSignup = !subscriptionSettings.allowSelfSignup;
|
2019-10-09 13:02:56 +03:00
|
|
|
}
|
|
|
|
if (key === 'fromAddress') {
|
|
|
|
subscriptionSettings.fromAddress = event.target.value;
|
|
|
|
}
|
|
|
|
this.setMembersSubscriptionSettings(subscriptionSettings);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
parseSubscriptionSettings(settingsString) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(settingsString);
|
|
|
|
} catch (e) {
|
|
|
|
return {
|
|
|
|
isPaid: false,
|
2019-10-11 11:34:39 +03:00
|
|
|
allowSelfSignup: true,
|
2019-10-09 13:02:56 +03:00
|
|
|
fromAddress: 'noreply',
|
|
|
|
paymentProcessors: [{
|
|
|
|
adapter: 'stripe',
|
|
|
|
config: {
|
|
|
|
secret_token: '',
|
|
|
|
public_token: '',
|
|
|
|
product: {
|
|
|
|
name: this.settings.get('title')
|
|
|
|
},
|
|
|
|
plans: [
|
|
|
|
{
|
|
|
|
name: 'Monthly',
|
|
|
|
currency: 'usd',
|
|
|
|
interval: 'month',
|
|
|
|
amount: ''
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Yearly',
|
|
|
|
currency: 'usd',
|
|
|
|
interval: 'year',
|
|
|
|
amount: ''
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|