Amount Mismatch when creating Terminal API Payment

Hi,

We have experienced an issue where when creating a checkout via Terminal API, at times, passed amount + tip throws an error from Square end.

Example of a Successful Order:

Request:

2024-10-29 15:40:09 - SQUARE-TERMINAL API >>>>>>>>>> 
URI         : https://connect.squareup.com/v2/terminals/checkouts
Method      : POST
Headers     : {Accept=[application/json], Content-Type=[application/json], Authorization=[Bearer REDACTED], Square-Version=[2024-01-18], Content-Length=[318]}
Request body: {"idempotency_key":"SQT-a22335c5a39c99-1730216409551","checkout":{"amount_money":{"amount":2273,"currency":"USD"},"tip_money":{"amount":429,"currency":"USD"},"order_id":"8BSvJuip13cH6zsLCx9UJMUNrvAZY","device_options":{"device_id":"846CS108A2000949","tip_settings":{"allow_tipping":false},"skip_receipt_screen":true}}}

Response:

2024-10-29 15:40:09 - SQUARE-TERMINAL API API  <<<<<<<<<< Status = [200] path = [https://connect.squareup.com/v2/terminals/checkouts]
Status code  : 200
Status text  : OK
Headers      : {Date=[Tue, 29 Oct 2024 15:40:09 GMT], Content-Type=[application/json], Connection=[keep-alive], CF-Ray=[8da4432fb8af05f9-IAD], CF-Cache-Status=[DYNAMIC], Strict-Transport-Security=[max-age=631152000; includeSubDomains; preload], Vary=[Accept-Encoding], frame-options=[DENY], square-version=[2024-01-18], squareup--connect--v2--common--versionmetadata-bin=[CgoyMDI0LTAxLTE4], x-content-type-options=[nosniff], x-envoy-decorator-operation=[/v2/terminals/**], x-frame-options=[DENY], x-sq-dc=[aws], x-sq-region=[us-east-1], x-xss-protection=[1; mode=block], Server=[cloudflare]}
Response body: {"checkout": {"id": "widl02zjRMWqO","amount_money": {"amount": 2273,"currency": "USD"},"device_options": {"device_id": "846CS108A2000949","collect_signature": false,"tip_settings": {"allow_tipping": false},"skip_receipt_screen": true,"show_itemized_cart": true},"status": "PENDING","created_at": "2024-10-29T15:40:09.817Z","updated_at": "2024-10-29T15:40:09.817Z","app_id": "sq0idp-TpHen_F96miOUr07zsUKTw","order_id": "8BSvJuip13cH6zsLCx9UJMUNrvAZY","location_id": "LVTX8NQD7J2DW","payment_type": "CARD_PRESENT","payment_options": {"autocomplete": true},"tip_money": {"amount": 429,"currency": "USD"}}}

A Failed Transaction:

Request

2024-10-02 14:00:37 - SQUARE-TERMINAL API >>>>>>>>>> 
URI         : https://connect.squareup.com/v2/terminals/checkouts
Method      : POST
Headers     : {Accept=[application/json], Content-Type=[application/json], Authorization=[Bearer REDACTED], Square-Version=[2024-01-18], Content-Length=[314]}
Request body: {"idempotency_key":"SQT-a295c4eckc7e-1727877637317","checkout":{"amount_money":{"amount":472,"currency":"USD"},"tip_money":{"amount":22,"currency":"USD"},"order_id":"87tYCMKdoSqogsDQJeiiyubzeELZY","device_options":{"device_id":"846CS108A2000949","tip_settings":{"allow_tipping":false},"skip_receipt_screen":true}}}

Response:

2024-10-02 14:00:37 - SQUARE-TERMINAL API API  <<<<<<<<<< Status = [400] path = [https://connect.squareup.com/v2/terminals/checkouts]
Status code  : 400
Status text  : Bad Request
Headers      : {Date=[Wed, 02 Oct 2024 14:00:37 GMT], Content-Type=[application/json], Content-Length=[180], Connection=[keep-alive], CF-Ray=[8cc538414801c980-IAD], CF-Cache-Status=[DYNAMIC], Strict-Transport-Security=[max-age=631152000; includeSubDomains; preload], frame-options=[DENY], square-version=[2024-01-18], squareup--connect--v2--common--versionmetadata-bin=[CgoyMDI0LTAxLTE4], x-content-type-options=[nosniff], x-envoy-decorator-operation=[/v2/terminals/**], x-frame-options=[DENY], x-sq-dc=[aws], x-sq-region=[us-east-1], x-xss-protection=[1; mode=block], Vary=[Accept-Encoding], Server=[cloudflare]}
Response body: {"errors": [{"code": "BAD_REQUEST","detail": "The checkout's total amount=472 does not match the order's total amount=494","field": "amount","category": "INVALID_REQUEST_ERROR"}]}

This has occurred to the same merchant. Our order placing and payment flow is the same for both instances.

Why has this happened?

Are you seeing that error in the API logs? I took a look at the application and I don’t see it in the logs. Can you confirm the application ID? :slightly_smiling_face:

Hi Bryan,

App ID: sq0idp-TpHen_F96miOUr07zsUKTw

The issue happened on the 2nd of October. We can’t see logs before the 7th on Square. The logs I have added are from our side. We have logged the requests and the responses. These are accurate.

Hey @nHiRanZ, I don’t see anything on the surface that’s wrong with these requests. However, the amount of information we have available is limited due to these being older requests that have expired from logs.

Do you have any more recent examples of this? If not, please do reach back out if you run into the issue again!

Hi Josh,

More recent occurrence on 4th of November 2024:

Request:

2024-11-04 02:03:27 - SQUARE-TERMINAL API >>>>>>>>>> 
URI         : https://connect.squareup.com/v2/terminals/checkouts
Method      : POST
Headers     : {Accept=[application/json], Content-Type=[application/json], Authorization=[Bearer REDACTED], Square-Version=[2024-01-18], Content-Length=[317]}
Request body: {"idempotency_key":"SQT-af9870a5dfc9f-1730685807554","checkout":{"amount_money":{"amount":4768,"currency":"USD"},"tip_money":{"amount":433,"currency":"USD"},"order_id":"Na4erlH4e7Si3A109VBmlcXoCNLZY","device_options":{"device_id":"349CS149B4Z06794","tip_settings":{"allow_tipping":false},"skip_receipt_screen":true}}}

Response:

2024-11-04 02:03:27 - SQUARE-TERMINAL API API  <<<<<<<<<< Status = [400] path = [https://connect.squareup.com/v2/terminals/checkouts]
Status code  : 400
Status text  : Bad Request
Headers      : {Date=[Mon, 04 Nov 2024 02:03:27 GMT], Content-Type=[application/json], Content-Length=[182], Connection=[keep-alive], CF-Ray=[8dd107194aae07b9-IAD], CF-Cache-Status=[DYNAMIC], Strict-Transport-Security=[max-age=631152000; includeSubDomains; preload], frame-options=[DENY], square-version=[2024-01-18], squareup--connect--v2--common--versionmetadata-bin=[CgoyMDI0LTAxLTE4], x-content-type-options=[nosniff], x-envoy-decorator-operation=[/v2/terminals/**], x-frame-options=[DENY], x-sq-dc=[aws], x-sq-region=[us-east-1], x-xss-protection=[1; mode=block], Vary=[Accept-Encoding], Server=[cloudflare]}
Response body: {"errors": [{"code": "BAD_REQUEST","detail": "The checkout's total amount=4768 does not match the order's total amount=5201","field": "amount","category": "INVALID_REQUEST_ERROR"}]}

Image:

Hey @nHiRanZ, thank you that’s very helpful!

It looks like there are duplicate checkouts happening here. I saw in your logs that there are two CreateTerminalCheckout attempts being made for order Na4erlH4e7Si3A109VBmlcXoCNLZY. The first one (idempotency_key: SQT-af9870a5dfc9f-1730685783682) succeeds, including the tip_money. Checkout ksEh4uBT5eYqO is successfully created.

However after that, another CreateTerminalCheckout request is made for the same order (SQT-af9870a5dfc9f-1730685807554). Because the order was already paid and a tip was added, the order total has changed and you’re getting that BAD_REQUEST error.

I’d recommend looking into your app logic to confirm why this second CreateTerminalCheckout request is being made.

Let me know if you have any follow up questions!