# Agent Pay

Take a payment while you're on the phone with a customer, without ever hearing or seeing their card. Built for call centers and front desks, and for AI phone agents.

Pick how the customer pays:

| Mode | What happens | Needs |
| --- | --- | --- |
| `link` | We text and/or email a payment link. They pay on their phone with a card, Apple Pay, Google Pay or their bank. | A mobile number (with the caller's OK to text) or an email |
| `keypad_callback` | We call the customer from the PayLynks pay line. They hear who's calling and the amount, press 1, key in their card, hear the total and press 1 to pay. | The pay line set up for your account, the customer's phone number, and their OK to be called |
| `keypad_transfer` | You transfer the caller to the PayLynks pay line. We recognize their number (or they enter a 6-digit code), they key in their card, hear the total and press 1. | The pay line set up for your account |
| `keypad_call` | The caller keys in their card on this call while you stay on the line. You see `•••• 4242` and `xxx`, never the digits, and the tones are muted for you and the recording. | Calls on a PCI-mode Twilio account, and the call's SID |

In the dashboard, open **Agent Pay**. The status updates live: link sent, opened, declined (with the reason), paid.

## API

```bash
curl -X POST https://paylynks.io/api/v1/agent_payments -H "Authorization: Bearer $PAYLYNKS_SECRET_KEY" \
  -H "Content-Type: application/json" -d '{
    "mode": "link",
    "amount": 12500,
    "description": "Balance on account 4471",
    "reference": "4471",
    "customer": { "name": "Pat Lee", "phone": "+19135550142" },
    "channels": ["sms"],
    "sms_consent": true
  }'
```

The response (and `GET /api/v1/agent_payments/:id`) tells you where things stand:

```json
{
  "id": "apay_…", "mode": "link", "status": "open",
  "stage": "opened", "headline": "Customer opened the link",
  "next": "They're on the payment page now. Stay on the line until it shows as paid.",
  "amount": 12500, "amount_paid": null,
  "link": { "url": "https://paylynks.io/r/…" },
  "timeline": [{ "at": "…", "type": "created", "text": "Payment link for $125.00 created" }, …]
}
```

`status` is `open`, `succeeded`, `failed`, `canceled` or `expired`. Poll every couple of seconds while the caller is on the line. Links expire after 24 hours and keypad sessions after 30 minutes.

### Pay line

```json
{ "mode": "keypad_transfer", "amount": 12500, "description": "Deposit", "customer": { "phone": "+19135550142" } }
```

The response has `pay_line.number` and `pay_line.code`. Transfer the caller to the number. If they call from the phone number you gave, they go straight to card entry; otherwise they enter the code.

### We call them

```json
{ "mode": "keypad_callback", "amount": 12500, "description": "Deposit", "customer": { "name": "Pat Lee", "phone": "+19135550142" }, "call_consent": true }
```

`stage` follows the call: `calling`, `ringing`, `answered`, then `entering_card`, `confirming` and `paid`. If they don't pick up you get `no_answer` (status `failed`); send a link instead. Canceling hangs up the call.

### Keypad on the live call

```json
{ "mode": "keypad_call", "amount": 12500, "description": "Deposit", "call_sid": "CA…" }
```

Then:

1. `POST /api/v1/agent_payments/:id/start_capture`: Twilio starts listening for the card number. Tell the caller to key it in and press pound. We move to expiration, security code and ZIP on our own; `live_call.current` says which one they're on, and `next` gives you the words.
2. If they get one wrong: `POST …/recapture` with `{ "field": "expiration" }`.
3. When `stage` is `card_ready`, read `live_call.quote.amount_total` to the caller (it includes any surcharge), then `POST …/charge` with `{ "expected_total": 12875 }`.

Other actions: `POST …/cancel`, and `POST …/resend` (links, optional `channels`).

## AI agents

The MCP server has `start_agent_payment` and `get_agent_payment`, so a phone agent can text a link mid-call and wait for it to be paid.

## Security

Card data never reaches PayLynks or your agents: links use Stripe's secure fields, and keypad entry goes from Twilio straight to the processor. Agent Pay keeps you out of the conversation with the card, but your own PCI DSS responsibilities (for example, not writing card numbers down) still apply.

## What about spoken card numbers?

Twilio's secure capture takes keypad entry only. A card number spoken aloud would pass through speech recognition, which puts the whole voice path in PCI scope, so Agent Pay doesn't offer it yet.
