Skip to main content
POST
/
v2
/
checkout

Create Checkout Session

Create a checkout session for a customer. Returns a checkout URL where the customer completes payment on Gale’s hosted page. Gale handles card collection, eligibility detection, and LMN flow automatically.

Authentication

Authorization: Bearer glm_test_YOUR_API_KEY

Request Body

{
  "customer": {
    "email": "customer@example.com",
    "first_name": "Jane",
    "last_name": "Doe",
    "phone": "+1-555-123-4567"
  },
  "line_items": [
    {
      "merchant_product_id": "PROD-001",
      "name": "Digital Thermometer",
      "quantity": 1,
      "price_cents": 2995
    }
  ],
  "shipping_info": {
    "address_line_1": "123 Main St",
    "city": "New York",
    "state": "NY",
    "zip": "10001",
    "country": "US"
  },
  "amounts": {
    "shipping_cents": 995,
    "tax_cents": 245
  },
  "success_url": "https://yoursite.com/success",
  "cancel_url": "https://yoursite.com/cart",
  "metadata": {
    "order_id": "ORDER-12345"
  }
}

Parameters

ParameterTypeRequiredDescription
customerobjectYesCustomer information
customer.emailstringYesCustomer email
customer.first_namestringYesCustomer first name
customer.last_namestringYesCustomer last name
customer.phonestringNoPhone number (E.164 format)
line_itemsarrayYesProducts being purchased
line_items[].merchant_product_idstringYesYour product ID
line_items[].namestringYesProduct name
line_items[].quantityintegerYesQuantity
line_items[].price_centsintegerYesUnit price in cents
shipping_infoobjectYesShipping address
billing_infoobjectNoBilling address (defaults to shipping)
amountsobjectNoAdditional amounts
amounts.shipping_centsintegerNoShipping cost in cents
amounts.tax_centsintegerNoTax in cents
amounts.discount_centsintegerNoDiscount in cents
success_urlstringYesRedirect URL after successful payment
cancel_urlstringNoRedirect URL if customer cancels
metadataobjectNoCustom key-value pairs
payment_typeenumNoone_time or subscription
subscriptionobjectNoRequired if payment_type is subscription

Response

{
  "id": "checkout_abc123xyz",
  "checkout_url": "https://checkout.withgale.com/c/checkout_abc123xyz",
  "status": "open",
  "customer": {
    "email": "customer@example.com",
    "first_name": "Jane",
    "last_name": "Doe"
  },
  "line_items": [
    {
      "merchant_product_id": "PROD-001",
      "name": "Digital Thermometer",
      "quantity": 1,
      "price_cents": 2995,
      "is_hsa_eligible": true,
      "eligibility_type": "auto_substantiation"
    }
  ],
  "amounts": {
    "subtotal_cents": 2995,
    "hsa_fsa_amount_cents": 2995,
    "regular_amount_cents": 0,
    "shipping_cents": 995,
    "tax_cents": 245,
    "total_cents": 4235
  },
  "expires_at": "2025-10-19T14:30:00Z",
  "created_at": "2025-10-18T14:30:00Z"
}

Examples

Basic Checkout

curl -X POST https://api.withgale.com/v2/checkout \
  -H "Authorization: Bearer glm_test_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": {
      "email": "customer@example.com",
      "first_name": "John",
      "last_name": "Smith"
    },
    "line_items": [
      {
        "merchant_product_id": "THERM-001",
        "name": "Digital Thermometer",
        "quantity": 1,
        "price_cents": 2995
      }
    ],
    "shipping_info": {
      "address_line_1": "456 Oak Ave",
      "city": "San Francisco",
      "state": "CA",
      "zip": "94102",
      "country": "US"
    },
    "amounts": {
      "shipping_cents": 500,
      "tax_cents": 200
    },
    "success_url": "https://yoursite.com/success",
    "cancel_url": "https://yoursite.com/cart"
  }'

With JavaScript

const createCheckout = async (cart) => {
  const response = await fetch('https://api.withgale.com/v2/checkout', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.GALE_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      customer: {
        email: cart.email,
        first_name: cart.firstName,
        last_name: cart.lastName
      },
      line_items: cart.items.map(item => ({
        merchant_product_id: item.sku,
        name: item.name,
        quantity: item.quantity,
        price_cents: item.price * 100
      })),
      shipping_info: cart.shippingAddress,
      amounts: {
        shipping_cents: cart.shipping * 100,
        tax_cents: cart.tax * 100
      },
      success_url: 'https://yoursite.com/success',
      cancel_url: 'https://yoursite.com/cart',
      metadata: {
        cart_id: cart.id
      }
    })
  });

  const checkout = await response.json();

  // Redirect to checkout
  window.location.href = checkout.checkout_url;
};

Subscription Checkout

curl -X POST https://api.withgale.com/v2/checkout \
  -H "Authorization: Bearer glm_test_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": {
      "email": "member@example.com",
      "first_name": "Jane",
      "last_name": "Doe"
    },
    "line_items": [
      {
        "merchant_product_id": "MEMBERSHIP-PREMIUM",
        "name": "Premium Membership",
        "quantity": 1,
        "price_cents": 9900
      }
    ],
    "payment_type": "subscription",
    "subscription": {
      "interval": "monthly",
      "trial_period_days": 14
    },
    "success_url": "https://yoursite.com/welcome",
    "cancel_url": "https://yoursite.com/pricing"
  }'

Checkout Status

StatusDescription
openCheckout session created, awaiting customer
completeCustomer completed payment
expiredSession expired (24 hours)

Webhooks

When payment is complete, receive webhook:
{
  "type": "order.created",
  "data": {
    "id": "ord_xyz789",
    "checkout_session_id": "checkout_abc123xyz",
    "status": "completed",
    "customer": {...},
    "line_items": [...]
  }
}
See Webhooks Reference.

Errors

Status CodeError CodeDescription
400invalid_requestMissing or invalid parameters
401unauthorizedInvalid API key
422validation_errorField validation failed