# How to charge a card on a terminal (https://developer.godaddy.com/en/docs/api-users/commerce/accept-payments/in-person-payments/charge-a-card)

---
title: How to charge a card on a terminal
description: >-
  Send a SALE payment request to a GoDaddy terminal, then get the payment
  request until it reaches COMPLETED or FAILED.
keywords: >-
  charge a card on a terminal, create payment request, SALE, terminal payment,
  X-Request-Id, paymentRequestId, deviceId, poll payment request, payment
  request status, commerce.payment-request:write, commerce.payment-request:read,
  202 Accepted.
agentNotes:
  permissions:
    - GoDaddy Payments
  scopes:
    - 'commerce.payment-request:write'
    - 'commerce.payment-request:read'
  idempotent: true
  destructive: false
  failureRecovery: >-
    A 202 Accepted means GoDaddy received the request, not that the customer
    paid. When create times out or returns 5XX, retry with the same
    paymentRequestId and a new X-Request-Id to get the existing payment request;
    the retry body isn't compared. A repeated X-Request-Id within 30 minutes
    returns 409 DUPLICATE_REQUEST. After EXTERNAL_SERVICE_ERROR the payment
    request is stored as FAILED, so retry with a new paymentRequestId. GET the
    payment request until status is COMPLETED or FAILED. A request stays QUEUED
    while the terminal is offline; it doesn't time out, and the API can't cancel
    it. A 404 has an empty body. An expired token returns a 401 with
    UNAUTHORIZED_ACCESS; other 401 and 403 responses might have an empty body.
related:
  guides:
    - title: How to connect your terminal
      href: >-
        /docs/api-users/commerce/accept-payments/in-person-payments/connect-terminal
    - title: How to handle the result
      href: >-
        /docs/api-users/commerce/accept-payments/in-person-payments/handle-result
    - title: How to get set up to accept payments
      href: /docs/api-users/commerce/accept-payments/before-you-start
  concepts:
    - title: About accepting payments
      href: /docs/api-users/commerce/accept-payments
    - title: About Payment Requests
      href: /docs/api-users/commerce/accept-payments/in-person-payments
    - title: Payment request reference
      href: /docs/api-users/commerce/accept-payments/in-person-payments/reference
  apis:
    - title: Create a payment request
      href: /docs/references/rest/payments/create-payment-request
    - title: Get a payment request by ID
      href: /docs/references/rest/payments/get-payment-request-by-id
pageId: b7589aba-212a-42f2-8ea2-b8a61e5fa2a9
---

## 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](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/in-person-payments#idempotency) for the full retry rules, and [Payment request reference](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/in-person-payments/reference#field-limits) 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](https://developer.godaddy.com/docs/api-users/rate-limits) for how many calls your token can make. Go to [How to handle the result](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/in-person-payments/handle-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:

