GoDaddy

How to charge a card on a terminal

View as Markdown

Send a SALE payment request to a GoDaddy terminal, then get the payment request until it reaches COMPLETED or FAILED.

Overview

This page covers sending a SALE to a GoDaddy terminal with the Payment Requests API at https://api.godaddy.com/v1/commerce, then reading the outcome. POST /v1/commerce/stores/{storeId}/payment-requests sends the request to the terminal and returns 202 Accepted with a paymentRequestId before the customer pays. GET /v1/commerce/stores/{storeId}/payment-requests/{paymentRequestId} returns the current status, so you get the payment request until it's COMPLETED or FAILED.

Save the paymentRequestId you generate with your order. A retry with the same ID returns the existing request instead of charging twice. Send a new X-Request-Id on every create call. Go to About Payment Requests for the full retry rules, and Payment request reference for amount and the other field limits.

Get the payment request every 5 seconds or so. The result can arrive seconds or hours after create. A terminal that goes offline can leave the request in QUEUED or IN_PROGRESS, and GoDaddy doesn't time it out. Stop polling after a timeout you choose, like 3 minutes, keep the order pending, and check it later with the list call. Go to Handle rate limits for how many calls your token can make. Go to How to handle the result to have GoDaddy push status updates to your server instead of polling.

Prerequisites

The following prerequisites are required before you can charge a card on a terminal:

Charge a card

The following procedure charges a card on a terminal.

  1. Create a SALE payment request:

    curl -sS -w "\n%{http_code}\n" -X POST "https://api.godaddy.com/v1/commerce/stores/$STORE_ID/payment-requests" \
      -H "Authorization: Bearer $GODADDY_PAT" \
      -H "Content-Type: application/json" \
      -H "X-Request-Id: $(uuidgen)" \
      -d '{
        "paymentRequestId": "'"$PAYMENT_REQUEST_ID"'",
        "type": "SALE",
        "deviceId": "'"$DEVICE_ID"'",
        "amount": {
          "amount": 5000,
          "currency": "USD",
          "amountType": "SIMPLE"
        }
      }'
  2. Get the payment request:

    curl -sS -w "\n%{http_code}\n" "https://api.godaddy.com/v1/commerce/stores/$STORE_ID/payment-requests/$PAYMENT_REQUEST_ID" \
      -H "Authorization: Bearer $GODADDY_PAT"
  3. Repeat step 2 every 5 seconds until status is COMPLETED or FAILED.

Don't treat 202 as paid

Wait until status is COMPLETED before you fulfill the order or print a receipt.

Add an order reference and a callback

Add references to match the payment to your order, and callbackConfig to have GoDaddy send the result to your server. The following fields go in the create body next to type and amount:

{
  "references": [{ "type": "CUSTOM", "value": "$REFERENCE_ID" }],
  "callbackConfig": {
    "url": "$CALLBACK_URL",
    "authentication": { "type": "hmac", "value": "$WEBHOOK_SECRET" },
    "payloadConfig": {
      "includeFields": ["paymentRequestId", "type", "amount", "transactionIds"]
    }
  }
}

Go to How to handle the result to verify the callback.

Example responses

Create response

202 Accepted returns a new payment request with status QUEUED. A retry with an existing paymentRequestId returns that request's current status instead. The following trimmed response is a new request:

{
  "paymentRequestId": "$PAYMENT_REQUEST_ID",
  "type": "SALE",
  "status": "QUEUED",
  "amount": { "amount": 5000, "currency": "USD", "amountType": "SIMPLE" },
  "storeId": "$STORE_ID",
  "deviceId": "$DEVICE_ID"
}

Get response

The following trimmed response is a completed request, which lists its transactionIds:

{
  "paymentRequestId": "$PAYMENT_REQUEST_ID",
  "type": "SALE",
  "status": "COMPLETED",
  "amount": { "amount": 5000, "currency": "USD", "amountType": "SIMPLE" },
  "storeId": "$STORE_ID",
  "deviceId": "$DEVICE_ID",
  "transactionIds": ["$TRANSACTION_ID"]
}

Common errors

The following table lists common situations when you charge a card and what to do:

SituationMost likely causeWhat to do
Create times out or returns 5XXThe response didn't reach you, so the request might existRetry with the same paymentRequestId and a new X-Request-Id
EXTERNAL_SERVICE_ERROR in name, with any statusAn unknown deviceId, or the terminal rejected the requestCheck deviceId, then retry with a new paymentRequestId
Any other 400A body field failed validationRead name and details[]
401A missing, expired, or invalid PAT, a missing scope, or a PAT without access to this storeCreate a token with both commerce.payment-request scopes for the account that owns the store
409 with DUPLICATE_REQUESTAn X-Request-Id you already sent within 30 minutesRetry with a new X-Request-Id
429Rate limit exceededWait, then retry with the same paymentRequestId and a new X-Request-Id
Get returns 404A wrong storeId or paymentRequestId, or a create that GoDaddy never storedConfirm both values. When create timed out, retry it with the same paymentRequestId
Status stays QUEUEDThe terminal is offline, or deviceId names the wrong terminalCheck that the terminal is on and connected, and that deviceId names a terminal in this store. Keep the order pending, and don't reuse that paymentRequestId for a new charge. If the request later reaches COMPLETED, fulfill the order or refund it

When you can't tell whether create succeeded, get the payment request by its paymentRequestId before you retry. A 404 means GoDaddy didn't store it, so retry create with the same paymentRequestId. FAILED means retry with a new paymentRequestId. Any other status means the request is live, so keep polling.

A request that fails at create doesn't send a callback. Read the create response, or get the payment request, instead of waiting for one. Go to Payment request reference for every status code, the 400 codes, and the error body. Go to How to connect your terminal for what to check when a request stays QUEUED.

Last updated on

How is this guide?

On this page