API POST error - 500 on callback function ajax request

EverscaleChris
New Member
1 0 0

Hi all, 

I'm new to the forum and was hoping someone could help.

I'm working on a site that was acquired by my employer a few years back and the original developers are no longer accessible. The site is a combination of Shopify and private apps (Express, Node, SQL).

I need to make modifications to the private apps and was looking to leverage an existing staging site that was created by the original developers. Unfortunately, the staging site errors out going from cart to checkout.

Per my discussions with Shopify Plus support, the checkout page we're using is custom and they recommended I reach out on the forums for assistance. 

Soooo...here's what I'm encountering:

1) I add items to my cart and click on the button for checkout

2) I've got a cart-scripts.liquid that runs a jQuery script sending the below ajax request. The first ajax request is successful and returns data (I can see this when I console log), but the second ajax request in the callback function is erroring out:

$("#cart-submit").click(function(event) {
    event.preventDefault();

    var payload;

    //gets cart.json from shopify

    $.ajax({
        url: "/cart.js",
        type: "GET",
        dataType: "json",
        success: function(data) {
            callCheckout(data);
        },
        error: function(data) {
            //         console.log(data);
        }
    });

});

function callCheckout(cartObject) {

    $.ajax({
        url: "/a/api/checkouts",
        type: "POST",
        data: cartObject,
        dataType: "json",
        cache: false,
        timeout: 15000,
        success: function(data) {
            //console.log(data);
            var checkoutLink = "/pages/checkout/?checkout_id=" + data.checkout.id;
            window.location.href = checkoutLink;
        },
        error: function(data) {
            //         console.log(data);
            var errortext = "";


            if (data) {

                if (data.responseJSON) {
                    errortext += data.responseJSON.errors[0] + " ";
                } else { errortext += "Looks like something went wrong. Please try again in a little while, or contact customer service for help."; }

            } else {
                errortext += "Looks like something went wrong. Please try again in a little while, or contact customer service for help.";

            }
            $('#cartSubmitError').text(errortext);
        }
    });
}

 

Does anyone have any ideas why?

 

0 Likes