API ReferenceEdge Functions

Edge Functions API

Complete request/response reference for Supabase Edge Functions.

process-payment

POST /functions/v1/process-payment

Headers

HeaderValue
Content-Typeapplication/json
AuthorizationBearer {SUPABASE_ANON_KEY}

Request Body

{
  "source_id": string,        // Card nonce or Apple Pay token
  "amount": number,           // Amount in cents (e.g., 495 = $4.95)
  "currency": string,         // "USD"
  "idempotency_key": string,  // UUID for duplicate prevention
  "note": string | undefined  // Optional payment note
}

Response (200)

{
  "payment_id": string,       // Square payment ID
  "order_id": string | null,  // Square order ID
  "status": string,           // "COMPLETED"
  "amount": number,           // Amount charged (cents)
  "currency": string          // "USD"
}

Error Responses

StatusBodyCause
400{ "error": "Missing required fields..." }Missing sourceId, amount, currency, or idempotencyKey
405{ "error": "Method not allowed" }Not a POST request
500{ "error": "Square configuration missing" }Missing environment variables
500{ "error": "..." }Square API error

cURL Example

curl -X POST \
  'https://YOUR-PROJECT.supabase.co/functions/v1/process-payment' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY' \
  -d '{
    "source_id": "cnon:card-nonce-ok",
    "amount": 495,
    "currency": "USD",
    "idempotency_key": "550e8400-e29b-41d4-a716-446655440000",
    "note": "Caffe Latte - Medium, Oat Milk"
  }'

sync-square-order

POST /functions/v1/sync-square-order

Headers

HeaderValue
Content-Typeapplication/json
AuthorizationBearer {SUPABASE_ANON_KEY}

Request Body

{
  "orderId": string,
  "orderNumber": string,       // e.g., "SC-A042"
  "items": [
    {
      "name": string,
      "quantity": number,
      "unitPrice": number,     // cents
      "totalPrice": number,    // cents
      "notes": string | undefined,
      "modifiers": [
        {
          "name": string,
          "priceAdjustment": number  // cents
        }
      ]
    }
  ],
  "subtotal": number,         // cents
  "tax": number,              // cents
  "tip": number,              // cents
  "total": number,            // cents
  "idempotencyKey": string
}

Response (200)

{
  "squareOrderId": string     // Square order ID
}

Error Responses

StatusBodyCause
400{ "error": "Missing required fields: orderId, items" }Missing required data
405{ "error": "Method not allowed" }Not a POST request
500{ "error": "Square configuration missing" }Missing environment variables
500{ "error": "..." }Square API error

cURL Example

curl -X POST \
  'https://YOUR-PROJECT.supabase.co/functions/v1/sync-square-order' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY' \
  -d '{
    "orderId": "abc-123",
    "orderNumber": "SC-A042",
    "items": [
      {
        "name": "Caffe Latte",
        "quantity": 1,
        "unitPrice": 575,
        "totalPrice": 575,
        "modifiers": [
          { "name": "Oat Milk", "priceAdjustment": 80 }
        ]
      }
    ],
    "subtotal": 575,
    "tax": 49,
    "tip": 100,
    "total": 724,
    "idempotencyKey": "550e8400-e29b-41d4-a716-446655440000"
  }'