> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pagamentos.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Convex

> Integrando o Convex com o **pagamentos.dev**

## O que é Convex?

Convex é uma plataforma de backend que combina banco de dados em tempo real,
funções serverless e sincronização de estado automática.

Visite o site oficial do [Convex](https://convex.dev/) para saber mais.

## Instalação

Para começar o desenvolvimento, instale a biblioteca com seu gerenciador de
pacotes favorito:

<CodeGroup>
  ```bash npm theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  npm i pagamentos
  ```

  ```bash Yarn theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  yarn add pagamentos
  ```

  ```bash pnpm theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  pnpm add pagamentos
  ```

  ```bash Bun theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  bun i pagamentos
  ```
</CodeGroup>

## Backend

No Convex, você define funções serverless no arquivo `convex/`
. Use o adaptador `toConvex` para integrar webhooks:

```ts convex/webhooks.ts theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { toConvex } from 'pagamentos/convex'
import { pg } from '../pagamentos'

export const webhookHandler = toConvex(pg.webhooks.handler)
```

```ts convex/http.ts theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { httpRouter } from 'convex/server'
import { webhookHandler } from './webhooks'

const http = httpRouter()

http.route({
  path: '/webhook',
  method: 'POST',
  handler: webhookHandler,
})

export default http
```

> Confira um exemplo completo de Convex HTTP Action com pagamentos.dev + Mercado Pago em:
> [github.com/pagamentosdev/pagamentos/blob/main/examples/with-convex/convex/webhooks.ts](https://github.com/pagamentosdev/pagamentos/blob/main/examples/with-convex/convex/webhooks.ts)
