{
  "openapi": "3.1.0",
  "info": {
    "title": "Snailgram Cards API",
    "version": "1.1.0",
    "description": "Buy pen-written cards through a buyer-paid Stripe checkout URL or USDC over x402 v2 on Base. No API key or account. Hosted Stripe checkout charges AUD and offers Link when enabled. Use server-side HTTP for purchases; browser CORS is available only on the public MCP endpoint.",
    "contact": {
      "email": "support@snailgram.com.au"
    }
  },
  "servers": [
    {
      "url": "https://snailgram.com.au",
      "description": "Production"
    }
  ],
  "externalDocs": {
    "url": "https://snailgram.com.au/developers"
  },
  "paths": {
    "/api/checkout/cards": {
      "get": {
        "operationId": "getCheckoutGuide",
        "summary": "Read the Stripe checkout guide",
        "responses": {
          "200": {
            "description": "How to create a hosted checkout URL.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createCardCheckout",
        "summary": "Prepare a card and return its Stripe payment URL",
        "description": "Charges the full card price, plus Express or International postage if chosen, in AUD. Creating a checkout does not pay or queue the card. Open payment_url for the buyer to pay. Stripe verifies payment through the existing signed webhook. Retry the exact request body with the same random Idempotency-Key to recover the URL; a new key creates another checkout. Five new attempts per buyer email per UTC day, 200 total per UTC day, plus WAF limits. Studio promotions and referral credits do not apply.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "A random UUID per order. Preserve this key and the exact body on retries.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CardOrder"
              },
              "example": {
                "card": "christmas-tree",
                "message": "Thanks for everything this year, Jo!",
                "sign_off": "Love, Sam",
                "sender_name": "Sam",
                "email": "sam@example.com",
                "recipient": {
                  "name": "Jo Park",
                  "street": "1 George Street",
                  "suburb": "Sydney",
                  "state": "NSW",
                  "postcode": "2000",
                  "country": "AU"
                },
                "postage": "regular",
                "card_size": "5x7"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout URL for an unpaid card, or current status for an existing paid card.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StripeCheckout"
                }
              }
            }
          },
          "202": {
            "description": "Another request is preparing this checkout. Retry with the same key and body shortly.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StripeCheckout"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or missing Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency-Key already used for a different request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Checkout expired. Prepare another with a new key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Request too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Cover refused or message does not fit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Checkout quota or WAF rate limit reached. The response may have no JSON body."
          },
          "503": {
            "description": "Checkout unavailable or preparation failed. No payment URL was issued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/checkout/cards/{reference}": {
      "get": {
        "operationId": "getCheckoutCardStatus",
        "summary": "Read a Stripe API order status",
        "description": "Never returns the payment URL, buyer email, message or recipient address. Payment status is updated by the signed Stripe webhook.",
        "parameters": [
          {
            "name": "reference",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^SG-[23456789A-HJKMNP-Z]{8}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current order status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StripeCheckout"
                }
              }
            }
          },
          "404": {
            "description": "No Stripe API order with this reference.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/x402/cards": {
      "get": {
        "operationId": "getCardGuide",
        "summary": "Read the purchase guide",
        "responses": {
          "200": {
            "description": "The live API guide and request field descriptions.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "buyCard",
        "summary": "Quote or buy a card",
        "description": "Without PAYMENT-SIGNATURE, returns 402 and a quote valid for 10 minutes. Retry the identical body with the quoted requirements signed by an x402 client. Confirm the address, message and price with the buyer before paying. The payer and nonce identify the order: preserve the same signed payment on retries. A new nonce can create another order. Both quote and paid requests count toward the WAF limit of 20 POSTs per IP per five minutes.",
        "parameters": [
          {
            "name": "PAYMENT-SIGNATURE",
            "in": "header",
            "required": false,
            "description": "Base64-encoded x402 v2 signed payment payload from an x402-compatible client. Scheme exact; USDC on Base (eip155:8453).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CardOrder"
              },
              "example": {
                "card": "christmas-tree",
                "message": "Thanks for everything this year, Jo!",
                "sign_off": "Love, Sam",
                "sender_name": "Sam",
                "email": "sam@example.com",
                "recipient": {
                  "name": "Jo Park",
                  "street": "1 George Street",
                  "suburb": "Sydney",
                  "state": "NSW",
                  "postcode": "2000",
                  "country": "AU"
                },
                "postage": "regular",
                "card_size": "5x7"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Paid card, or the existing order for the same signed payment.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CardStatus"
                }
              }
            }
          },
          "202": {
            "description": "Payment is being confirmed. Keep the reference, poll status and do not pay again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CardStatus"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, field or payment payload. Read error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Payment required, expired quote or changed order. Use this quote for the paid retry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            },
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 payment requirements. Preserve the signed extra.quote on the paid retry.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "description": "Payment conflict or cover could not be drawn. Read error before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Cover refused or message does not fit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Back off; the response may have no JSON body."
          },
          "503": {
            "description": "Payments, exchange rate or payment verification unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/x402/cards/{reference}": {
      "get": {
        "operationId": "getCardStatus",
        "summary": "Read an x402 order status",
        "description": "Returns no address or message. Regular and International post do not have delivery confirmation.",
        "parameters": [
          {
            "name": "reference",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^SG-[23456789A-HJKMNP-Z]{8}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CardStatus"
                }
              }
            }
          },
          "202": {
            "description": "Payment is being confirmed; do not create another payment.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CardStatus"
                }
              }
            }
          },
          "404": {
            "description": "No x402 card with this reference.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "StripeCheckout": {
        "type": "object",
        "required": [
          "reference",
          "status",
          "paid"
        ],
        "properties": {
          "reference": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "preparing checkout",
              "awaiting payment",
              "checkout failed",
              "checkout expired",
              "queued",
              "received",
              "posted",
              "delivered",
              "cancelled"
            ]
          },
          "paid": {
            "type": "boolean"
          },
          "arrive_by": {
            "type": "string",
            "format": "date"
          },
          "payment_url": {
            "type": "string",
            "format": "uri",
            "description": "Only returned by the idempotent POST while awaiting payment. Open this URL for the buyer to pay."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "price": {
            "type": "object",
            "properties": {
              "aud": {
                "type": "string"
              },
              "currency": {
                "const": "AUD"
              }
            }
          }
        }
      },
      "CardOrder": {
        "type": "object",
        "required": [
          "sender_name",
          "email",
          "recipient"
        ],
        "oneOf": [
          {
            "required": [
              "card"
            ],
            "not": {
              "required": [
                "image"
              ]
            }
          },
          {
            "required": [
              "image"
            ],
            "not": {
              "required": [
                "card"
              ]
            }
          }
        ],
        "properties": {
          "card": {
            "type": "string",
            "description": "A ready-made card id (the Snailgram MCP server's search_cards, or /browse). Or, instead:",
            "pattern": "^[a-z0-9-]{1,80}$"
          },
          "image": {
            "type": "string",
            "description": "Your own picture for the cover, JPEG or PNG, base64 (a data: URL is fine), 4 MB at most, at least 1200 pixels on its shorter side to print sharp. Printed as it is; refused if it isn't fit for a card."
          },
          "message": {
            "type": "string",
            "description": "The message written inside, up to 800 characters (160 on a fun size card), line breaks kept. It must be the sender's own words. Refused if the pen can't fit it on the card.",
            "maxLength": 800,
            "default": ""
          },
          "sign_off": {
            "type": "string",
            "description": "Optional, up to 40 characters, e.g. \"Love, Sam\".",
            "maxLength": 40,
            "default": ""
          },
          "sender_name": {
            "type": "string",
            "description": "Who it's from, for the back of the envelope.",
            "minLength": 1,
            "maxLength": 100
          },
          "email": {
            "type": "string",
            "description": "The buyer's email, for the receipt, posting and tracking emails and their Snailgram account.",
            "format": "email",
            "maxLength": 254
          },
          "recipient": {
            "$ref": "#/components/schemas/Recipient",
            "description": "{ name, street, suburb, state, postcode, country }. In Australia state is NSW, VIC, QLD, WA, SA, TAS, ACT or NT with a 4-digit postcode; overseas, country is a two-letter code, suburb the town or city."
          },
          "postage": {
            "type": "string",
            "description": "regular (default in Australia), express, or international (overseas).",
            "enum": [
              "regular",
              "express",
              "international"
            ]
          },
          "arrive_by": {
            "type": "string",
            "description": "Optional YYYY-MM-DD, no earlier than it can arrive; it's posted in time for it. Defaults to the earliest.",
            "format": "date"
          },
          "handwriting": {
            "type": "string",
            "description": "Optional style: easy, neat, joined, quick, fountain, copperplate, school, friendly, print, tall; only those the studio offers now are taken. Default easy.",
            "enum": [
              "easy",
              "neat",
              "joined",
              "quick",
              "fountain",
              "copperplate",
              "school",
              "friendly",
              "print",
              "tall"
            ],
            "default": "easy"
          },
          "handwriting_size": {
            "type": "string",
            "description": "medium (default) or large.",
            "enum": [
              "medium",
              "large"
            ],
            "default": "medium"
          },
          "card_size": {
            "type": "string",
            "description": "5x7 (default) or fun (2″ × 3″).",
            "enum": [
              "5x7",
              "fun"
            ],
            "default": "5x7"
          }
        }
      },
      "Recipient": {
        "type": "object",
        "required": [
          "name",
          "street",
          "suburb"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Recipient name.",
            "minLength": 1,
            "maxLength": 100
          },
          "street": {
            "type": "string",
            "description": "Street address.",
            "minLength": 1,
            "maxLength": 150
          },
          "suburb": {
            "type": "string",
            "description": "Suburb, town or city.",
            "minLength": 1,
            "maxLength": 60
          },
          "state": {
            "type": "string",
            "description": "Australian state abbreviation; optional region overseas.",
            "maxLength": 60
          },
          "postcode": {
            "type": "string",
            "description": "Four digits in Australia; optional overseas postal code.",
            "maxLength": 12
          },
          "country": {
            "type": "string",
            "description": "Supported two-letter country code. Defaults to AU.",
            "enum": [
              "AU",
              "AE",
              "AG",
              "AI",
              "AL",
              "AM",
              "AO",
              "AR",
              "AS",
              "AT",
              "AW",
              "AZ",
              "BA",
              "BB",
              "BD",
              "BE",
              "BF",
              "BG",
              "BH",
              "BI",
              "BJ",
              "BM",
              "BN",
              "BQ",
              "BR",
              "BS",
              "BT",
              "BZ",
              "CA",
              "CD",
              "CG",
              "CH",
              "CI",
              "CK",
              "CL",
              "CM",
              "CN",
              "CO",
              "CR",
              "CV",
              "CW",
              "CY",
              "CZ",
              "DE",
              "DK",
              "DM",
              "DO",
              "DZ",
              "EC",
              "EE",
              "EG",
              "ER",
              "ES",
              "ET",
              "FI",
              "FJ",
              "FK",
              "FM",
              "FO",
              "FR",
              "GA",
              "GB",
              "GE",
              "GF",
              "GH",
              "GI",
              "GL",
              "GM",
              "GN",
              "GP",
              "GQ",
              "GR",
              "GT",
              "GU",
              "GY",
              "HK",
              "HN",
              "HR",
              "HU",
              "ID",
              "IE",
              "IL",
              "IN",
              "IS",
              "IT",
              "JM",
              "JO",
              "JP",
              "KH",
              "KI",
              "KN",
              "KR",
              "KW",
              "KY",
              "LA",
              "LB",
              "LC",
              "LI",
              "LK",
              "LR",
              "LS",
              "LT",
              "LU",
              "LV",
              "MA",
              "ME",
              "MF",
              "MH",
              "MK",
              "ML",
              "MM",
              "MO",
              "MP",
              "MQ",
              "MR",
              "MT",
              "MU",
              "MV",
              "MW",
              "MX",
              "MY",
              "MZ",
              "NA",
              "NC",
              "NE",
              "NG",
              "NI",
              "NL",
              "NO",
              "NP",
              "NR",
              "NU",
              "NZ",
              "OM",
              "PA",
              "PE",
              "PF",
              "PG",
              "PH",
              "PK",
              "PL",
              "PM",
              "PN",
              "PR",
              "PT",
              "PW",
              "QA",
              "RO",
              "RS",
              "SA",
              "SB",
              "SC",
              "SE",
              "SG",
              "SH",
              "SI",
              "SK",
              "SN",
              "ST",
              "SV",
              "SZ",
              "TG",
              "TH",
              "TK",
              "TL",
              "TM",
              "TO",
              "TR",
              "TT",
              "TV",
              "TW",
              "TZ",
              "UA",
              "US",
              "UY",
              "VA",
              "VC",
              "VG",
              "VI",
              "VN",
              "VU",
              "WF",
              "WS",
              "ZA",
              "ZM",
              "ZW"
            ],
            "default": "AU"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "country": {
                  "const": "AU"
                }
              }
            },
            "then": {
              "required": [
                "state",
                "postcode"
              ],
              "properties": {
                "state": {
                  "enum": [
                    "NSW",
                    "VIC",
                    "QLD",
                    "WA",
                    "SA",
                    "TAS",
                    "ACT",
                    "NT"
                  ]
                },
                "postcode": {
                  "pattern": "^\\d{4}$"
                }
              }
            }
          }
        ]
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "CardStatus": {
        "type": "object",
        "required": [
          "reference",
          "status"
        ],
        "properties": {
          "reference": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "confirming payment",
              "queued",
              "received",
              "posted",
              "delivered",
              "cancelled"
            ]
          },
          "arrive_by": {
            "type": "string",
            "format": "date"
          },
          "transaction": {
            "type": "string",
            "description": "Settlement transaction when available."
          },
          "posted": {
            "type": "string",
            "format": "date"
          },
          "error": {
            "type": "string",
            "description": "Additional payment confirmation guidance, if present."
          }
        }
      },
      "Quote": {
        "type": "object",
        "required": [
          "error",
          "price",
          "card"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "price": {
            "type": "object",
            "required": [
              "aud",
              "usdc",
              "aud_to_usd",
              "network",
              "quote_expires"
            ],
            "properties": {
              "aud": {
                "type": "string"
              },
              "usdc": {
                "type": "string"
              },
              "aud_to_usd": {
                "type": "number"
              },
              "network": {
                "type": "string"
              },
              "quote_expires": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "card": {
            "type": "object",
            "properties": {
              "cover": {
                "type": "string"
              },
              "to": {
                "type": "string"
              },
              "postage": {
                "type": "string"
              },
              "arrive_by": {
                "type": "string",
                "format": "date"
              }
            }
          }
        }
      }
    }
  }
}
