Skip to main content
POST
/
api
/
v1
/
cart

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.

Base URL

https://carts.withgale.com

Authentication

Authorization: Bearer glm_test_YOUR_API_KEY

Request Body

{
  "plugin_version": "1.0.1",
  "test_mode": false,
  "merchant_cart_id": "e17580b9-0637-405c-b507-28230f2db7ba",
  "customer": {
    "email": "Cleo_Pacocha79@yahoo.com",
    "first_name": "Hulda",
    "last_name": "Klocko",
    "phone": "271-970-2219",
    "timezone": "America/Chicago"
  },
  "metadata": {
    "platform": "SHOPIFY",
    "webhook_url": "https://your-server.com/payment-webhook"
  },
  "shipping_info": {
    "address_line_1": "901 L Street Northwest",
    "address_line_2": null,
    "state": "Washington DC",
    "city": "Washington",
    "zip": "20001",
    "country": "US"
  },
  "billing_info": {
    "address_line_1": "901 L Street Northwest",
    "address_line_2": null,
    "state": "Washington DC",
    "city": "Washington",
    "zip": "20001",
    "country": "US"
  },
  "shipping_amount": 0,
  "discount": 0,
  "tax_amount": 0,
  "success_url": "https://your-site.com/payment/success",
  "failure_url": "https://your-site.com/payment/failed",
  "line_items": [
    {
      "merchant_product_id": null,
      "name": "Shopify Product",
      "product_picture": "https://via.placeholder.com/150",
      "product_amount": 101,
      "quantity": 1,
      "currency_code": "USD"
    },
    {
      "merchant_product_id": 232,
      "name": "Shopify Product",
      "product_picture": "https://via.placeholder.com/150",
      "product_amount": 201,
      "quantity": 1,
      "currency_code": "USD"
    }
  ]
}

Parameters

ParameterTypeRequiredDescription
plugin_versionstringYesPlugin or integration version
test_modebooleanYesProcess transaction in test mode
merchant_cart_idstringYesUnique cart ID from your platform
customerobjectYesCustomer information
customer.emailstringYesCustomer email
customer.first_namestringYesCustomer first name
customer.last_namestringYesCustomer last name
customer.phonestringNoCustomer phone number
customer.timezonestringNoCustomer timezone (e.g., "America/Chicago")
line_itemsarrayYesProducts being purchased
line_items[].merchant_product_idstring or numberNoYour product ID (nullable for some platforms)
line_items[].namestringYesProduct name
line_items[].product_picturestringNoImage URL of the product
line_items[].product_amountintegerYesUnit price of the product in cents
line_items[].quantityintegerYesQuantity
line_items[].currency_codestringYesCurrency (e.g., "USD")
shipping_infoobjectYesShipping address
shipping_info.address_line_1stringYesAddress line 1
shipping_info.address_line_2stringNoAddress line 2
shipping_info.statestringYesState
shipping_info.citystringYesCity
shipping_info.zipstringYesZIP/Postal code
shipping_info.countrystringYesCountry code (e.g., "US")
billing_infoobjectYesBilling Address
billing_info.address_line_1stringYesAddress line 1
billing_info.address_line_2stringYesAddress line 2
billing_info.statestringYesState
billing_info.citystringYesCity
billing_info.zipstringYesZip/postal code
billing_info.countrystringYesCountry code (e.g., "US")
shipping_amountintegerNoShipping fee amount in cents
discountintegerNoDiscount amount in cents
tax_amountintegerNoTax amount in cents
success_urlstringYesRedirect URL after successful payment
failure_urlstringYesRedirect URL if payment fails
metadataobjectNoCustom key-value pairs
metadata.platformstringNoPlatform name (e.g., SHOPIFY)
metadata.webhook_urlstringNoURL to receive payment status webhook (recommended)

Response

{
  "success": true,
  "payment": {
    "redirect_url": "https://checkout.staging.withgale.com/checkout/01K94XXXXXXXXXXXXXXXX",
    "cart_id": "01K94XXXXXXXXXXXXXXXX",
    "redirect_mode": "modal"
  }
}

Examples

Basic Checkout

curl --location 'https://carts.withgale.com/api/v1/cart' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data-raw '{
  "plugin_version": "1.0.1",
  "test_mode": false,
  "merchant_cart_id": "e17580b9-0637-405c-b507-28230f2db7ba",
  "customer": {
    "email": "Cleo_Pacocha79@yahoo.com",
    "first_name": "Hulda",
    "last_name": "Klocko",
    "phone": "271-970-2219",
    "timezone": "America/Chicago"
  },
  "metadata": {
    "platform": "CUSTOM",
    "webhook_url": "https://your-server.com/payment-webhook"
  },
  "shipping_info": {
    "address_line_1": "901 L Street Northwest",
    "state": "Washington DC",
    "city": "Washington",
    "zip": "20001",
    "country": "US"
  },
  "billing_info": {
    "address_line_1": "901 L Street Northwest",
    "state": "Washington DC",
    "city": "Washington",
    "zip": "20001",
    "country": "US"
  },
  "shipping_amount": 0,
  "discount": 0,
  "tax_amount": 0,
  "success_url": "https://your-site.com/payment/success",
  "failure_url": "https://your-site.com/payment/failed",
  "line_items": [
    {
      "merchant_product_id": null,
      "name": "Shopify Product",
      "product_picture": "https://via.placeholder.com/150",
      "product_amount": 101,
      "quantity": 1,
      "currency_code": "USD"
    },
    {
      "merchant_product_id": 232,
      "name": "Shopify Product",
      "product_picture": "https://via.placeholder.com/150",
      "product_amount": 201,
      "quantity": 1,
      "currency_code": "USD"
    }
  ]
}'

With JavaScript

const createCheckoutSession = async (cart) => {
  try {
    const response = await fetch('https://carts.withgale.com/api/v1/cart', {
      method: 'POST',
      headers: {
        "Authorization": `Bearer ${process.env.GALE_API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        plugin_version: "1.0.1",
        test_mode: false,
        merchant_cart_id: cart.id,
        customer: {
          email: cart.email,
          first_name: cart.firstName,
          last_name: cart.lastName,
          phone: cart.phone,
          timezone: cart.timezone
        },
        metadata: {
          platform: "CUSTOM",
          webhook_url: "https://your-server.com/payment-webhook"
        },
        shipping_info: cart.shippingAddress,
        billing_info: cart.billingAddress,
        shipping_amount: cart.shippingAmount,
        discount: cart.discount || 0,
        tax_amount: cart.taxAmount || 0,
        success_url: "https://your-site.com/payment/success",
        failure_url: "https://your-site.com/payment/failed",
        line_items: cart.items.map(item => ({
          merchant_product_id: item.id ?? null,
          name: item.name,
          product_picture: item.image,
          product_amount: item.price,
          quantity: item.quantity,
          currency_code: item.currency || "USD"
        }))
      })
    });

    const data = await response.json();

    if (!data.success) {
      console.error("Failed to create checkout session:", data);
      return;
    }

    // Redirect customer to Gale Hosted Checkout
    window.location.href = data.payment.redirect_url;

  } catch (error) {
    console.error("Error creating checkout session:", error);
  }
};

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