<commit_before>
<button id="ckoShowForm" class="action submit primary">
    <?= $block->escapeHtml(__('Add a card')) ?>
</button>

<div id="cko-form-holder" style="display: none;">
    <br>
    <div class="one-liner">
      <div class="card-frame">
        <!-- form will be added here -->
      </div>
    </div>
    <form class="widget-container" id="saveCardForm" method="POST">
        <?= $block->getBlockHtml('formkey') ?>
        <input type="hidden" id="ckoCardToken" name="ckoCardToken">
    </form>
</div>
<button id="ckoSaveCard" type="button" class="action primary"  title="<?= $block->escapeHtmlAttr(__('Save the card')) ?>" style="display: none;">
    <?= $block->escapeHtml(__('Save the card')) ?>
</button>

<script type="text/javascript">
    require([
        'jquery',
        'domReady!',
        'framesjs'
    ], function ($) {
        // Prepare the elements
        var saveCardButton = $('#ckoSaveCard');
        var showFormButton = $('#ckoShowForm');
        var cardTokenField = $('#ckoCardToken');
        var cardFormContainerId = '#cko-form-holder';
        var ckoPublicKey = '<?= $block->escapeHtml($block->config->getValue('public_key')); ?>';
        var paymentForm = document.getElementById('saveCardForm');

        // Initialize the embedded form
        Frames.init(
            {
                publicKey: ckoPublicKey,
                debug: Boolean(<?= $block->escapeHtml(($block->config->getValue('debug') && $block->config->getValue('console_logging'))); ?>),
                frameValidationChanged: function() {
                    if (Frames.isCardValid()) {
                        saveCardButton.attr("disabled", false);
                        Frames.submitCard();
                    }
                },
                frameActivated: function () {
                    saveCardButton.attr("disabled", true);
                },
                cardTokenized: function(event) {
                    // Add the card token to the form
                    Frames.addCardToken(paymentForm, event.token);
                    // Add the card token to the hidden input field
                    cardTokenField.val(event.token);
                    Frames.enableSubmitForm();
                }
            }
        );

        // Add card form controls
        showFormButton.on('click touch', function (event) {
            $(cardFormContainerId).show();
            saveCardButton.show();
            showFormButton.hide();
        });

        // Handle the submit event
        saveCardButton.on('click touch', function (event) {
            // Disable the save button
            saveCardButton.attr("disabled", true);

            // Start the loader
            $('body').trigger('processStart');

            // Send the request
            $.ajax({
                type: 'POST',
                url: '<?= $block->escapeHtml($block->getUrl('checkout_com/account/savecard')); ?>',<commit_msg>Support to Frames v2 in the backend.<commit_after>
<button id="ckoShowForm" class="action submit primary">
    <?= $block->escapeHtml(__('Add a card')) ?>
</button>

<div id="cko-form-holder" style="display: none;">
    <br>
    <div class="one-liner">
      <div class="card-frame">
        <!-- form will be added here -->
      </div>
    </div>
    <form class="widget-container" id="saveCardForm" method="POST">
        <?= $block->getBlockHtml('formkey') ?>
        <input type="hidden" id="ckoCardToken" name="ckoCardToken">
    </form>
</div>
<button id="ckoSaveCard" type="button" class="action primary"  title="<?= $block->escapeHtmlAttr(__('Save the card')) ?>" style="display: none;">
    <?= $block->escapeHtml(__('Save the card')) ?>
</button>

<script type="text/javascript">
    require([
        'jquery',
        'domReady!',
        'framesjs'
    ], function ($) {
        // Prepare the elements
        var saveCardButton = $('#ckoSaveCard');
        var showFormButton = $('#ckoShowForm');
        var cardTokenField = $('#ckoCardToken');
        var cardFormContainerId = '#cko-form-holder';
        var ckoPublicKey = '<?= $block->escapeHtml($block->config->getValue('public_key')); ?>';
        var paymentForm = document.getElementById('saveCardForm');

        // Initialize the embedded form
        Frames.init(
            {
                publicKey: ckoPublicKey,
                debug: Boolean(<?= $block->escapeHtml(($block->config->getValue('debug') && $block->config->getValue('console_logging'))); ?>),
                cardValidationChanged: function() {
                    if (Frames.isCardValid()) {
                        Frames.submitCard();
                    }
                },
                frameActivated: function () {
                    saveCardButton.attr("disabled", true);
                },
                cardTokenized: function(event) {
                    // Add the card token to the form
                    Frames.addCardToken(paymentForm, event.token);

                    // Add the card token to the hidden input field
                    cardTokenField.val(event.token);
                    saveCardButton.attr("disabled", false);

                    Frames.enableSubmitForm();
                }
            }
        );

        // Add card form controls
        showFormButton.on('click touch', function (event) {
            $(cardFormContainerId).show();
            saveCardButton.show();
            showFormButton.hide();
        });

        // Handle the submit event
        saveCardButton.on('click touch', function (event) {
            // Disable the save button
            saveCardButton.attr("disabled", true);

            // Start the loader
            $('body').trigger('processStart');

            // Send the request
            $.ajax({
                type: 'POST',
                url: '<?= $block->escapeHtml($block->getUrl('checkout_com/account/savecard')); ?>',
{'fraction_non_alphanumeric': 0.15154080596004063, 'fraction_numerical': 0.00016931933626820184, 'mean_word_length': 1.9358846918489065, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3305745', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1492, 'n_words': 328}