# PagarMe

> Connect PagarMe to your Cademí: the product or subscription ID, the webhook with order and subscription events and how to find the ID in a received sale.

Connect PagarMe to your Cademí so each approved purchase gives the student access on its own. You need the product ID (or the subscription ID) and a webhook pointing to Cademí. PagarMe does not ask for a token.

## 1. Create the delivery in Cademí

1. In the Cademí dashboard, open **Sales > Deliveries** and add a delivery.
2. In **Select a Gateway**, pick **PagarMe**.
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 product on PagarMe.
5. The **Gateway connection** section shows the **Product or Subscription ID** field and the **Postback URL**.

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

## 2. Find the product ID

On PagarMe, the product ID can be in two places: in the store where you created the product or in PagarMe itself.

**In the store:**

1. In the store dashboard, open **Produtos** (Products) and pick the product.
2. Copy the ID shown below the offer name or in the browser address bar.

**In PagarMe:**

1. In the PagarMe dashboard, open **Vendas > Links de Pagamento** (Sales > Payment links).
2. Click **Detalhes** (Details) on the link you sell.
3. On the **Informações** (Information) tab, copy the code of the **Link de Pagamento** (payment link). It starts with `pl_`, followed by letters and numbers.

Paste the value into **Product or Subscription ID** in the Cademí delivery.

**If you are not sure about the ID:** set up the webhook (step 3), make a test purchase and open **Sales > Sales** in Cademí. In **View details** of the sale, the **Data** tab shows **Product ID in the gateway**: that is the value PagarMe sends. Paste it into the delivery.

## 3. Set up the webhook

1. In the PagarMe dashboard, open **Configurações > Webhooks** (Settings > Webhooks) and click **Criar Webhook** (Create webhook).
2. In **Status**, choose **Ativo** (Active).
3. In **URL**, paste the **Postback URL** of the delivery.
4. In **Máximo de tentativas** (Maximum attempts), enter 3.
5. In **Eventos** (Events), select `order.paid`, `order.payment_failed`, `order.canceled`, `subscription.created` and `subscription.canceled`.
6. Click **Salvar** (Save) and, in Cademí, save the delivery.