* the GoDaddy Payments account, `storeId`, and environment variables from [How to get set up to accept payments](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/before-you-start)
* a [Personal Access Token (PAT)](https://developer.godaddy.com/docs/api-users/auth/how-to) with the `commerce.payment-request:write` and `commerce.payment-request:read` scopes
* a terminal configured for your store and its `deviceId` in `DEVICE_ID`, from [How to connect your terminal](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/in-person-payments/connect-terminal)
* a new UUID for this charge in `PAYMENT_REQUEST_ID`, like the output of `export PAYMENT_REQUEST_ID=$(uuidgen)`

## Charge a card

The following procedure charges a card on a terminal.

1. Create a `SALE` payment request:

   ```bash tab="curl"
   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"
       }
     }'
   ```

   ```js tab="Node"
   import { randomUUID } from "node:crypto";

   const token = process.env.GODADDY_PAT;
   const storeId = process.env.STORE_ID;

   const res = await fetch(
     `https://api.godaddy.com/v1/commerce/stores/${storeId}/payment-requests`,
     {
       method: "POST",
       headers: {
         Authorization: `Bearer ${token}`,
         "Content-Type": "application/json",
         "X-Request-Id": randomUUID(),
       },
       body: JSON.stringify({
         paymentRequestId: process.env.PAYMENT_REQUEST_ID,
         type: "SALE",
         deviceId: process.env.DEVICE_ID,
         amount: { amount: 5000, currency: "USD", amountType: "SIMPLE" },
       }),
     }
   );
   if (res.status !== 202) {
     throw new Error(`${res.status} ${await res.text()}`);
   }
   const paymentRequest = await res.json();
   console.log(paymentRequest.paymentRequestId, paymentRequest.status);
   ```

   ```python tab="Python"
   import os, uuid, requests

   token = os.environ["GODADDY_PAT"]
   store_id = os.environ["STORE_ID"]

   res = requests.post(
       f"https://api.godaddy.com/v1/commerce/stores/{store_id}/payment-requests",
       headers={
           "Authorization": f"Bearer {token}",
           "Content-Type": "application/json",
           "X-Request-Id": str(uuid.uuid4()),
       },
       json={
           "paymentRequestId": os.environ["PAYMENT_REQUEST_ID"],
           "type": "SALE",
           "deviceId": os.environ["DEVICE_ID"],
           "amount": {"amount": 5000, "currency": "USD", "amountType": "SIMPLE"},
       },
   )
   res.raise_for_status()
   payment_request = res.json()
   print(res.status_code, payment_request["paymentRequestId"], payment_request["status"])
   ```

   ```go tab="Go"
   package main

   import (
   	"bytes"
   	"crypto/rand"
   	"encoding/json"
   	"fmt"
   	"io"
   	"net/http"
   	"os"
   )

   // newUUID returns a random version 4 UUID.
   func newUUID() string {
   	b := make([]byte, 16)
   	if _, err := rand.Read(b); err != nil {
   		panic(err)
   	}
   	b[6] = b[6]&0x0f | 0x40
   	b[8] = b[8]&0x3f | 0x80
   	return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
   }

   func main() {
   	token := os.Getenv("GODADDY_PAT")
   	storeId := os.Getenv("STORE_ID")

   	body, err := json.Marshal(map[string]any{
   		"paymentRequestId": os.Getenv("PAYMENT_REQUEST_ID"),
   		"type":             "SALE",
   		"deviceId":         os.Getenv("DEVICE_ID"),
   		"amount": map[string]any{
   			"amount":     5000,
   			"currency":   "USD",
   			"amountType": "SIMPLE",
   		},
   	})
   	if err != nil {
   		panic(err)
   	}

   	url := fmt.Sprintf(
   		"https://api.godaddy.com/v1/commerce/stores/%s/payment-requests",
   		storeId,
   	)
   	req, err := http.NewRequest("POST", url, bytes.NewReader(body))
   	if err != nil {
   		panic(err)
   	}
   	req.Header.Set("Authorization", "Bearer "+token)
   	req.Header.Set("Content-Type", "application/json")
   	req.Header.Set("X-Request-Id", newUUID())

   	res, err := http.DefaultClient.Do(req)
   	if err != nil {
   		panic(err)
   	}
   	defer res.Body.Close()

   	if res.StatusCode != http.StatusAccepted {
   		payload, _ := io.ReadAll(res.Body)
   		panic(fmt.Sprintf("%d %s", res.StatusCode, payload))
   	}

   	var paymentRequest map[string]any
   	if err := json.NewDecoder(res.Body).Decode(&paymentRequest); err != nil {
   		panic(err)
   	}
   	fmt.Println(paymentRequest["paymentRequestId"], paymentRequest["status"])
   }
   ```

2. Get the payment request:

   ```bash tab="curl"
   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"
   ```

   ```js tab="Node"
   const token = process.env.GODADDY_PAT;
   const storeId = process.env.STORE_ID;
   const paymentRequestId = process.env.PAYMENT_REQUEST_ID;

   const res = await fetch(
     `https://api.godaddy.com/v1/commerce/stores/${storeId}/payment-requests/${paymentRequestId}`,
     { headers: { Authorization: `Bearer ${token}` } }
   );
   if (!res.ok) {
     throw new Error(`${res.status} ${await res.text()}`);
   }
   const paymentRequest = await res.json();
   console.log(paymentRequest.status, paymentRequest.transactionIds);
   ```

   ```python tab="Python"
   import os, requests

   token = os.environ["GODADDY_PAT"]
   store_id = os.environ["STORE_ID"]
   payment_request_id = os.environ["PAYMENT_REQUEST_ID"]

   res = requests.get(
       f"https://api.godaddy.com/v1/commerce/stores/{store_id}/payment-requests/{payment_request_id}",
       headers={"Authorization": f"Bearer {token}"},
   )
   res.raise_for_status()
   payment_request = res.json()
   print(payment_request["status"], payment_request.get("transactionIds"))
   ```

   ```go tab="Go"
   package main

   import (
   	"encoding/json"
   	"fmt"
   	"io"
   	"net/http"
   	"os"
   )

   func main() {
   	token := os.Getenv("GODADDY_PAT")
   	storeId := os.Getenv("STORE_ID")
   	paymentRequestId := os.Getenv("PAYMENT_REQUEST_ID")

   	url := fmt.Sprintf(
   		"https://api.godaddy.com/v1/commerce/stores/%s/payment-requests/%s",
   		storeId,
   		paymentRequestId,
   	)
   	req, err := http.NewRequest("GET", url, nil)
   	if err != nil {
   		panic(err)
   	}
   	req.Header.Set("Authorization", "Bearer "+token)

   	res, err := http.DefaultClient.Do(req)
   	if err != nil {
   		panic(err)
   	}
   	defer res.Body.Close()

   	if res.StatusCode != http.StatusOK {
   		payload, _ := io.ReadAll(res.Body)
   		panic(fmt.Sprintf("%d %s", res.StatusCode, payload))
   	}

   	var paymentRequest map[string]any
   	if err := json.NewDecoder(res.Body).Decode(&paymentRequest); err != nil {
   		panic(err)
   	}
   	fmt.Println(paymentRequest["status"], paymentRequest["transactionIds"])
   }
   ```

3. Repeat step 2 every 5 seconds until `status` is `COMPLETED` or `FAILED`.

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`:

