Hello! Writing in regards to some unhelpful errors that are being received when attempting to create an integration between Salesforce and Square.
I am attempting to deeplink to Square via the iOS app, and am getting an unspecified JSON error from the Square app upon attempt to open.
Here is the un-encoded JSON that I am attempting to pass through:
{amount_money: {amount: "500", currency_code: "USD" }, callback_url: "CALLBACK_URL", client_id: "CLIENT_ID", location_id: "LOCATION_ID", version: "1.3", notes: "New Work Order", options: { supported_tender_types: ["CREDIT_CARD"]}}'
While attempting to debug, I have appended the encoded JSON string to the end of the www.connect.squareupsandbox.com URL to see if the JSON string is formatted correctly. Unfortunately, I am getting a similarly unhelpful error, as the UI shows an “Oops! We’re sorry, but something went wrong” screen and the console shows the failing line of code with a comment of “// this fails for some browsers. :(”
I have verified that everything is encoded properly, and no miscellaneous characters are being cut off.
Any assistance is appreciated.
I have continued investigating this issue and am receiving the following error in the browser console:
Any assistance is appreciated.
Further updates, I have verified by comparing my stringified and encoded JSON structure to the structure listed on this blog, and I am still getting the following API error in iOS: “The JSON passed in the request is invalid. Check that your JSON string is URL-encoded and the JSON is correctly formatted.”
Currently with Square mobile web and all in person payment solutions need to be tested in production. They aren’t currently supported in sandbox. Also that un-encoded JSON does look correct. Could you provide the encoded string so we can take a look? Also what’s you application ID?
Sure, thank you!
This is the deeplink we are attempting to use:
square-commerce-v1://payment/create?data=`%7B%22amount_money%22%3A%7B%22amount%22%3A1%2C%22currency%22%3A%22USD%22%7D%2C%22callback_url%22%3A%22com.salesforce.fieldservice%3A%2F%2Fv1%2FsObject%SALESFORCE_ID%22%2C%22client_id%22%3A%22sq0idp-RsbpdgUuHgArthzh6i8dmw%22%2C%22version%22%3A%221.3%22%2C%22notes%22%3A%22TestNote%22%2C%22options%22%3A%7B%22supported_tender_types%22%3A%5B%22CREDIT_CARD%22%5D%7D%7D`
with our test org Id being: sq0idp-RsbpdgUuHgArthzh6i8dmw
There is currently conflicting information in the documentation as to whether the money
object should have a value for currency
or currency_code
, so any assistance there would be appreciated as well.
Sorry for the barrage of comments, one other piece of information that might be helpful: this account is not activated, but I have tried substituting an active account (sq0idp-jBftfDD2RvuvyPS7H0hMQg
) to no avail.
That’s probably the issue. Card processing needs to be enabled. What issues are you running into?
I have attempted this with an org that has card processing enabled to no avail. The issue is that I am getting an error on the JSON:
API ERROR - The JSON passed in the request is invalid. Check that your JSON string is URL-encoded and the JSON is correctly formatted.
It doesn’t tell me how the JSON is incorrectly formatted.
Good morning, just an update on this:
While attempting to test this functionality this morning, our deep-link is no longer working. Currently getting an error that Square is not installed. To resolve this, we attempted to update the Square application on iOS to no avail.
So the Square app didn’t update on the device?
The square app did update on the device, but now the deeplink is not working at all - we were previously getting an invalid JSON error, but now are getting an error saying that the app is not installed.
It looks like the data
that you’re passing in is in a single quote. If you try the following does it work?
square-commerce-v1://payment/create?data=%7B%22amount_money%22%3A%7B%22amount%22%3A1%2C%22currency%22%3A%22USD%22%7D%2C%22callback_url%22%3A%22com.salesforce.fieldservice%3A%2F%2Fv1%2FsObject%SALESFORCE_ID%22%2C%22client_id%22%3A%22sq0idp-RsbpdgUuHgArthzh6i8dmw%22%2C%22version%22%3A%221.3%22%2C%22notes%22%3A%22TestNote%22%2C%22options%22%3A%7B%22supported_tender_types%22%3A%5B%22CREDIT_CARD%22%5D%7D%7D
Hello, I am using the tics per the documentation linked above, it does not work with or without the tics.
I am now receiving an error that the Square app will not open due to not being installed - has the deeplink changed?
Hi @evelyn.grizzle, I just sent you an email but in looking at the account is this the location_id
your passing in: LBJ24DS5JMDK6
. If so that’s a sandbox location_id
and won’t work with Point of Sale API. Also is your testing taking place in the US with the account that has card processing enabled?
Yes, our testing is taking place in the US with the account that has card processing enabled. We have tried it with and without the sandbox Location_Id. Rather than guessing, I need to know the proper JSON fields to include, as there is conflicting information in the documentation, and I need to know the updated deeplink, as the given deeplink of square-commerce-v1://payment/create?data=
is no longer working after the most recent Square update.
I just tested multiple times with the Point of Sale API using this link and it’s working as expected:
square-commerce-v1://payment/create?data=%7B%22callback_url%22%3A%22https%3A%2F%2Fios-web-api-test.herokuapp.com%2Fv2.0%2Findex.html%22%2C%22client_id%22%3A%22sq0idp-K-i6--d9HD4fha58YpSS6w%22%2C%22version%22%3A%222.0%22%2C%22amount_money%22%3A%7B%22amount%22%3A%22100%22%2C%22currency_code%22%3A%22USD%22%7D%2C%22notes%22%3A%22Extra%20toppings%22%2C%22options%22%3A%7B%22tender_types%22%3A%5B%22CARD_FROM_READER%22%2C%22KEYED_IN_CARD%22%2C%22CARD_ON_FILE%22%2C%22OTHER%22%2C%22SQUARE_GIFT_CARD%22%5D%2C%22auto_return%22%3Atrue%2C%22skip_receipt%22%3Atrue%2C%22allow_split_tender%22%3Atrue%2C%22full_transaction_response%22%3Atrue%7D%7D
Is the application_id
you’re using still this one? sq0idp-RsbpdgUuHgArthzh6i8dmw
If so card processing still isn’t enabled with that account. If you’re using a different application could you provide the link that you’re currently getting the error with so the team can take a look?
An update on this,
After working with Bryan in the Slack channel to determine the proper JSON structure for the string, it was determined that the appropriate structure is:
{"callback_url":"https://bergenterprises--partial.lightning.force.com/services/apexrest/Payment__c/SquarePaymentManager","client_id":"sq0idp-iI6vYl3TSmY4cJ2-NeTw3Q","version":"1.3","amount_money":{"amount":100,"currency_code":"USD"},"options":{"supported_tender_types":["CREDIT_CARD"],"clear_default_fees":true,"auto_return":true,"skip_receipt":true}}
The issue with Salesforce is that when using an App Extension from Salesforce Field Service Lightning into the Square app, Salesforce automatically URL encodes any input, so we were URL encoding twice, which is what was causing the JSON error.
Hopefully this helps anyone trying to figure out the same issue.