<?php
$page_title = 'Mailchimp Transactional — Integration Demo';
require 'header.php';
?>

<p>
    This is a guided walkthrough of integrating with the
    <strong>Mailchimp Transactional API</strong> (formerly Mandrill) in PHP.
    Each step below is a standalone page that performs one API call, shows
    the code that did it, and prints the raw request &amp; response.
</p>

<?php if (!is_configured()): ?>
<div class="callout warn">
    <strong>Before you can run any step:</strong> you need an API key.
    Open <code>config.php</code> and paste it in, or follow the
    <a href="setup.php">setup guide</a> for how to generate one.
</div>
<?php else: ?>
<div class="callout ok">
    <strong>API key detected.</strong> You're good to go — start with
    <a href="01-ping.php">Step 1: Ping</a> to confirm auth works.
</div>
<?php endif; ?>

<h2>The steps</h2>

<a class="step-card" href="setup.php">
    <span class="num">0</span><h3>Setup — get an API key</h3>
    <p>How to enable Transactional email on your Mailchimp account and generate a key.</p>
</a>

<a class="step-card" href="01-ping.php">
    <span class="num">1</span><h3>Ping — test the connection</h3>
    <p>Hits <span class="endpoint">/users/ping</span>. Always do this first — if auth is broken, nothing else will work.</p>
</a>

<a class="step-card" href="02-allowlist-list.php">
    <span class="num">2</span><h3>List the allowlist</h3>
    <p>Hits <span class="endpoint">/allowlists/list</span>. Shows which emails are currently allowlisted (exempt from rejection).</p>
</a>

<a class="step-card" href="03-allowlist-add.php">
    <span class="num">3</span><h3>Add to allowlist</h3>
    <p>Hits <span class="endpoint">/allowlists/add</span> — the endpoint from the docs page you shared.</p>
</a>

<a class="step-card" href="04-allowlist-delete.php">
    <span class="num">4</span><h3>Remove from allowlist</h3>
    <p>Hits <span class="endpoint">/allowlists/delete</span>. Completes the CRUD cycle so you can clean up.</p>
</a>

<a class="step-card" href="05-send.php">
    <span class="num">5</span><h3>Send a transactional email</h3>
    <p>Hits <span class="endpoint">/messages/send</span>. The core of the API — what you'll actually use in production.</p>
</a>

<a class="step-card" href="06-templates-list.php">
    <span class="num">6</span><h3>List templates</h3>
    <p>Hits <span class="endpoint">/templates/list</span>. Templates let you design emails once and reuse them with merge vars.</p>
</a>

<a class="step-card" href="07-templates-add.php">
    <span class="num">7</span><h3>Create a template</h3>
    <p>Hits <span class="endpoint">/templates/add</span>, then shows how to send using it with <span class="endpoint">/messages/send-template</span>.</p>
</a>

<a class="step-card" href="08-stats.php">
    <span class="num">8</span><h3>Account stats</h3>
    <p>Hits <span class="endpoint">/users/info</span> and <span class="endpoint">/tags/all-time-series</span> to show sending reputation and recent activity.</p>
</a>

<h2>How it's organised</h2>

<p>The demo is deliberately flat — no framework, no Composer. Just PHP files you can read top-to-bottom:</p>

<table>
<tr><th>File</th><th>What it does</th></tr>
<tr><td><code>config.php</code></td><td>Holds your API key and the default sender identity.</td></tr>
<tr><td><code>lib.php</code></td><td>One function — <code>mandrill_call()</code> — that every page uses. Wraps cURL and returns a structured result.</td></tr>
<tr><td><code>header.php</code> / <code>footer.php</code></td><td>Shared HTML shell and navigation.</td></tr>
<tr><td><code>style.css</code></td><td>Styling. No dependencies.</td></tr>
<tr><td><code>01-...</code> &ndash; <code>08-...</code></td><td>One page per API call.</td></tr>
</table>

<p class="muted">
    Every page renders a "What just happened?" panel showing the exact JSON that
    was sent and received (with the API key redacted) so you can learn the shape
    of each endpoint by doing.
</p>

<?php require 'footer.php'; ?>
