> For the complete documentation index, see [llms.txt](https://docs.1q.gg/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1q.gg/documentation/reference/callback-financeiro-e-carteira-do-cassino.md).

# Callback financeiro e carteira do cassino

A 1Q entrega eventos financeiros à URL HTTPS configurada na aba **Callback** do Projeto. O seu cassino é autoridade dos saldos, valida a assinatura e responde com resultados duráveis.

## Segurança da entrega

| Header               | Uso                                  |
| -------------------- | ------------------------------------ |
| X-1Q-Key             | Identidade da origem                 |
| X-1Q-Request-Id      | Identificador da requisição          |
| X-1Q-Correlation-Id  | Correlação de rastreamento           |
| X-1Q-Timestamp       | Timestamp Unix                       |
| X-1Q-Nonce           | Nonce único                          |
| X-1Q-Signature       | HMAC SHA-256                         |
| X-1Q-Idempotency-Key | Identificador financeiro idempotente |

A assinatura usa o **segredo do callback**, separado do segredo usado nas chamadas da Games API.

```
POST + "\\n" +
CALLBACK_PATH + "\\n" +
UNIX_TIMESTAMP + "\\n" +
NONCE + "\\n" +
IDEMPOTENCY_KEY + "\\n" +
SHA256(CANONICAL_JSON_BODY)
```

O JSON canônico ordena as chaves de objetos recursivamente e não escapa as barras `/`. Compare assinaturas em tempo constante.

## Movimentações

No contrato atual, `WIN_BET` representa **uma única operação financeira atômica** com movimento líquido `win − bet`. A resposta aceita precisa indicar explicitamente aceitação, `balance_before` e `balance_after`. O operador deve persistir o resultado antes de responder.

{% hint style="danger" %}
Não trate as requisições como dois movimentos independentes (débito e crédito) quando a operação recebida é `WIN_BET`. Repetições com a mesma idempotência devem retornar o resultado original sem duplicar saldo.
{% endhint %}

## Regras da URL

Em Production use HTTPS na porta 443; a 1Q rejeita callbacks com redirecionamentos, query, fragmento, userinfo, host sem DNS válido ou endereço privado/reservado.

{% hint style="warning" %}
**Ponto de homologação:** os exemplos exatos de JSON de cada operação e cada recusa devem ser extraídos dos testes e DTOs financeiros antes de usar esta página para implementar um ledger real. Este rascunho não inventa campos de payload não confirmados.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1q.gg/documentation/reference/callback-financeiro-e-carteira-do-cassino.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
