How to handle the result
View as MarkdownReceive and verify HMAC-signed payment request callbacks, and list payment requests to find results your server missed.
Overview
This page covers how GoDaddy pushes payment request status updates to your server, and how to find results your server missed. GoDaddy sends a callback to the callbackConfig.url you set on create. GET /v1/commerce/stores/{storeId}/payment-requests on the Payment Requests API lists a store's payment requests, so you can reconcile after your endpoint was down. Go to How to charge a card on a terminal to get one payment request by ID instead.
Callbacks with authentication.type set to hmac carry an X-Signature header: the hex-encoded HMAC-SHA256 of the raw body concatenated with the X-Timestamp and X-Request-Id values, keyed with your secret. X-Timestamp is in epoch seconds. GoDaddy signs each scheduled retry again with the current time and a new X-Request-Id, so a 300-second replay window covers the whole retry schedule. The X-Request-Id isn't the one you sent on create.
Your endpoint returns 401 for a callback whose X-Timestamp is outside your replay window, or whose signature doesn't match. Inside the window, a copied callback still verifies, so the duplicate check on paymentRequestId and status keeps it from updating an order twice.
The handlers on this page listen on http://localhost:3000/webhooks/payment-requests and use a 300-second window. The Python handler needs Flask, and the Python list example needs requests. The curl tab doesn't verify anything. It signs and sends a test callback to that local URL, so you can check your handler before GoDaddy calls it. Go to Payment request reference for callback fields, statuses, list filters, and error codes.
Prerequisites
The following prerequisites are required before you can handle the result:
- the
paymentRequestIdof a request from How to charge a card on a terminal - a Personal Access Token (PAT) with the
commerce.payment-request:readscope for listing and reading status - a public HTTPS endpoint and the shared secret you sent in
callbackConfig.authentication.value, when you use callbacks
Configure the callback
Send callbackConfig in the create body with your url, at least one field in payloadConfig.includeFields, and authentication.type set to hmac. Use none during development only. Don't log create requests or responses, because they carry your callback credentials.
GoDaddy sends one callback per payment request, after the terminal reports the result. Read status from that callback instead of assuming the payment succeeded. Return 2XX within 5 seconds to acknowledge it. Return 5XX for a temporary failure on your side, so GoDaddy retries instead of dropping the callback. The same callback can reach you more than once.
Go to Payment request reference for every callbackConfig field, the includeFields values, the authentication types, and the retry schedule.
Verify the callback signature
The following procedure verifies a callback signature.
-
Read the raw request body before any JSON parsing.
-
Check that
X-Timestampis inside your replay window. -
Compute
hex(HMAC-SHA256(secret, rawBody + X-Timestamp + X-Request-Id))from the headers on the callback. -
Compare the result with
X-Signaturein constant time:# Sign a sample body the way GoDaddy does, then send it to your local handler. BODY='{"paymentRequestId":"'"$PAYMENT_REQUEST_ID"'","type":"SALE","status":"COMPLETED"}' TIMESTAMP=$(date +%s) REQUEST_ID=$(uuidgen) SIGNATURE=$(printf '%s%s%s' "$BODY" "$TIMESTAMP" "$REQUEST_ID" \ | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | awk '{print $NF}') curl -sS -w "\n%{http_code}\n" -X POST "http://localhost:3000/webhooks/payment-requests" \ -H "Content-Type: application/json" \ -H "X-Signature: $SIGNATURE" \ -H "X-Timestamp: $TIMESTAMP" \ -H "X-Request-Id: $REQUEST_ID" \ -d "$BODY" -
Respond to the callback before you do slow work.
-
Read
statusfrom the verified callback body. -
Drop a callback whose
paymentRequestIdandstatusyou already processed.
List payment requests
GET /v1/commerce/stores/{storeId}/payment-requests returns a store's payment requests, newest update first. Without updatedAtAfter, the list covers the last day. Pass the response's pageToken, with the same filters, to get the next page.
The following procedure lists every payment request updated since UPDATED_AT_AFTER, like the start of an outage.
-
List the payment requests, one page at a time:
PAGE_TOKEN="" while :; do page=$(curl -sS -f -G "https://api.godaddy.com/v1/commerce/stores/$STORE_ID/payment-requests" \ -H "Authorization: Bearer $GODADDY_PAT" \ --data-urlencode "updatedAtAfter=$UPDATED_AT_AFTER" \ --data-urlencode "pageSize=100" \ ${PAGE_TOKEN:+--data-urlencode "pageToken=$PAGE_TOKEN"}) || { echo "request failed" >&2; break; } jq -r '.items[]? | "\(.paymentRequestId) \(.status)"' <<< "$page" PAGE_TOKEN=$(jq -r '.pageToken // empty' <<< "$page") [ -n "$PAGE_TOKEN" ] || break done
Add status, deviceId, or type to the query to narrow the list, like status=FAILED for failed requests only.
Example responses
Callback
The following table lists the headers on an hmac callback:
| Header | Value |
|---|---|
Content-Type | application/json |
X-Signature | The hex-encoded HMAC-SHA256 signature |
X-Timestamp | The time GoDaddy signed this attempt, in epoch seconds |
X-Request-Id | A new UUID for this attempt |
GoDaddy sends the body as compact JSON, and field order can vary, so verify the raw bytes. The following body is for the includeFields in Add an order reference and a callback, formatted for reading:
{
"paymentRequestId": "$PAYMENT_REQUEST_ID",
"type": "SALE",
"status": "COMPLETED",
"amount": { "amount": 5000, "currency": "USD", "amountType": "SIMPLE" },
"transactionIds": ["$TRANSACTION_ID"]
}List response
A response with pageToken has more results. The last page has no pageToken. pageToken is an opaque string, so pass it back unchanged. The following example is a page with more results:
{
"items": [
{
"paymentRequestId": "$PAYMENT_REQUEST_ID",
"type": "SALE",
"status": "COMPLETED",
"amount": { "amount": 5000, "currency": "USD", "amountType": "SIMPLE" }
}
],
"pageToken": "$PAGE_TOKEN"
}Common errors
The following table lists common situations when you handle the result and what to do:
| Situation | Most likely cause | What to do |
|---|---|---|
| No callback arrives | The request failed at create, delivery is still retrying, your endpoint returned 4XX, or the URL isn't public HTTPS | Get the payment request, then check callbackConfig.url |
| Every callback fails verification | The wrong secret, or a body your framework parsed before you signed it | Sign the raw bytes with the secret you sent on create |
Your handler rejects every X-Timestamp | Your server clock is more than 300 seconds off, and each 401 ends delivery | Sync your server clock with NTP |
| The same callback arrives twice | GoDaddy retried delivery | Drop a paymentRequestId and status you already processed |
| The list misses an older request | updatedAtAfter defaults to 1 day ago | Set updatedAtAfter to an earlier RFC 3339 date-time |
List returns 400 | An invalid filter value | Check updatedAtAfter, updatedAtBefore, and status |
List returns 401 | A missing, expired, or invalid PAT, or a missing scope | Create a token with commerce.payment-request:read |
Go to Payment request reference for every status code and the error body.
Last updated on
How is this guide?