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

# Mestry

> Send your paid orders to Mestry automatically, so each sale is attributed to the click and campaign that produced it.

Mestry is an ad attribution platform that ties each sale back to the click, campaign and ad network that produced it. Connecting it lets the platform report every paid order to your Mestry workspace on its own, carrying the Mestry click id and the UTM parameters the checkout captured. You no longer have to export sales or set up postbacks.

The mechanism: you authorize PagAmerican in your Mestry account once, and from then on the platform sends a signed `POST` with a JSON body to the webhook address Mestry gave it. Each order is signed with the signing secret you copy from Mestry. Nothing is injected into your checkout and no script runs in the buyer's browser.

> [!NOTE]
>
> You need a Mestry account and a Mestry workspace first. You log in to Mestry during the connection, and the signing secret is copied from the Mestry dashboard.

## How to configure

**1. Open the Mestry app**

In the PagAmerican dashboard, go to **Integrations** and find the **Mestry** card. Click **Install integration** the first time, or **Manage** if you have connected it before.

**2. Connect your Mestry account**

The **Connect Mestry** page lists what will be shared. Click **Connect with Mestry**. You are redirected to Mestry, where you log in, choose the workspace to connect and authorize PagAmerican. Mestry then sends you back to the PagAmerican dashboard, which now shows **Mestry connected**, the **Mestry workspace** and the date under **Connected on**.

**3. Save the signing secret**

Copy the webhook signing secret from your Mestry dashboard. Back in PagAmerican, paste it into the **Delivery signature** card and click **Save**. The badge changes from **Not configured** to **Configured**.

The connection does not deliver this secret. Until you save it, no sale is sent to Mestry.

**4. Create an item**

Under **Items**, click **New item**. Fill in **Item name** (an internal label, so you can tell your items apart). **Events sent** shows the events the item sends. There is nothing to choose there.

**5. Choose the product scope and save**

Under **Product Scope**, pick **All products**, **Specific products**, or **Specific offers from a product**, then click **Create item**. The item starts active.

The setup has two levels. The connection is one per account: one Mestry workspace and one signing secret. Under it, items decide which sales go to Mestry. Each item has its own name, product scope and status, and you can edit, deactivate or remove it from the **Items** table.

Items are filters, not separate destinations. Every item sends to the same Mestry workspace, so items can overlap. A sale that falls inside two items is still sent once.

The connection also belongs to the role you were using when you connected it. One made as a vendor receives sales of your own products. One made as an affiliate receives sales of the offers you promote. If you sell both ways, connect Mestry once under each role.

## Events sent

| Event in the UI | Value sent | When it fires |
| - | - | - |
| **Order paid** | `order.paid` | Every approved purchase, including upsell and downsell purchases |

Each purchase is its own event. When a buyer accepts an upsell, Mestry receives a second `order.paid` for the same order, with its own payment id and its own revenue. An order bump is not a separate event: it is part of the purchase it was added to.

> [!NOTE]
>
> For now, Mestry receives paid orders only. Refunds and chargebacks are not sent, so a refunded order stays counted as revenue in Mestry.

## What Mestry receives

One paid purchase is one `POST`. This is the body:

```json theme={null}
{
  "event": "order.paid",
  "event_id": "pur_01a00000-0000-7000-8000-000000000000:order.paid",
  "occurred_at": "2026-09-01T14:35:48.000Z",
  "test": false,
  "data": {
    "order": {
      "id": "ord_01a00000-0000-7000-8000-000000000000"
    },
    "payment": {
      "id": "pur_01a00000-0000-7000-8000-000000000000",
      "method": "credit_card"
    },
    "amounts": {
      "currency": "USD",
      "account_revenue": 9300
    },
    "account": {
      "role": "producer"
    },
    "product": {
      "id": "prd_01a00000-0000-7000-8000-000000000000",
      "name": "EXAMPLE PRODUCT"
    },
    "customer": {
      "email": "jane.doe@example.com",
      "phone": "+15551234567"
    },
    "tracking": {
      "click_id": "000000000000000000000000",
      "utm": {
        "source": "facebook",
        "medium": "example-medium",
        "campaign": "EXAMPLE-CAMPAIGN",
        "content": "example-content",
        "term": "example-term"
      },
      "ad": {
        "platform": "meta"
      }
    }
  }
}
```

What is worth knowing about those fields:

| Field | Description |
| - | - |
| `event_id` | Unique per purchase and event. Mestry uses it to ignore a repeated delivery of the same sale |
| `occurred_at` | The moment the payment was authorized, in UTC, as ISO-8601 |
| `test` | `false` for live traffic |
| `data.order.id` | The PagAmerican order. A purchase and its upsells share this value |
| `data.payment.id` | The purchase itself. Different for the front purchase and for each upsell |
| `data.payment.method` | `credit_card` or `paypal` |
| `data.amounts.account_revenue` | Your net on this purchase, as an integer in cents: `9300` is \$93.00. The vendor's net on the vendor's copy, the affiliate's net on the affiliate's copy |
| `data.account.role` | `producer` on the vendor's copy, `affiliate` on the affiliate's copy |
| `data.product` | The main product of the purchase, never the order bump |
| `data.customer.phone` | The buyer's phone in international format (`+` and digits), or `null` |
| `data.tracking.click_id` | The `mestry_cid` value the checkout link carried, or `null` |
| `data.tracking.utm` | The five UTM keys the checkout captured. A key the link did not carry arrives as `null` |
| `data.tracking.ad` | Present only when the ad network can be identified (see below) |

