So what type of variable are you setting? Note the amount must be a string; earlier I see you were using .val()
, which can return a string, number, or array. Can you confirm that the value is actually a string?
sorry I am lost, is it integer or string? I tried String in the beginning but got an error, then I tried integer and got 0 whenever I try to pass a value.
It should be a string. Like â500â (the quotes implies itâs a string). If itâs evaluating to something other than a string, itâs probably just ignoring it, or it may cause an error.
You said â500â works, which is definitely a string, so now Iâm also confused . Can you confirm what actually works or not?
actually â500â and 500 both works, so both string and number worked for me for some reason. so in my case var num2 = $("#total-payable").val();
var num3 = num2.toSyring();
var data = {
amount_money: {
amount: num3,
currency_code: âUSDâ
},
when I run the code, I get âAPI Error The JSON passed in your request is invalid. Check that your JSON string is URL-encoded and JSON is correctly formattedâ
for more clarification, I am getting the value from a span tag inside a table data cell td. I have been trying to retrieve the data using document.getElementbyID() and the way above and in both cases trying to change the value to String type but I keep getting the above error. this is the code
<td class="text-right" colspan="2" style="font-weight:bold;"><span id="total-payable">0</span>
</td>
I really appreciate your help!
If youâre using span
as the HTML element, then I think you would need to do:
var payable = document.getElementById("total-payable").innerHTML;
var data = {
amount_money: {
amount: payable,
...
Note: youâd probably want to add additional validation here, though, since amount needs to be an integer, to make sure you donât pass bad data.
Further, val()
wouldnât work on a span
element as far as I knowâŚit typically is used on something like an input
, so this would result in nothing (because a span doesnât have a value), which is why neither of the above are working, Iâm guessing.
Edit: If you prefer jQuery, it looks like you can do:
var payable = $("#total-payable").text(); // instead of .val()
...
Thank you, I tried both but neither worked, still getting the error.
Can you confirm in the above example, payable
is actually equal to something if you print it out? If so, what does it print?
To be clear, I tested the above, and it worked fine as far as I could see. Passing the hard-coded â5â versus doing var payable = document.getElementById("total-payable").innerHTML;
produced the exact same data object.
yes, we also debugged the code and the value that is passed is correct but when the value is passed, then the amount to be paid is showing as 0 now. I will look into it more and see what we are missing.
For the call back, I am just getting an empty page with a header. Just to confirm, I donât have to change anything in the callback.html and callback.js, correct? sorry for bothering you!
@Bryan-Square any update of Squareâs functionality here? Is there an ability to connect a web application to a Square reader?
If not, curious why not? Because of the limited bluetooth functionality, making it difficult to find the device?
Thank you.
At this time the only way to connect a web application with Square hardware is with Terminal API. Connecting to a reader isnât currently possible.