<commit_before>
import { PayPalCheckout } from '../components';
import xcomponent from 'xcomponent/src';
import { isEligible } from './eligibility';
import { config } from '../config';
import { getMeta } from '../bridge';

import { urlWillRedirectPage, redirect as redir, onDocumentReady, getElements } from './util';
import { renderButtons } from './button';
import { logDebug, logInfo, logWarning, logError } from './log';

let redirected = false;

function redirect(location) {

    if (redirected) {
        return;
    }

    redirected = true;

    if (window.ppCheckpoint) {
        if (location && location.match(/^https:\/\/www\.paypal\.com/)) {
            window.ppCheckpoint('flow_fullpage_redirect');
        } else if (location && (location.match(/PayerID=/) || location.match(/ba_token=/))) {
            window.ppCheckpoint('flow_complete');
        } else {
            window.ppCheckpoint('flow_cancel');
        }
    }

    setTimeout(function() {
        redir(location);
    }, 500);
}

/*  Parse Token
    -----------

    We are passed either a token, or a url containing the token. In order to run the new checkout component we need to
    strip out the token from the url in order to pass it down as a prop
*/

function parseToken(token) {
<commit_msg>Flush logs before redirecting<commit_after>
import xcomponent from 'xcomponent/src';
import $logger from 'beaver-logger/client';

import { PayPalCheckout } from '../components';
import { isEligible } from './eligibility';
import { config } from '../config';
import { getMeta } from '../bridge';

import { urlWillRedirectPage, redirect as redir, onDocumentReady, getElements } from './util';
import { renderButtons } from './button';
import { logDebug, logInfo, logWarning, logError } from './log';

let redirected = false;

function redirect(location) {

    if (redirected) {
        return;
    }

    redirected = true;

    if (window.ppCheckpoint) {
        if (location && location.match(/^https:\/\/www\.paypal\.com/)) {
            window.ppCheckpoint('flow_fullpage_redirect');
        } else if (location && (location.match(/PayerID=/) || location.match(/ba_token=/))) {
            window.ppCheckpoint('flow_complete');
        } else {
            window.ppCheckpoint('flow_cancel');
        }
    }

    setTimeout(function() {
        redir(location);
    }, 500);

    $logger.flush();
}

/*  Parse Token
    -----------

    We are passed either a token, or a url containing the token. In order to run the new checkout component we need to
    strip out the token from the url in order to pass it down as a prop
*/

function parseToken(token) {

{'fraction_non_alphanumeric': 0.13830996589617278, 'fraction_numerical': 0.0022735884804850324, 'mean_word_length': 2.8260869565217392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3914474', 'n_tokens_mistral': 766, 'n_tokens_neox': 740, 'n_words': 230}