@malga-checkout/core
Version:
Core components for Malga Checkout
44 lines (43 loc) • 1.92 kB
JavaScript
import { Sessions } from '../../services/sessions';
import settings from '../../stores/settings';
import { setThemeBackgroundColor, setThemeErrorColors, setThemePrimaryColors, setThemeSuccessColors, setThemeWarningColors, } from './malga-payments-session.utils';
import { t } from '@malga-checkout/i18n';
export class MalgaPaymentsSessionService {
constructor({ onShowDialog }) {
this.session = new Sessions();
this.onShowDialog = onShowDialog;
}
handleFailed() {
if (settings.dialogConfig.show) {
this.onShowDialog({
open: true,
mode: 'error',
errorMessage: t('dialogs.session.errorMessage', settings.locale),
});
}
}
async findSession(sessionId) {
var _a, _b;
settings.hiddenPoweredByMalga = false;
try {
const session = await this.session.find(sessionId);
settings.merchantId = session.merchantId;
settings.transactionConfig = Object.assign(Object.assign({}, settings.transactionConfig), session.transactionConfig);
settings.dialogConfig = Object.assign(Object.assign({}, settings.dialogConfig), { pixFilledProgressBarColor: session.customization.primaryColor.medium, pixEmptyProgressBarColor: session.customization.primaryColor.lightest });
settings.paymentMethods = session.checkoutPaymentMethods;
settings.hiddenPoweredByMalga = (_b = (_a = session.settings) === null || _a === void 0 ? void 0 : _a.hiddenPoweredByMalga) !== null && _b !== void 0 ? _b : false;
this.customize(session.customization);
return session;
}
catch (error) {
this.handleFailed();
}
}
customize(customization) {
setThemePrimaryColors(customization.primaryColor);
setThemeWarningColors(customization.warningColor);
setThemeErrorColors(customization.errorColor);
setThemeSuccessColors(customization.successColor);
setThemeBackgroundColor(customization.backgroundColor);
}
}