DEV Community

anusha
anusha

Posted on

I Built a Voice AI Payment Collection Demo That Keeps Card Details Out of the Assistant

Voice AI payment collection is tricky because the most impressive part of the demo is also the part you should not let the model handle.

An assistant can verify a caller, explain an account balance, answer billing questions, and negotiate a payment plan. But once the caller is ready to enter card details, the assistant should step aside.

I built a Telnyx code example that does exactly that.

The code example:
https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-pci-protected-payment-collection-python

The Flow

A caller dials a Telnyx number for a billing line. Telnyx sends the inbound call event to a Flask webhook. The app answers with Voice API and starts a Telnyx AI Assistant.

The assistant explains what the line can do: account status, billing questions, payment plans, and secure keypad payment collection. Then it verifies the caller by full name and date of birth.

After verification, the assistant can disclose the account balance and help the caller choose a payment plan. If the caller agrees to pay, the assistant calls a backend webhook tool called start_secure_payment.

That tool starts Telnyx Pay over Voice. From that point on, the caller enters card details with the phone keypad. The assistant does not ask for the numbers, does not hear the numbers, and does not receive the keypad digits.

Why This Pattern Matters

The pattern is simple:

  • AI handles the conversation
  • Pay over Voice handles card entry
  • The app records only sanitized payment status

That split is the point of the sample.

If you let a general voice agent collect card numbers, you immediately create a logging, recording, transcript, and storage problem. Even if the assistant is "just helping," the raw payment data can end up in places it does not belong.

Pay over Voice moves that sensitive step into a purpose-built IVR flow. Telnyx prompts for card number, expiration date, billing ZIP, and security code. The caller enters those values by keypad, and Telnyx sends payment progress/completion events back to the app.

The local dashboard in the sample is intentionally boring in the right way. It shows high-level proof that the secure payment flow started and completed. It does not show raw PAN, CVV, expiration date, billing ZIP, or raw DTMF.

What The Demo Shows

The sample includes:

  • Flask webhook handling for inbound Voice API events
  • AI Assistant startup with ai_assistant_start
  • Assistant webhook tools
  • Pay Connector provisioning
  • Pay over Voice start command
  • Mock payment processor endpoint
  • Sanitized event dashboard
  • Test-mode payment flow

The demo customer is Jordan Lee, with a past-due balance of $342.50. A good demo path is:

caller: jordan lee
caller: march fifteenth nineteen ninety
caller: can i do forty dollars a week?
caller: yes, start the secure payment
Enter fullscreen mode Exit fullscreen mode

Then Pay over Voice takes over. For test mode, enter:

4111111111111111
0827
94111
123
Enter fullscreen mode Exit fullscreen mode

Run It Locally

git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/ai-pci-protected-payment-collection-python
cp .env.example .env
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
ngrok http 5000
Enter fullscreen mode Exit fullscreen mode

Set your public URL and API key in .env, then provision the assistant:

python provision_assistant.py
python app.py
Enter fullscreen mode Exit fullscreen mode

Point your Voice API application webhook to:

https://<ngrok-id>.ngrok-free.app/webhooks/voice
Enter fullscreen mode Exit fullscreen mode

Call your Telnyx number and walk through the billing flow.

Where To Take It Next

For a production implementation, replace the mock payment processor with your actual processor, review PCI scope with your compliance team, verify webhook signatures, and store only the sanitized payment outcome your business process needs.

The assistant should keep the same boundary: explain, verify, plan, and hand off. It should never ask for card details out loud.

Resources

Top comments (0)