Forgive my naivete here, but I am an old developer moving into the modern age. In short, I have an old web site programmed in ASP (I know, I know) that needs to use the Square Checkout API for very simple processing of payment. Thus, I need to send a JSON request to Square and process its response. I created a very, very stripped down JSON request using Javascript to be sent to Square for testing purposes, but cannot seem to get a handle on the response, "null." I cannot tell if I am simply getting no response and/or if my code is incorrect on receiving the JSON return. As it stands, I am only attempting to receive the response and print it to the screen before I add code to parse it and later redirect back to Square as per the API documentation. What am I doing wrong??
[Please note that I had previously wrapped the onload parameter to the request.response but it did not fire.]
My code is below. Any and all help would be sincerely appreciated!
Thank you, -Joe
<html>
<script>
var obj = {
"idempotency_key": "00000000c",
"order":
{
"reference_id": "00000000c",
"line_items":
[{
"name": "My order",
"quantity": "1",
"base_price_money":
{
"amount": 15,
"currency": "USD"
}
}],
"taxes":
[{
"name": "Sales Tax",
"percentage": "8.5"
}]
},
"ask_for_shipping_address": false,
"merchant_support_email": "confused@myownsamplesite.com",
"redirect_url": "https://www.myownsamplesite.com/success.asp"
}
var myJSON = JSON.stringify(obj);
var request = new XMLHttpRequest();
request.open('POST', 'https://connect.squareup.com/v2/locations/{location_ID_removed_for_security}/checkouts', true);
request.setRequestHeader('Authorization', '{auth_token_removed_for_security}');
request.setRequestHeader('Accept','application/json');
request.setRequestHeader('Content-Type','application/json');
request.responseType = "json";
request.send(myJSON);
var returnJSON = request.response;
document.write(returnJSON);
</script>
</html>