LittleDemon WebShell


Linux hosting5.siteguarding.com 3.10.0-962.3.2.lve1.5.88.el7.x86_64 #1 SMP Fri Sep 26 14:06:42 UTC 2025 x86_64
Path : /home/devsafetybis/verd.dev.safetybis.com/js/brippopaymentsfrontend/method-renderer/
File Upload :
Command :
Current File : /home/devsafetybis/verd.dev.safetybis.com/js/brippopaymentsfrontend/method-renderer/express.js

var BrippoExpress = Class.create();

BrippoExpress.prototype = {
    stripe: null,
    pkey: null,
    elements: null,
    currentTotals: null,
    paymentMethodCode: "brippopayments_express",
    paymentRequest: null,
    config: null,
    isPlaceOrderActionAllowed: false,
    isLoaded: false,

    initialize: function(config) {
        let self = this;
        this.config = config;

        if (config === null) {
            return;
        }

        if (typeof BrippoExpressCheckout === 'undefined') {
            let listener = function() {
                self.onLoad();
                window.removeEventListener('BrippoExpressCheckoutLoaded', listener);
            };
            window.addEventListener('BrippoExpressCheckoutLoaded', listener);
        } else {
            self.onLoad();
        }

        window.addEventListener('BrippoExpressMethodRendered', self.methodRendered.bind(this));
        window.addEventListener('BrippoExpressUpdatePaymentRequest', self.onRenderedHandler.bind(this));

        window.addEventListener('BrippoExpressPlaceOrder', () => {
            self.placeOrder();
        });
    },

    onLoad: function() {
        let self = this;

        if (BrippoExpressCheckout.prototype.isOSC()) {
            document.addEventListener('click', function(event) {
                let targetElement = event.target;

                if (targetElement.id === 'p_method_brippopayments_express') {
                    if (self.methodLogo() != "") {
                        self.methodRendered();
                    }
                }
            });
            const isElementLoaded = async selector => {
                while ( document.querySelector(selector) === null) {
                    await new Promise( resolve =>  requestAnimationFrame(resolve) )
                }
                return document.querySelector(selector);
            };

            isElementLoaded('#p_method_brippopayments_express').then((selector) => {
                if (self.methodLogo() != "") {
                    self.methodRendered();
                }
            });
        } else {
            Review.prototype.save = Review.prototype.save.wrap(
                function(originalMethod) {
                    if (payment.currentMethod !== self.paymentMethodCode) {
                        return originalMethod();
                    } else {
                        self.placeOrder();
                    }
                }
            );
        }
        this.onRenderedHandler();
        BrippoExpress.prototype.isLoaded = true;
    },

    dispatchOnLoadEvent:function() {
        window.dispatchEvent(new Event('BrippoExpressLoaded'));
    },

    placeOrder: function() {
        let self = this;

        if (!this.validate()) {
            console.log("place order validate error, exit.");
            return false;
        }

        if (this.isPlaceOrderActionAllowed !== true) {
            alert(Translator.translate("Couldn't place order (Express). Unexpected error, please try again."));
            if (BrippoExpressCheckout.prototype.isOSC()) {
                BrippoExpressCheckout.prototype.restoreOSC();
            }
            return false;
        }

        console.log(BrippoExpressCheckout.prototype.expressPaymentRequest);
        console.log("Showing payment window");
        try {
            BrippoExpressCheckout.prototype.expressPaymentRequest.show();
        } catch(e) {
            console.log("payment request.show failed");
            console.log(e);
            BrippoExpressCheckout.prototype.restoreOSC();
        }

        return true;
    },

    onRenderedHandler: function() {
        let self = this;
        if (!this.shouldDisplayInPaymentsList()) {
            return;
        }
        console.log("BrippoCheckout - Express rendered");
        self.initRequest();
        window.dispatchEvent(new Event('BrippoExpressMethodRendered'));
    },

    methodRendered: function() {
        let self = this;

        self.hideLoadingPayment();
        let methodTitle = document.getElementById('brippo-in-list-title');
        let methodLogo = document.getElementById('brippo-payment-list-wallet-logo');
        let methodNote = document.getElementById('brippo-payment-method-note');

        if (!methodLogo || !methodTitle || !methodNote) {
            console.log("Missing methodLogo || !methodTitle || !methodNote");
            return;
        }
        methodTitle.innerText = self.methodTitleForPaymentList();
        let logoSrc = self.methodLogo();
        console.log("set logo to " +logoSrc);
        methodLogo.src = logoSrc;
        methodLogo.style.display = "inline-block";
        methodNote.style.display = 'block';

        if (logoSrc == "") {
            methodLogo.style.display = 'none';
            methodNote.style.display = 'none';
        }

        if (BrippoExpressCheckout.prototype.quoteHasValidAddressData !== true) {
            //BrippoExpressCheckout.prototype.saveBillingAddress();
        }

        if (document.getElementById('container_payment_method_brippopayments_express')) {
            document.getElementById('container_payment_method_brippopayments_express').style.display='block'
        }
    },

    initRequest: function (intent = 1) {
        const self = this;
        console.log("Init wallet");

        if(typeof intent == 'undefined') intent = 1;

        if (!this.config.enabledInCheckout) {
            return;
        }
        self.showLoadingPayment();
        BrippoExpressCheckout.prototype.onCanMakePaymentHandlers.push(function () {
            window.dispatchEvent(new Event('BrippoExpressMethodRendered'));
        });

        if (BrippoExpressCheckout.prototype.expressPaymentRequest != null) {
            console.log("UPDATE PAYMENT REQUEST");
            BrippoExpressCheckout.prototype.updatePaymentRequest(
                {
                    source: 'checkout',
                    elementId: 'brippopayments_express-express-button'
                },
                BrippoExpressCheckout.prototype.expressPaymentRequest,
                function(canMakePayment) {
                    console.log("update isPlaceOrderActionAllowed("+self.isPlaceOrderActionAllowed+") to " + canMakePayment);
                    self.methodRendered();
                    self.isPlaceOrderActionAllowed = canMakePayment;
                }
            );
        } else {
            console.log("NEW PAYMENT REQUEST");
            BrippoExpressCheckout.prototype.initPaymentRequest(
                this.config,
                {
                    source: 'checkout',
                    elementId: 'brippopayments_express-express-button'
                },
                function (prButton) {
                    self.onButtonReadyHandler(prButton);
                },
                function (canMakePayment, paymentRequest) {
                    BrippoExpressCheckout.prototype.expressPaymentRequest = paymentRequest;
                    console.log("can make payment "+ canMakePayment);
                    // console.log(BrippoExpressCheckout.prototype.expressPaymentRequest);

                    self.isPlaceOrderActionAllowed = canMakePayment;
                    if (canMakePayment && paymentRequest) {
                        self.resetExpressError();
                        paymentRequest.on('cancel', function (ev) {
                            console.log("paymentRequest.cancel executed");
                            self.isPlaceOrderActionAllowed = true;
                        });
                        console.log("canMakePayment:" + canMakePayment);
                    }
                    if (canMakePayment !== true && intent <= 3) {
                        console.log("can make payment: "+canMakePayment);
                        console.log("wallet not available");
                        // setTimeout(self.initRequest(intent + 1), 3500);
                        self.showExpressError('Wallet not available.');
                        self.hideLoadingPayment();
                    }
                }
            );
        }

    },

    showLoadingPayment: function() {
        let element = document.querySelector('#brippo-payment-method-loading');

        if (element !== null) {
            element.style.display = 'block';
            // $('#brippo-payment-method-loading').show();
        }
    },
    hideLoadingPayment: function() {
        let element = document.querySelector('#brippo-payment-method-loading');

        if (element !== null) {
            element.style.display = 'none';
            // $('#brippo-payment-method-loading').hide();
        }
    },

    onButtonReadyHandler: function (prButton) {
        const self = this;
        prButton.on('click', function (ev) {
            if (!self.validate()) {
                ev.preventDefault();
            }
        });
    },
    validate: function () {
        if (BrippoExpressCheckout.prototype.placeOrderLock === true) {
            return false;
        }

        let agreementsElement = document.getElementById('checkout-agreements');
        if (agreementsElement === null || agreementsElement === undefined) {
            return true;
        }

        let checkboxes = agreementsElement.querySelectorAll('input[type=checkbox]');
        let allChecked = true;

        for (let i = 0; i < checkboxes.length; i++) {
            if (!checkboxes[i].checked) {
                allChecked = false;
                break;
            }
        }

        if (allChecked) {
            return true;
        } else {
            alert(Translator.translate("Please agree to the terms and conditions before placing the order."));
            return false;
        }
    },

    shouldDisplayInPaymentsList: function() {
        return this.config.checkoutLocation === "payments_list";
    },
    methodTitleForPaymentList: function () {
        return BrippoExpressCheckout.prototype.getWalletName();
    },
    methodLogo: function () {
        if (BrippoExpressCheckout.prototype.isGooglePay()) {
            return this.config.walletsLogosUrls.googlePay;
        } else if (BrippoExpressCheckout.prototype.isApplePay()) {
            return this.config.walletsLogosUrls.applePay;
        } else if (BrippoExpressCheckout.prototype.isLink()) {
            return this.config.walletsLogosUrls.link;
        }
        return '';
    },
    showExpressError: function(error) {
        let container = document.getElementById('brippopayments_express-express-button-payment-errors');

        container.style.display = 'block';
        container.innerHTML = error;
    },
    resetExpressError: function() {
        let container = document.getElementById('brippopayments_express-express-button-payment-errors');
        if (container == null) return;
        container.style.display = 'none';
        container.innerHTML = '';
    }
};

window.dispatchEvent(new Event('BrippoExpressLoaded'));

LittleDemon - FACEBOOK
[ KELUAR ]