Skip to main content

Twilio Integration

Add PCI-compliant voice payments to a voice application you’ve built directly on Twilio. This guide is for developers who orchestrate their own call flow using TwiML or the Twilio REST API — if you’re using a voice agent platform like VAPI, Retell, or Outbox, see the platform-specific guides or Custom Platform guide instead.

How It Works

1

Your app creates a payment session

When your call flow needs to collect a payment, your server calls the Maven API with the amount and caller’s phone number.
2

Your app transfers the caller

Maven returns a phone number. Your server responds with TwiML that dials that number, preserving the original caller ID.
3

Maven collects the payment

Maven handles the entire card collection conversation — card number, expiry, CVV, and ZIP code. Your app is never exposed to card data (PCI compliant).
4

Caller returns to your app

After payment, Maven transfers the caller back to your callback number. You receive a webhook with the payment result.

Prerequisites

  1. A Maven account with an API key
  2. An app with a payment gateway connected
  3. A Twilio account with a phone number

Step 1 — Create a Payment Session

When your call flow reaches the payment step, create a session from your server:
The response includes:

Step 2 — Transfer with TwiML

Respond to the Twilio webhook with a <Dial> that transfers the caller to Maven’s payment line. The critical detail: set callerId to the customer’s phone number, not your Twilio number.
This generates:
callerId must be the customer’s phone number. Maven matches sessions by the caller ID on the inbound leg. If you use your Twilio number as the caller ID, the session won’t connect.

Step 3 — Handle the Result

After the payment completes and the caller is transferred back, Twilio hits your action URL. You can look up the session result:
You’ll also receive a webhook with the full payment details (card brand, last 4, gateway transaction IDs).

Full Example

Here’s a minimal FastAPI app that handles the complete flow:

Caller ID Verification

If sessions are created but calls aren’t connecting, verify the session exists for the right number:
If this returns the session but calls still don’t connect, the callerId on your <Dial> doesn’t match the caller you passed to session creation.

Next

Webhooks

Get notified when sessions complete.

API Reference

Explore the full API.

Testing

Test with test cards and test mode keys.

Custom Platform

Integrating via a voice agent platform instead?