Skip to main content

Verify a locked cart

Use a sandbox cart to check how the gateway responds to an invoice hash mismatch and an incorrect total. Set PA to the provisioned HTTPS gateway origin and use the gateway key, tenant ID and merchant ID for that environment.

# 1. Lock a $42.00 cart
curl -s -X POST "$PA/v1/negotiate" -H 'Content-Type: application/json' -H "X-API-Key: $IXOPAY_GATEWAY_KEY" -H "tx-tokenex-id: $TOKENEX_ID" -d '{
"agentId":"demo","cartParams":{"merchantId":"<your-merchant-id>","currency":"USD","amount":4200,
"items":[{"id":"SKU-A","name":"Lip Treat","price":4200,"qty":1}]}}'
# → note sessionId and invoiceHash

# 2. Complete the test checkout with a different invoice hash
curl -s -i -X POST "$PA/v1/checkout/complete" -H 'Content-Type: application/json' -H "X-API-Key: $IXOPAY_GATEWAY_KEY" -H "tx-tokenex-id: $TOKENEX_ID" \
-d '{"sessionId":"<sessionId>","uttToken":"utt_test","invoiceHash":"0000000000000000000000000000000000000000000000000000000000000000","protocol":"TOKENEX_DIRECT"}'

Expected: HTTP 401 with {"error":"INVOICE_HASH_MISMATCH","errorCategory":"AUTH_FAILURE"}, and the session is terminated. Negotiate again to retry.

Then try the arithmetic guard: lock the same cart with "amount": 999. Expect 400 INVALID_CART_STRUCTURE, because the amount does not equal the sum of the lines.

Now compute the hash yourself for the cart in step 1 with examples/invoice-hash.js and confirm it equals the invoiceHash you were given. That is exactly the check a safe agent performs before signing.