# How to take your first payment (https://developer.godaddy.com/en/docs/api-users/commerce/accept-payments/first-payment)

---
title: How to take your first payment
navLabel: Take your first payment
description: >-
  Charge one card end to end through hosted checkout, confirm it in the
  transaction record, then refund it.
keywords: >-
  first payment, test a payment, hosted checkout quickstart,
  createCheckoutSession, confirm a payment, list transactions, refund a payment,
  GoDaddy Payments
agentNotes:
  permissions:
    - GoDaddy Payments account on the business that owns the store
  scopes:
    - 'commerce.checkout-session:write'
    - 'commerce.transaction:read'
  idempotent: false
  destructive: false
  failureRecovery: >-
    This procedure charges a real card in production. A failure creating the
    session means the token, its scope, the storeId, the order, or the return
    URLs are wrong, and no money has moved. Session creation isn't idempotent,
    so calling it again creates another session. Reuse the session url you
    already have. Refund the payment after you confirm it.
related:
  guides:
    - title: How to get set up to accept payments
      href: /docs/api-users/commerce/accept-payments/before-you-start
    - title: How to use hosted checkout
      href: /docs/api-users/commerce/accept-payments/online-payments/hosted
    - title: How to create a checkout session
      href: /docs/api-users/commerce/accept-payments/online-payments/create-session
    - title: How to view transactions
      href: /docs/api-users/commerce/manage-orders-and-customers/transaction
  concepts:
    - title: About accepting payments
      href: /docs/api-users/commerce/accept-payments
    - title: About online payments
      href: /docs/api-users/commerce/accept-payments/online-payments
pageId: 25bca505-1d47-492b-bc6a-cb2733822348
---

## Overview

This page charges one card through hosted checkout, confirms the payment in the transaction record, and refunds it. Hosted checkout is the shortest path: it needs no checkout UI code and no terminal.

Your server creates a checkout session with `createCheckoutSession`, and the session returns a `url` for a checkout page GoDaddy hosts. You pay on that page with your own card. `GET /v2/commerce/stores/{storeId}/transactions` then lists the store's transactions, newest first, so you can confirm the money moved.

Every request goes to production. Use your own card and a small amount, then refund it.

## Prerequisites

The following prerequisites are required before you can take your first payment:

* a GoDaddy Payments account with an active store, and your `storeId`
* a Personal Access Token (PAT) with the `commerce.checkout-session:write` and `commerce.transaction:read` scopes
* public HTTPS pages for a completed payment and a cancelled one

Go to [How to get set up to accept payments](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/before-you-start) for the account, store, and token.

Checkout rejects loopback URLs like `localhost` and `127.0.0.1` before creating the session, so local development needs a tunnel that gives you a public hostname.

## Take a payment

The following procedure charges one card and refunds it.

1. Install the package:

   ```bash tab="npm"
   npm install @godaddy/react
   ```

   ```bash tab="pnpm"
   pnpm add @godaddy/react
   ```

   ```bash tab="yarn"
   yarn add @godaddy/react
   ```

2. Create a session for a one dollar item and log its URL and draft order ID:

   ```typescript
   import { createCheckoutSession } from '@godaddy/react/server';

   const storeId = process.env.STORE_ID;
   const personalAccessToken = process.env.GODADDY_PAT;
   if (!storeId || !personalAccessToken) {
     throw new Error('Set STORE_ID and GODADDY_PAT');
   }

   const session = await createCheckoutSession(
     {
       storeId,
       returnUrl: 'https://your-app.example.com/cancel',
       successUrl: 'https://your-app.example.com/success',
       lineItems: [
         {
           quantity: 1,
           lineItemData: {
             name: 'Test item',
             priceData: { currencyCode: 'USD', unitAmount: 100 },
           },
         },
       ],
       paymentMethods: {
         card: { processor: 'godaddy', checkoutTypes: ['standard'] },
       },
     },
     {
       auth: { personalAccessToken },
     },
   );
   if (!session?.url) {
     throw new Error('Checkout returned no session URL');
   }

   console.log(session.url, session.draftOrder?.id);
   ```

3. Open the logged URL and pay with your own card.

   Checkout redirects you to your `successUrl` after the payment succeeds.

4. List the store's most recent transactions:

   ```bash tab="curl"
   curl -s "https://api.godaddy.com/v2/commerce/stores/${STORE_ID}/transactions?pageSize=20&sortOrder=DESC" \
     -H "Authorization: Bearer $GODADDY_PAT"
   ```

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

   const params = new URLSearchParams({ pageSize: "20", sortOrder: "DESC" });
   const res = await fetch(
     `https://api.godaddy.com/v2/commerce/stores/${storeId}/transactions?${params}`,
     { headers: { Authorization: `Bearer ${token}` } }
   );
   const data = await res.json();
   console.log(data);
   ```

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

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

   res = requests.get(
       f"https://api.godaddy.com/v2/commerce/stores/{store_id}/transactions",
       params={"pageSize": 20, "sortOrder": "DESC"},
       headers={"Authorization": f"Bearer {token}"},
   )
   res.raise_for_status()
   print(res.json())
   ```

   ```go tab="Go"
   package main

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

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

       url := fmt.Sprintf(
           "https://api.godaddy.com/v2/commerce/stores/%s/transactions?pageSize=20&sortOrder=DESC",
           storeId,
       )
       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 {
           panic(fmt.Sprintf("unexpected status %d", res.StatusCode))
       }

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

5. Find the transaction with a `references` entry whose `value` matches the session's `draftOrder.id`:

   ```js
   const draftOrderId = "<DRAFT_ORDER_ID>";

   const match = data.items.find((transaction) =>
     transaction.references?.some((ref) => ref.value === draftOrderId),
   );
   console.log(match?.transactionId, match?.status);
   ```

6. Refund the payment from your Commerce dashboard.

Go to [How to view transactions](https://developer.godaddy.com/docs/api-users/commerce/manage-orders-and-customers/transaction) for the fields each transaction returns.

A working payment confirms the following four things:

* The token carries the right scope.
* The store is active and can take money.
* Your return URLs are public.
* Your server can create a session.

Go to [How to create a checkout session](https://developer.godaddy.com/docs/api-users/commerce/accept-payments/online-payments/create-session) to build the session route your integration will use.
