# Asaas

> Connect Asaas to your Cademí: the payment link ID, the API key that works as the token and the version V3 webhook with every billing event.

Connect Asaas to your Cademí so each paid charge gives the student access on its own. You need the payment link ID, an API key from your Asaas account and a webhook pointing to Cademí.

## 1. Create the delivery in Cademí

1. In the Cademí dashboard, open **Sales > Deliveries** and add a delivery.
2. In **Select a Gateway**, pick **Asaas**.
3. In **Delivery Name**, enter a name that helps you recognize it later.
4. In **Sales Mode**, choose **One-time sale** or **Subscription**, matching the billing on Asaas.
5. The **Gateway connection** section shows the **Payment Link ID** and **API Token** fields and the **Postback URL**.

Keep the delivery open: you come back to it in the next steps.

## 2. Find the payment link ID

1. In the Asaas dashboard, open **Links de Pagamento** (Payment links) in the side menu and create a link or pick an existing one.
2. Inside the link, click **Compartilhar** (Share) and then **Copiar link** (Copy link).
3. Paste the link into the address bar of a new browser tab: the ID is the part after the last slash of the address.
4. Paste the ID into **Payment Link ID** in the Cademí delivery.

**Several links:** each payment link that gives access needs to be registered in a delivery. Paste more than one ID into the same field when they give the same access.

## 3. Copy the API key

The Asaas notification does not carry all the purchase data. On each notification, Cademí uses the API key to fetch the rest from your Asaas account and grant the delivery. Without the key, the sale cannot be completed.

If you already registered your Asaas key in another delivery, pick it in **Use an already registered token** and go to step 4.

1. In the Asaas dashboard, click your photo in the top right corner and open **Integrações** (Integrations).
2. Click **Chaves de API** (API keys) and then **Gerar chave de API** (Generate API key).
3. Name it "Cademí", with no expiration, and click **Avançar** (Next).
4. Confirm the two-step verification with the code sent by SMS.
5. Copy the key and leave it as **Habilitada** (Enabled).
6. Paste the key into **API Token** in the Cademí delivery.

## 4. Set up the webhook

1. Still under **Integrações** in the Asaas dashboard, click **Webhook** and then **+ Adicionar Webhook** (Add webhook). Use version **V3**.
2. In **Nome do Webhook** (Webhook name), enter "Cademí".
3. In **URL**, paste the **Postback URL** of the delivery.
4. In **Fila de Sincronização Ativa** (Sync queue active), choose **Sim** (Yes).
5. In **Tipo de Envio** (Sending type), choose **Sequencial** (Sequential).
6. In **Cobranças** (Charges), choose **Todos os eventos** (All events).
7. Click **Salvar** (Save) and, in Cademí, save the delivery.

**The webhook queue:** Asaas sends its notices in a queue. If one delivery attempt fails, the queue may stop and the following sales no longer reach Cademí. If sales stop showing up, check in Asaas whether the webhook queue is still active and reactivate it.