```json
{
  "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](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/in-person-payments/handle-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:

```json
{
  "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`:

```json
{
  "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:

| Situation                                           | Most likely cause                                                                          | What to do                                                                                                                                                                                                                                                  |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Create times out or returns `5XX`                   | The response didn't reach you, so the request might exist                                  | Retry with the same `paymentRequestId` and a new `X-Request-Id`                                                                                                                                                                                             |
| `EXTERNAL_SERVICE_ERROR` in `name`, with any status | An unknown `deviceId`, or the terminal rejected the request                                | Check `deviceId`, then retry with a new `paymentRequestId`                                                                                                                                                                                                  |
| Any other `400`                                     | A body field failed validation                                                             | Read `name` and `details[]`                                                                                                                                                                                                                                 |
| `401`                                               | A missing, expired, or invalid PAT, a missing scope, or a PAT without access to this store | Create a token with both `commerce.payment-request` scopes for the account that owns the store                                                                                                                                                              |
| `409` with `DUPLICATE_REQUEST`                      | An `X-Request-Id` you already sent within 30 minutes                                       | Retry with a new `X-Request-Id`                                                                                                                                                                                                                             |
| `429`                                               | Rate limit exceeded                                                                        | Wait, then retry with the same `paymentRequestId` and a new `X-Request-Id`                                                                                                                                                                                  |
| Get returns `404`                                   | A wrong `storeId` or `paymentRequestId`, or a create that GoDaddy never stored             | Confirm both values. When create timed out, retry it with the same `paymentRequestId`                                                                                                                                                                       |
| Status stays `QUEUED`                               | The terminal is offline, or `deviceId` names the wrong terminal                            | Check 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](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/in-person-payments/reference#status-codes) for every status code, the `400` codes, and the error body. Go to [How to connect your terminal](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/in-person-payments/connect-terminal#get-a-terminal-ready) for what to check when a request stays `QUEUED`.
