I'm trying to pass a POST request to charge a card to the /locations/{location}/transactions
endpoint in Square. I have a nonce, a location ID and a Guid (.NET implementation). Everything works fine except I cannot pass a decimal value. I am using the Sandbox.
When I pass the following, the API returns 422, Value was not expected to be a string
{
"card_nonce":"VALID_CARD_NONCE",
"amount_money":{
"amount":"225.00",
"currency":"USD"
},
"idempotency_key":"3f5f21a5-9d6b-4277-93b2-2b257a8e64df"
}
When I pass the following, the API returns 422, Value was not expected to be a number 225.00
{
"card_nonce":"VALID_CARD_NONCE",
"amount_money":{
"amount": 225.00,
"currency":"USD"
},
"idempotency_key":"3f5f21a5-9d6b-4277-93b2-2b257a8e64df"
}
When I pass the following, the API returns 200
{
"card_nonce":"VALID_CARD_NONCE",
"amount_money":{
"amount": 225,
"currency":"USD"
},
"idempotency_key":"3f5f21a5-9d6b-4277-93b2-2b257a8e64df"
}
It allows me to submit an integer amount but not a decimal. Any ideas why?
No need to use decimals if you are charging with cents in USD - the smallest denomination for the amount field is in cents for USD. You can set it to 22500 to charge US$225.00
Here is the relevant documentation: https://docs.connect.squareup.com/api/connect/v2/#workingwithmonetaryamounts
The amount of money, in the lowest in the smallest denomination of the currency indicated by currency. For example, when currency_code is USD, amount is in cents.