{
  "openapi": "3.1.0",
  "info": {
    "title": "Static Riot developer-owned sandbox wallet contract",
    "version": "1.0.0",
    "description": "Outbound browser connector contract to implement on YOUR sandbox wallet. These endpoints are not hosted by Static Riot. Test EUR credits only. Permit the console origin through CORS. Original transaction receipts and exactly-once balance changes must survive retries. This is separate from the evaluation RGS API and from a production partner adapter."
  },
  "servers": [{"url": "https://wallet-sandbox.example.com/static-riot", "description": "Replace with your public HTTPS sandbox base URL"}],
  "security": [{"SandboxToken": []}],
  "paths": {
    "/handshake": {
      "post": {
        "operationId": "sandboxHandshake",
        "summary": "Verify test-only environment and player balance",
        "parameters": [{"$ref": "#/components/parameters/Environment"}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HandshakeRequest"}}}},
        "responses": {
          "200": {"description": "Sandbox identity verified", "content": {"application/json": {"schema": {"allOf": [{"$ref": "#/components/schemas/HandshakeRequest"}, {"type": "object", "required": ["balanceCents"], "properties": {"balanceCents": {"$ref": "#/components/schemas/Cents"}}}]}}}},
          "401": {"description": "Invalid or expired sandbox token"},
          "403": {"description": "Token cannot access this test player"}
        }
      }
    },
    "/transactions": {
      "post": {
        "operationId": "sandboxTransaction",
        "summary": "Debit, credit or roll back test credits atomically",
        "description": "Exact duplicates replay the original immutable receipt. Same ID with changed operation or payload returns409 without a balance mutation. A credit closes its debit round, including zero credits. A settled round cannot be rolled back. Authenticate test-player ownership and retain stable rejections.",
        "parameters": [{"$ref": "#/components/parameters/Environment"}, {"in": "header", "name": "Idempotency-Key", "required": true, "schema": {"type": "string"}, "description": "Exactly the transactionId in the body. Retain it after a timeout."}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Transaction"}}}},
        "responses": {
          "200": {"$ref": "#/components/responses/Receipt"},
          "201": {"$ref": "#/components/responses/Receipt"},
          "409": {"description": "IDEMPOTENCY_CONFLICT: same transaction ID with changed payload. Original receipt remains unchanged.", "content": {"application/json": {"schema": {"type": "object", "required": ["error"], "properties": {"error": {"type": "object", "required": ["code"], "properties": {"code": {"const": "IDEMPOTENCY_CONFLICT"}}}}}}}},
          "401": {"description": "Invalid or expired sandbox token"},
          "403": {"description": "Wrong player scope"}
        }
      }
    },
    "/transactions/{transactionId}": {
      "get": {
        "operationId": "sandboxReceipt",
        "summary": "Recover the original transaction without moving credits",
        "description": "A missing receipt is not proof that an earlier request cannot still commit. Retry its identical POST and transaction ID. Never refund an uncertain credit.",
        "parameters": [{"$ref": "#/components/parameters/Environment"}, {"in": "path", "name": "transactionId", "required": true, "schema": {"type": "string"}}],
        "responses": {
          "200": {"description": "Original receipt or null", "content": {"application/json": {"schema": {"type": "object", "required": ["receipt"], "properties": {"receipt": {"oneOf": [{"$ref": "#/components/schemas/Receipt"}, {"type": "null"}]}}}}}},
          "404": {"description": "No visible receipt for this player and ID"},
          "401": {"description": "Invalid token"},
          "403": {"description": "Wrong player scope"}
        }
      }
    }
  },
  "components": {
    "securitySchemes": {"SandboxToken": {"type": "http", "scheme": "bearer", "description": "Limited, test-only wallet token supplied in console memory. Never a production credential."}},
    "parameters": {"Environment": {"in": "header", "name": "X-Static-Riot-Environment", "required": true, "schema": {"const": "sandbox"}}},
    "schemas": {
      "Cents": {"type": "integer", "minimum": 0, "maximum": 9007199254740991, "description": "Nonnegative safe integer EUR cents"},
      "HandshakeRequest": {
        "type": "object", "required": ["protocol", "environment", "funds", "redeemable", "playerId", "currency"],
        "properties": {"protocol": {"const": "static-riot-sandbox-wallet-v1"}, "environment": {"const": "sandbox"}, "funds": {"const": "test_credits"}, "redeemable": {"const": false}, "playerId": {"type": "string", "minLength": 1, "maxLength": 64}, "currency": {"const": "EUR"}}
      },
      "Transaction": {
        "type": "object", "required": ["operation", "transactionId", "roundId", "playerId", "currency", "amountCents"],
        "properties": {"operation": {"enum": ["debit", "credit", "rollback"]}, "transactionId": {"type": "string"}, "roundId": {"type": "string"}, "playerId": {"type": "string"}, "currency": {"const": "EUR"}, "amountCents": {"$ref": "#/components/schemas/Cents"}, "referenceTransactionId": {"type": "string", "description": "Required for credit and rollback; original debit ID"}},
        "allOf": [{"if": {"properties": {"operation": {"enum": ["credit", "rollback"]}}}, "then": {"required": ["referenceTransactionId"]}}]
      },
      "Receipt": {
        "allOf": [{"$ref": "#/components/schemas/Transaction"}, {"type": "object", "required": ["status", "balanceBeforeCents", "balanceCents"], "properties": {"status": {"enum": ["succeeded", "rejected"]}, "balanceBeforeCents": {"$ref": "#/components/schemas/Cents"}, "balanceCents": {"$ref": "#/components/schemas/Cents"}, "refundedCents": {"$ref": "#/components/schemas/Cents"}, "code": {"type": "string", "description": "Required for a rejected operation"}}, "allOf": [{"if": {"properties": {"operation": {"const": "rollback"}}}, "then": {"required": ["refundedCents"]}}, {"if": {"properties": {"status": {"const": "rejected"}}}, "then": {"required": ["code"]}}]}]
      }
    },
    "responses": {"Receipt": {"description": "Original successful or rejected receipt, unchanged on exact duplicate", "content": {"application/json": {"schema": {"type": "object", "required": ["receipt"], "properties": {"receipt": {"$ref": "#/components/schemas/Receipt"}}}}}}}
  }
}
