{
  "openapi": "3.1.0",
  "info": {
    "title": "CardGenr API",
    "version": "1.0.0",
    "summary": "Free test card generation, Luhn validation and BIN lookup.",
    "description": "Generate Luhn-valid test credit card numbers, validate card numbers and look up BIN/IIN data. No API key is required. Generated numbers are for testing only: they are not linked to any account and are not accepted by payment gateway sandboxes, which only take their own published test cards (see https://cardgenr.com/test-cards).",
    "contact": { "url": "https://cardgenr.com/contact" }
  },
  "servers": [{ "url": "https://cardgenr.com/api/v1" }],
  "externalDocs": { "description": "API documentation", "url": "https://cardgenr.com/api" },
  "paths": {
    "/generate": {
      "get": {
        "operationId": "generateCards",
        "summary": "Generate test credit cards",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "description": "Card network, or several comma-separated. Defaults to visa.",
            "schema": { "type": "string", "example": "visa,mastercard" }
          },
          {
            "name": "count",
            "in": "query",
            "description": "Number of cards, 1-1000. Defaults to 1.",
            "schema": { "type": "integer", "minimum": 1, "maximum": 1000, "default": 1 }
          },
          {
            "name": "country",
            "in": "query",
            "description": "ISO country code or country name for the billing address.",
            "schema": { "type": "string", "example": "GB" }
          },
          {
            "name": "format",
            "in": "query",
            "description": "Response format.",
            "schema": { "type": "string", "enum": ["json", "csv", "xml", "pipe"], "default": "json" }
          }
        ],
        "responses": {
          "200": {
            "description": "Generated cards. CSV, XML and pipe formats return the same fields as text.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "count": { "type": "integer" },
                    "cards": { "type": "array", "items": { "$ref": "#/components/schemas/Card" } }
                  }
                }
              },
              "text/csv": { "schema": { "type": "string" } },
              "application/xml": { "schema": { "type": "string" } },
              "text/plain": { "schema": { "type": "string" } }
            }
          },
          "400": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/validate": {
      "get": {
        "operationId": "validateCard",
        "summary": "Validate a card number",
        "description": "Runs the Luhn check and detects the card network and MII category.",
        "parameters": [
          {
            "name": "number",
            "in": "query",
            "required": true,
            "description": "Card number. Spaces and dashes are ignored.",
            "schema": { "type": "string", "example": "4242424242424242" }
          }
        ],
        "responses": {
          "200": {
            "description": "Validation result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "validation": {
                      "type": "object",
                      "properties": {
                        "isValid": { "type": "boolean" },
                        "cardType": { "type": ["string", "null"] },
                        "miiCategory": { "type": "string" },
                        "issuerInfo": { "type": "string" },
                        "errors": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/bin": {
      "get": {
        "operationId": "lookupBin",
        "summary": "Look up a BIN/IIN",
        "description": "Returns the card brand, type, issuing bank and country for the first 6-8 digits of a card. Rate limited per IP.",
        "parameters": [
          {
            "name": "bin",
            "in": "query",
            "required": true,
            "description": "At least the first 6 digits.",
            "schema": { "type": "string", "pattern": "^[0-9]{6,8}$", "example": "411111" }
          }
        ],
        "responses": {
          "200": {
            "description": "BIN details.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "bin": { "type": "string" },
                    "data": { "$ref": "#/components/schemas/BinResult" }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/types": {
      "get": {
        "operationId": "listCardTypes",
        "summary": "List supported card networks",
        "responses": {
          "200": {
            "description": "Card networks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "count": { "type": "integer" },
                    "types": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": { "key": { "type": "string" }, "name": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/countries": {
      "get": {
        "operationId": "listCountries",
        "summary": "List countries available for billing addresses",
        "responses": {
          "200": {
            "description": "Countries.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "count": { "type": "integer" },
                    "countries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": { "code": { "type": "string" }, "name": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Card": {
        "type": "object",
        "properties": {
          "number": { "type": "string", "example": "4532015112830366" },
          "type": { "type": "string", "example": "VISA" },
          "expiry": { "type": "string", "example": "09/2028" },
          "expiryMonth": { "type": "string", "example": "09" },
          "expiryYear": { "type": "string", "example": "2028" },
          "name": { "type": "string" },
          "cvv": { "type": "string" },
          "address": { "type": "string" },
          "city": { "type": "string" },
          "state": { "type": "string" },
          "zipcode": { "type": "string" },
          "country": { "type": "string" }
        }
      },
      "BinResult": {
        "type": "object",
        "properties": {
          "scheme": { "type": "string" },
          "type": { "type": "string" },
          "brand": { "type": "string" },
          "prepaid": { "type": "boolean" },
          "country": {
            "type": "object",
            "properties": {
              "name": { "type": "string" },
              "alpha2": { "type": "string" },
              "emoji": { "type": "string" }
            }
          },
          "bank": {
            "type": "object",
            "properties": {
              "name": { "type": "string" },
              "url": { "type": "string" },
              "phone": { "type": "string" },
              "city": { "type": "string" }
            }
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Error.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "success": { "type": "boolean", "const": false },
                "error": { "type": "string" }
              }
            }
          }
        }
      }
    }
  }
}
