{"size": 3848, "ext": "js", "max_stars_repo_path": "example/public/js/main.js", "max_stars_repo_name": "JohnAdamsy/africastalking-node.js", "max_stars_repo_stars_event_min_datetime": "2016-01-19T08:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T13:23:18.000Z", "max_issues_repo_path": "example/public/js/main.js", "max_issues_repo_name": "JohnAdamsy/africastalking-node.js", "max_issues_repo_issues_event_min_datetime": "2016-01-21T08:24:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T21:54:45.000Z", "max_forks_repo_path": "example/public/js/main.js", "max_forks_repo_name": "JohnAdamsy/africastalking-node.js", "max_forks_repo_forks_event_min_datetime": "2016-01-18T15:11:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-26T16:26:52.000Z"}
{"max_stars_count": 106, "max_issues_count": 54, "max_forks_count": 102, "avg_line_length": 25.6533333333, "max_line_length": 100, "alphanum_fraction": 0.4404885655}
$(function () {

    function log(message) {
        $("#response").text(message);
        $('pre span').each(function (i, block) {
            hljs.highlightBlock(block);
        });
    }

    $("#sendSms").click(() => {
        let to = $("#phone").val();
        if ( !to) {
            log(JSON.stringify({ error: "Enter a phone number" }, null, 2));
            return;
        }

        log("Sending SMS...");

        $.ajax({
            method: "POST",
            url: "/sms/send",
            data: {
                to,
                message: "Im a lumberjack, I sleep all day and I code all night"
            },
        })
        .done(function (msg) {
            console.log("message : ", msg);
            log(JSON.stringify(msg, null, 2));
        })
        .fail(function (jqXHR, textStatus) {
            console.log("jqXHR", jqXHR);
            log(textStatus);
        });

    });

    $("#airtime").click(function () {
        const to = $("#phone").val();
        const inputAmount = $("#amount").val();
        if (!to) {
            log(JSON.stringify({ error: "Enter a phone number" }, null, 2));
            return;
        }

        if (!inputAmount) {
            log(JSON.stringify({ error: "Enter an amount (with currency) e,g, KES 334" }, null, 2));
            return;
        }

        let currencyCode, amount;
        [currencyCode, amount] = inputAmount.split(" ");

        log("Sending airtime.....");

        $.ajax({
            method: "POST",
            url: "/airtime/send",
            data: {
                to,
                currencyCode,
                amount
            }
        })
        .done(function (msg) {
            log(JSON.stringify(msg, null, 2));
        })
        .fail(function (jqXHR, textStatus) {
            log(textStatus);
        });

    });

    $("#mobileCheckout").click(function () {
        const phoneNumber = $("#phone").val();
        const inputAmount = $("#mobileCheckoutAmount").val();
        const productName = "TestProduct";

        if (!phoneNumber) {
            log(JSON.stringify({ error: "Enter a phone number" }, null, 2));
            return;
        }

        if (!inputAmount) {
            log(JSON.stringify({ error: "Enter an amount (with currency) e,g, KES 334" }, null, 2));
            return;
        }

        let currencyCode, amount;
        [currencyCode, amount] = inputAmount.split(" ");

        log("Sending...");

        $.ajax({
            method: "POST",
            url: "/payments/mobile-checkout",
            data: {
                phoneNumber,
                currencyCode,
                amount,
                productName
            }
        })
        .done(function (msg) {
            log(JSON.stringify(msg, null, 2));
        })
        .fail(function (jqXHR, textStatus) {
            log(textStatus);
        });

    });

    $("#mobileB2C").click(function () {
        const phoneNumber = $("#phone").val();
        const inputAmount = $("#mobileB2CAmount").val();
        if (!phoneNumber) {
            log(JSON.stringify({ error: "Enter a phone number" }, null, 2));
            return;
        }

        if (!inputAmount) {
            log(JSON.stringify({ error: "Enter an amount (with currency) e,g, KES 334" }, null, 2));
            return;
        }

        let currencyCode, amount;
        [currencyCode, amount] = inputAmount.split(" ");

        log("Sending money...");

        $.ajax({
            method: "POST",
            url: "/payments/mobile-b2c",
            data: {
                phoneNumber,
                currencyCode,
                amount
            }
        })
        .done(function (msg) {
            log(JSON.stringify(msg, null, 2));
        })
        .fail(function (jqXHR, textStatus) {
            log(textStatus);
        });

    });

});
