# Herospark

> Connect Herospark to your Cademí: the product ID and the Piloto Automático webhook automations for payment and cancellation.

Connect Herospark to your Cademí so each approved purchase gives the student access on its own. You need an ID for the product and automations in Herospark's Piloto Automático (Autopilot) that notify Cademí. Herospark does not ask for a token.

## Before you start

Ask Herospark support, through the chat on their platform, to turn off Herospark's native members area on your account. That way the sales from your checkout no longer create access in Herospark's members area, and the student's access lives in 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 **Herospark**.
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 Herospark.
5. The **Gateway connection** section shows the **Product ID** field and the **Postback URL**.

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

## 2. Choose the product ID

With Herospark, you write the product ID yourself in the automation in step 3. What matters is that the same value is in both places.

1. Choose an ID for the product: the product code on Herospark, for example.
2. Paste the ID into **Product ID** in the Cademí delivery and keep it for step 3.

## 3. Create the payment confirmed automation

1. On Herospark, open **Piloto Automático** (Autopilot) and create the **Pagamento Confirmado** (Payment confirmed) automation, with the webhook option.
2. In **Filtro de disparo** (Trigger filter), pick the product (or products) you deliver through this delivery.
3. In **URL**, paste the **Postback URL** of the delivery.
4. In **Método** (Method), keep the default value, **POST**.
5. In **Headers**, add the key `Content-Type` with the value `application/json`.
6. In **Body**, paste the code below exactly. Then replace `00000` with the product ID of the delivery, keeping the quotes.

```json
{"valor": "{{ offer_price | divided_by: 100.00}}", "codigo": "{{ payment_id }}", "status": "aprovado", "produto_id": "00000", "cliente_doc": "{{ buyer_document_id }}", "cliente_nome": "{{ buyer_name }}", "cliente_email": "{{ buyer_email }}", "recorrencia_id": "{{subscription_id}}", "cliente_celular": "{{ buyer_phone }}", "recorrencia_status": "ativo", "subscription_expiration_at": "{{subscription_expiration_at}}", "subscription_next_invoice_at": "{{subscription_next_invoice_at}}"}
```

7. Turn on the automation and, in Cademí, save the delivery.

## 4. Create the cancellation automations

If you sell subscriptions, create two more automations, **Assinatura cancelada pelo cliente** and **Assinatura cancelada pelo produtor** (subscription canceled by the customer, by the producer). They make the student inactive in Cademí when the subscription is canceled on Herospark.

1. Fill in each one as in step 3, with the same filter, URL, method and header.
2. In **Body**, paste the code below exactly and replace the product ID the same way.

```json
{"valor": "{{ offer_price | divided_by: 100.00}}", "codigo": "{{ payment_id }}", "status": "cancelado", "produto_id": "00000", "cliente_doc": "{{ buyer_document_id }}", "cliente_nome": "{{ buyer_name }}", "cliente_email": "{{ buyer_email }}", "recorrencia_id": "{{subscription_id}}", "cliente_celular": "{{ buyer_phone }}", "recorrencia_status": "cancelado", "subscription_expiration_at": "{{subscription_expiration_at}}", "subscription_next_invoice_at": "{{subscription_next_invoice_at}}"}
```

3. Turn on both automations.
