# Send Tim for PrestaShop

Free module by Evia Software for PrestaShop 8 and 9. A Send Tim account and API key are required. The module has no Marketplace activation or licensing step.

## What it does

- Connects one PrestaShop shop to one Send Tim workspace using `GET /me`.
- Queues and synchronizes **registered customers with the PrestaShop newsletter flag** through `PUT /contacts`. Account creation and a purchase alone do not count as consent.
- Imports existing eligible customers in batches of 100.
- Sends names and selected order summary fields as contact properties: customer ID, order count, last order ID, total, currency and status ID. It preserves other Send Tim custom properties when the API returns them. It does not send product or cart line items.
- Removes the module's Send Tim list membership when a customer's newsletter flag is turned off. It does not change a Send Tim contact's global unsubscribe state.
- Tracks carts for known registered customers and can start an existing active Send Tim automation with a manual trigger after the configured delay. It checks for a completed order and newsletter consent immediately before triggering.
- Processes API work in a database-backed queue through cron, with retry for network errors, 5xx and 429 responses.
- Keeps configuration, queue, contact mappings and cart tracking separate per PrestaShop shop.
- Deletes completed job records after 30 days and terminal cart tracking records after 90 days when cron runs.

## Requirements

- PrestaShop 8.0 or 9.x, PHP supported by that PrestaShop version, PHP cURL and OpenSSL extensions, HTTPS outbound access to `sendtim.com`.
- A Send Tim workspace and API key. Generate it in Send Tim **Settings → API**. The key has workspace administrator-level API access.
- A server cron runner for background processing. The module does not call Send Tim on storefront requests.
- A Send Tim plan with automations if using abandoned-cart recovery (Starter or above).

## Install

1. Download `sendtim-prestashop.zip` from the [Send Tim PrestaShop guide](https://sendtim.com/docs/connect-prestashop).
2. In PrestaShop **Module Manager**, select **Upload a module** and upload the ZIP. It contains a single `sendtim/` root folder.
3. Install **Send Tim**, then select one shop in the multistore selector and open **Configure**.
4. Paste a Send Tim API key and select **Connect / test key**. The page shows the workspace returned by `GET /me`.
5. Choose a Send Tim destination list if desired. Enable customer synchronization. Save.
6. Select **Generate / rotate cron token** and install the displayed `curl` command as a server cron entry that runs every minute. Keep the header token secret. Each shop needs its own cron URL and token.
7. Select **Import existing eligible customers** for a historical import. Monitor the counts on the configuration page.

The key is encrypted before storage using the PrestaShop instance secret and AES-256-GCM. A database backup without the shop secret does not disclose it. Protect full server backups as usual.

## Abandoned carts

1. Create and activate a Send Tim automation with a **manual trigger** and appropriate recovery email content. The module cannot create an automation through the current public API.
2. In the module settings, select that automation, enable abandoned carts and set a delay between 15 minutes and 7 days.
3. Keep cron running. The module only tracks carts tied to known registered customers and triggers for those whose PrestaShop newsletter flag remains set.

The module checks `orders.id_cart` before calling the automation API. Send Tim does not provide cancellation or an idempotency key for `POST /automations/{id}/trigger`. To prevent duplicates, the module reserves a cart before the call and **does not automatically retry an ambiguous trigger failure**. A checkout completed in the narrow interval after the final check could still receive a recovery email; add an order-completion exit or filter in the Send Tim automation if needed.

## Data and privacy

The newsletter flag is the only consent source used for automatic contact import and automation. The module does not infer consent from an account or an order. `PUT /contacts` records `consentGiven` on a new contact; it does not alter consent on an existing Send Tim contact. Existing Send Tim unsubscribes remain in force.

The Official GDPR module's export/delete hooks expose or remove the module's local contact mapping and cart rows. They **do not erase data from Send Tim**. The public Send Tim `DELETE /contacts/{id}` is a soft delete; complete erasure must be handled in the Send Tim workspace. On uninstall, the module deletes its own tables, credentials, jobs and mappings. Completed job status records are retained for 30 days and terminal cart tracking for 90 days, then cron removes them. The module stores no raw API response bodies or customer email addresses in job logs.

The merchant controls whether the PrestaShop newsletter flag is a valid record of marketing opt-in for their storefront and whether the Send Tim automation's content complies with local law.

## API and current limits

The module uses only documented Send Tim endpoints: `GET /me`, `GET /lists`, `GET /automations`, `GET /contacts?email=…`, `PUT /contacts`, `DELETE /lists/{id}/contacts`, and `POST /automations/{id}/trigger`. There are no public order, cart, product, event, or automation-cancellation endpoints. Order summaries are contact custom properties, and full ecommerce event flows require additional Send Tim backend capabilities.

API limits are per key: Free 60, Starter 300, Pro and Scale 600 requests per minute. The worker claims at most 20 jobs per cron run and respects `Retry-After` on 429 responses. A run may use more than one API request per job; if rate limited, it stops and retries later.

## Troubleshooting

- **Disconnected / 401:** Generate a new Send Tim key, reconnect, and ensure the correct workspace is shown.
- **No contacts imported:** Enable sync, start the import, configure cron, and check that customers opted into the PrestaShop newsletter.
- **Pending jobs do not move:** Check the cron command, HTTPS, PHP cURL and the token. The endpoint accepts `POST` and the `X-Sendtim-Cron-Token` header only.
- **429 / retry:** Jobs retry after the server's `Retry-After` delay or exponential backoff. Reduce cron concurrency if other integrations share the key.
- **Failed cart trigger:** Check the automation is active, manual and available on the plan. A failed or timed-out trigger is not automatically replayed because the remote call may already have succeeded.
- **Wrong shop or list:** Select one shop in the multistore selector. Each shop needs its own settings, list, key and cron command.

## Updates and support

Back up the store before updating. Upload the new ZIP through Module Manager; do not remove the module first unless you intend to erase its settings and queued work. For help, contact Evia Software through [sendtim.com](https://sendtim.com).

## Validation status

The source repository includes PHP syntax and isolated mocked tests. Installation and end-to-end behavior still require verification against live PrestaShop 8 and 9 test stores; these are not bundled with this module. See the release notes on the public guide for the exact checks performed.
