HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //proc/thread-self/cwd/wp-content/plugins/woo-stripe-payment/packages/cartflows/assets/js/index.js
import $ from 'jquery';
import {loadStripe} from '@stripe/stripe-js';
import apiFetch from "@wordpress/api-fetch";

const data = cartflows_offer.stripeData;
const getStripe = new Promise(resolve => {
    loadStripe(data.key, (() => data.accountId ? {stripeAccount: data.accountId} : {})()).then(stripe => {
        resolve(stripe);
    }).catch(error => {
        resolve(false);
    })
});

let currentButton;

const initialize = () => {
    window.addEventListener('hashchange', handleHashChange);
    $(document.body).on('click', 'a[href*="wcf-up-offer"], a[href*="wcf-down-offer"]', handleButtonClick);
}

const handleButtonClick = (e) => {
    currentButton = $(e.currentTarget);
}

const handleHashChange = async (e) => {
    var match = e.newURL.match(/response=(.*)/);
    if (match) {
        try {
            var obj = JSON.parse(window.atob(decodeURIComponent(match[1])));
            if (obj && obj.hasOwnProperty('client_secret')) {
                history.pushState({}, '', window.location.pathname + window.location.search);
                handleCardAction(obj);
            }
        } catch (err) {

        }
    }
    return true;
}

const handleCardAction = async ({client_secret, ...props}) => {
    const stripe = await getStripe;
    stripe.handleCardAction(client_secret).then(result => {
        if (result.error) {
            $('body').trigger('wcf-update-msg', [result.error.message, 'wcf-payment-error']);
            setTimeout(() => {
                $(document.body).trigger('wcf-hide-loader')
                $(document.body).trigger('wcf-update-msg', [data.msg, 'wcf-payment-success']);
            }, data.timeout);
            syncPaymentIntent({client_secret, ...props});
        } else {
            triggerOfferClick();
        }
    })
}

const triggerOfferClick = () => {
    currentButton.click();
}

const syncPaymentIntent = (data) => {
    return new Promise((resolve, reject) => {
        apiFetch({
            path: '/wc-stripe/v1/cartflows/payment-intent',
            method: 'POST',
            data
        }).then(response => {
        }).catch(err => {
        });
    });
}

initialize();