<commit_before>hqDefine("accounting/js/stripe_card_manager", [
    'jquery',
    'knockout',
    'accounting/js/lib/stripe',
], function (
    $,
    ko,
    Stripe
) {
    var newStripeCardModel = function(data, cardManager){
        var self = {};
        var mapping = {
            observe: ['number', 'cvc', 'expMonth','expYear', 'isAutopay', 'token'],
        };

        self.wrap = function (data) {
            ko.mapping.fromJS(data, mapping, self);
        };
        self.reset = function () {
            self.wrap({'number': '', 'cvc': '', 'expMonth': '', 'expYear': '', 'isAutopay': false, 'token': ''});
        };
        self.reset();

        self.unwrap = function () {
            return {token: self.token(), autopay: self.isAutopay()};
        };

        self.isTestMode = ko.observable(false);
        self.isProcessing = ko.observable(false);
        self.errorMsg = ko.observable('');

        var submit = function () {
            // Sends the new card to HQ
            return $.ajax({
                type: "POST",
                url: data.url,
                data: self.unwrap(),
                success: function (data) {
                    $("#card-modal").modal('hide');
                    $("#success-modal").modal('show');
                    cardManager.wrap(data);
                    self.reset();
                },
            }).fail(function (data) {
                var response = JSON.parse(data.responseText);
                self.errorMsg(response.error);
            }).always(function () {
                self.isProcessing(false);
            });
        };

        var handleStripeResponse = function (status, response) {
            if (response.error) {
                self.isProcessing(false);
                self.errorMsg(response.error.message);
            } else {
                self.errorMsg('');
                self.token(response.id);
                submit();
            }
        };

        var createStripeToken = function () {
            Stripe.card.createToken({
                number: self.number(),
                cvc: self.cvc(),
                exp_month: self.expMonth(),
                exp_year: self.expYear(),
            }, handleStripeResponse);
        };

        self.saveCard = function () {
            self.isProcessing(true);
            createStripeToken();
        };

        return self;
    };

    var stripeCardModel = function (card, baseUrl, cardManager) {
        'use strict';
        var self = {};
        var mapping = {
            include: ['brand', 'last4', 'exp_month','exp_year', 'is_autopay'],
            copy: ['url', 'token'],
        };

        self.wrap = function (data) {
            ko.mapping.fromJS(data, mapping, self);
            self.is_autopay(self.is_autopay() === 'True');
            self.url = baseUrl + card.token + '/';
        };<commit_msg>Fix autopay indicator<commit_after>hqDefine("accounting/js/stripe_card_manager", [
    'jquery',
    'knockout',
    'accounting/js/lib/stripe',
], function (
    $,
    ko,
    Stripe
) {
    var newStripeCardModel = function(data, cardManager){
        var self = {};
        var mapping = {
            observe: ['number', 'cvc', 'expMonth','expYear', 'isAutopay', 'token'],
        };

        self.wrap = function (data) {
            ko.mapping.fromJS(data, mapping, self);
        };
        self.reset = function () {
            self.wrap({'number': '', 'cvc': '', 'expMonth': '', 'expYear': '', 'isAutopay': false, 'token': ''});
        };
        self.reset();

        self.unwrap = function () {
            return {token: self.token(), autopay: self.isAutopay()};
        };

        self.isTestMode = ko.observable(false);
        self.isProcessing = ko.observable(false);
        self.errorMsg = ko.observable('');

        var submit = function () {
            // Sends the new card to HQ
            return $.ajax({
                type: "POST",
                url: data.url,
                data: self.unwrap(),
                success: function (data) {
                    $("#card-modal").modal('hide');
                    $("#success-modal").modal('show');
                    cardManager.wrap(data);
                    self.reset();
                },
            }).fail(function (data) {
                var response = JSON.parse(data.responseText);
                self.errorMsg(response.error);
            }).always(function () {
                self.isProcessing(false);
            });
        };

        var handleStripeResponse = function (status, response) {
            if (response.error) {
                self.isProcessing(false);
                self.errorMsg(response.error.message);
            } else {
                self.errorMsg('');
                self.token(response.id);
                submit();
            }
        };

        var createStripeToken = function () {
            Stripe.card.createToken({
                number: self.number(),
                cvc: self.cvc(),
                exp_month: self.expMonth(),
                exp_year: self.expYear(),
            }, handleStripeResponse);
        };

        self.saveCard = function () {
            self.isProcessing(true);
            createStripeToken();
        };

        return self;
    };

    var stripeCardModel = function (card, baseUrl, cardManager) {
        'use strict';
        var self = {};
        var mapping = {
            include: ['brand', 'last4', 'exp_month','exp_year', 'is_autopay'],
            copy: ['url', 'token'],
        };

        self.wrap = function (data) {
            ko.mapping.fromJS(data, mapping, self);
            self.url = baseUrl + card.token + '/';
        };
{'fraction_non_alphanumeric': 0.1486793772957845, 'fraction_numerical': 0.00034983382893125764, 'mean_word_length': 1.490418118466899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7660300', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1546, 'n_words': 290}