GoDaddy

How to take your first payment

View as Markdown

Charge one card end to end through hosted checkout, confirm it in the transaction record, then refund it.

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.

This charges a real card

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

    npm install @godaddy/react
  2. Create a session for a one dollar item and log its URL and draft order ID:

    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:

    curl -s "https://api.godaddy.com/v2/commerce/stores/${STORE_ID}/transactions?pageSize=20&sortOrder=DESC" \
      -H "Authorization: Bearer $GODADDY_PAT"
  5. Find the transaction with a references entry whose value matches the session's draftOrder.id:

    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 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 to build the session route your integration will use.

Last updated on

How is this guide?

On this page