In this tutorial, you will create an interactive voice response (IVR) that collects payment details from a customer and passes the information in a PCI-compliant manner to your payment processor of choice. This tutorial uses a TwiML Bin with the <Pay> verb and the Stripe Pay Connector to charge a credit card.
<Pay>
In order to use any of Twilio's Pay Connectors, you must enable PCI mode on your Twilio account. This ensures that Twilio will capture the payment details from your customers in a PCI-compliant manner and redact any sensitive PCI information from any call logs.
PCI Mode will redact sensitive information from ALL of your account's logs. Turning on PCI Mode cannot be undone.
If you want to avoid redacting information from all logs on an account, consider creating another Twilio account, enable PCI Mode on that account, and use that account when collecting payments with <Pay>
or Agent Assist/Payment API.
To enable PCI Mode, complete the following steps:
Click on the Enable PCI Mode button.
_10<?xml version="1.0" encoding="UTF-8"?>_10<Response>_10 <Say>Calling Twilio Pay</Say>_10 <Pay paymentConnector="Default" action="" chargeAmount="20.45"/>_10</Response>
Notice how the <Pay>
verb has three attributes: paymentConnector
, action
, and chargeAmount
.
The paymentConnector
attribute's value is the Pay Connector you want to use with this <Pay>
verb. In this case, it's the Generic Pay Connector you just created called "Default".
The action
attribute is left blank for now. This attribute will be a URL. Upon the completion of a <Pay>
transaction, Twilio will send a webhook to your action
URL to get a new set of TwiML instructions. We'll create an endpoint in the next step that handles the request to this this action
attribute.
The chargeAmount
attribute is set to 20.45
, representing a charge of $20.45. (If you wanted to create a tokenize transaction, you would set this attribute value to 0 or omit the attribute altogether.)
When <Pay>
completes capturing the consumers' credit card the Pay Connector initiates a transaction with the Payment Provider. Next, the Twilio sends an HTTP request to <Pay>
's action
URL with a status
returned.
You will use Twilio's Serverless Functionsto write and host the endpoint for our action
URL. Twilio Functions allow you deploy Node.js-based applications without needing to install anything locally on your own machine.
In the Functions pane on the top left, rename the /path_1
Function to /pay
and hit Enter.