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.
Hello @Bryan-Square ,
Iâm working on redirection from salesforce web component to square pos app. Using android and ios both but having trouble in both
Android : After calling square app
getting error[Unexpected developer error
Point of Sale API must be started with startActivityForResult() in the same task. It looks like the caller either used startActivity() or used startActivityForResult() from a finished activity or with the FLAG_A CTIVITY_NEW_TASK flag.]
ios : While hitting square app its redirecting to callback url everytime.
The error youâre encountering suggests that the Square Point of Sale API is not being started correctly. Specifically, it looks like the startActivityForResult()
method is not being used properly.
Square Point of Sale API requires that you start the activity using startActivityForResult()
from an active, non-finished activity, and without the FLAG_ACTIVITY_NEW_TASK
flag. Hereâs how you can correctly implement this:
Correct Implementation
- Ensure you are using
startActivityForResult()
:
- You need to start the Point of Sale activity with
startActivityForResult()
to handle the result properly.
- Check the Activity State:
- Make sure the activity from which you are calling
startActivityForResult()
is not finished or destroyed.
- Avoid using
FLAG_ACTIVITY_NEW_TASK
:
- Do not use the
FLAG_ACTIVITY_NEW_TASK
flag when starting the activity.
The iOS redirection to the Square app is also not functioning as expected. When attempting to redirect, it returns to the callback URL without any error.
Are there any dependencies for this redirection:
1] such as limitations on using a sandbox application ID? As the Point of Sale API may not support it,
2] Iâm using the production environment. Additionally.
3] is it necessary for the account to be activated for successful redirection?
4] Also, does redirection not work in India?
Point of Sale API wonât work in sandbox. If your in India then youâll only be able to test cash payments.
The iOS redirection to the Square app is also not functioning as expected. When attempting to redirect, it returns to the callback URL without any error. Even not able to debug why its happening. Please mention all required prerequisites needs to do before redirection like from square app, developer dashboard side