Every delivery carries an `X-Mestry-Signature` header, an HMAC-SHA256 of the body computed with your signing secret. Mestry checks it to confirm the sale came from your account.

## Click id and ad platform

Mestry attributes a sale through `mestry_cid`, the click id Mestry adds to the link that brings the buyer to your checkout. The platform reads it from the checkout link and sends it back as `data.tracking.click_id`. If the link loses the parameter on the way, for example through a redirect that drops the query string, the sale reaches Mestry with `click_id` set to `null` and can only be matched by its UTMs.

`data.tracking.ad.platform` tells Mestry which ad network the click came from. The platform decides it from the checkout link:

| The link carries | `ad.platform` |
| - | - |
| `fbclid` | `meta` |
| `gclid`, `gbraid` or `wbraid` | `google` |
| `ttclid` | `tiktok` |
| no click id above, and `utm_source` is `facebook`, `fb`, `instagram`, `ig` or `meta` | `meta` |
| no click id above, and `utm_source` is `google` or `youtube` | `google` |
| no click id above, and `utm_source` is `tiktok` | `tiktok` |
| no click id above, and `utm_source` is `taboola` | `taboola` |

An ad network click id wins over `utm_source`. When neither identifies a network, the `ad` key is left out.

## Vendor and affiliate copies

When a purchase came through an affiliate, the platform sends it twice: once to the vendor's Mestry connection and once to the affiliate's. Each copy carries its own `account.role` and its own `account_revenue`. Neither side sees the other's figure.

When the affiliate is paid a fixed commission (CPA), `customer.email` and `customer.phone` arrive as `REDACTED` on the affiliate's copy. The vendor's copy, and the copy of an affiliate on revenue share, carry them unchanged.

## Troubleshooting

Click **View Logs** on the **Mestry** card to open the delivery logs, with one row per attempt: **Sent At**, **Event**, **Status**, **Code**, and **Details**.

> [accordion] Nothing arrives and there is no log row
>
> A row is written only when a delivery is actually attempted. When the platform decides not to send, nothing is attempted, so there is no row and no error message. **An empty log is the diagnostic, not a sign that the platform is broken.**
>
> The platform skips the delivery silently when:
>
> * the signing secret was never saved: the **Delivery signature** card shows **Not configured**
> * Mestry is disconnected
> * there is no item, or every item is inactive
> * the purchase falls outside the **Product Scope** of every active item
> * the purchase belongs to the other role: a vendor's connection does not receive the purchases you made as an affiliate, and an affiliate's does not receive the purchases of products you sell
>
> With **Specific products** or **Specific offers from a product**, the purchase is matched by its main item, never by the order bump. A purchase whose main item sits outside the scope is skipped even when the order bump is inside it.

> [accordion] The log row says Failed
>
> Read the **Code** column:
>
> * a `4xx`: Mestry refused the delivery. Check that the signing secret saved in PagAmerican is the one in your Mestry dashboard, and paste it again with **Replace secret** if you are unsure. If your Mestry access was revoked, click **Reconnect**.
> * `429` or a `5xx`: Mestry was unavailable. The platform tries again right away, after 1 and 3 seconds, before recording the delivery as failed.
> * no code, with a timeout in **Details**: Mestry did not answer within 10 seconds. A timeout is not retried.
>
> A failed delivery is not sent again later. Once the row says Failed, that sale will not reach Mestry on its own.

> [accordion] Sales arrive but are not attributed to a click
>
> `click_id` only ever contains what the checkout link carried. If the buyer reached the checkout through a link without `mestry_cid`, the sale arrives with `click_id` set to `null`. Check that your Mestry links keep the parameter all the way to the checkout. Fix the links, not the integration.

> [accordion] The connection page shows an error after Mestry
>
> If you cancel on Mestry's authorization page, or take too long, you come back with an error message and the connection is not made. Click **Connect with Mestry** and complete the authorization again.

## FAQ

**Can I send some products to Mestry and not others?**
Yes. Create items only for the products or offers you want to send. A sale outside every item's scope is not sent.

**What happens when I deactivate or remove an item?**
Sales covered only by that item stop being sent immediately. Sales still covered by another active item keep going. Nothing is queued, and turning an item back on does not backfill the sales made while it was off.

**What happens when I disconnect?**
The platform stops sending your sales to Mestry and revokes the access you granted. You can connect again at any time with **Connect with Mestry**.

**Can I change the signing secret later?**
Yes. Paste the new secret into the **Delivery signature** card and click **Replace secret**. The change applies to the next sale.

**Do I have to change my checkout links?**
No. The integration reads the parameters the checkout already captures. For Mestry to attribute a sale to a click, the link that brings the buyer to the checkout has to carry `mestry_cid`.

> [card] [Need help?](mailto:support@pagamerican.com)
>
> Our team can help you set up your integration: [support@pagamerican.com](mailto:support@pagamerican.com)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.