@malga-checkout/core
Version:
Core components for Malga Checkout
65 lines (64 loc) • 3.43 kB
JavaScript
import { Component, Host, h, Event } from '@stencil/core';
import settings from '../../stores/settings';
import payment from '../../stores/payment';
import dialog from '../../stores/dialog';
import { MalgaPaymentsPixService } from './malga-payments-pix.service';
export class MalgaPaymentsPix {
constructor() {
this.handleShowDialog = (dialogData) => {
dialog.configs = Object.assign(Object.assign({}, dialog.configs), dialogData);
};
this.checkIfPixIsPaid = async () => {
if (settings.sessionId)
return;
const pixService = new MalgaPaymentsPixService({
data: settings.paymentMethods.pix,
onShowDialog: this.handleShowDialog,
onPaymentFailed: (error) => this.pixPaymentFailed.emit({ error }),
});
await pixService.findCharge(payment.chargeId);
};
this.handleErrorModalButtonClicked = () => {
this.handleShowDialog({ open: false });
};
this.handleSuccessModalButtonClicked = () => {
if (settings.dialogConfig.successRedirectUrl) {
location.assign(settings.dialogConfig.successRedirectUrl);
}
this.handleShowDialog({ open: false });
};
}
render() {
return (h(Host, null,
h("checkout-manual-payment", { fullWidth: true, locale: settings.locale, paymentMethod: "pix" }),
settings.dialogConfig.show && dialog.configs.open && (h("checkout-modal", { locale: settings.locale, isSession: !!settings.sessionId, hasSuccessRedirectUrl: !!settings.dialogConfig.successRedirectUrl, currency: settings.transactionConfig.currency, mode: dialog.configs.mode, open: dialog.configs.open, amount: dialog.configs.amount, paymentCode: dialog.configs.paymentCode, paymentImageUrl: dialog.configs.paymentImageUrl, expirationDate: dialog.configs.expirationDate, expirationTime: dialog.configs.expirationTime, errorTitle: dialog.configs.errorTitle, errorDescription: dialog.configs.errorMessage, successDescription: dialog.configs.successMessage, actionButtonLabel: settings.dialogConfig.actionButtonLabel, pixImportantMessages: settings.dialogConfig.pixImportantMessages, pixWaitingPaymentMessage: settings.dialogConfig.pixWaitingPaymentMessage, pixFilledProgressBarColor: settings.dialogConfig.pixFilledProgressBarColor, pixEmptyProgressBarColor: settings.dialogConfig.pixEmptyProgressBarColor, successActionButtonLabel: settings.dialogConfig.successActionButtonLabel, errorActionButtonLabel: settings.dialogConfig.errorActionButtonLabel, onPixCountdownIsFinished: this.checkIfPixIsPaid, onSuccessButtonClicked: this.handleSuccessModalButtonClicked, onErrorButtonClicked: this.handleErrorModalButtonClicked }))));
}
static get is() { return "malga-payments-pix"; }
static get originalStyleUrls() { return {
"$": ["malga-payments-pix.scss"]
}; }
static get styleUrls() { return {
"$": ["malga-payments-pix.css"]
}; }
static get events() { return [{
"method": "pixPaymentFailed",
"name": "pixPaymentFailed",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "{\n error: MalgaPaymentsError\n }",
"resolved": "{ error: MalgaPaymentsError; }",
"references": {
"MalgaPaymentsError": {
"location": "import",
"path": "../../types/malga-payments-error.types"
}
}
}
}]; }
}