Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

How to capture your first payment using <Pay>


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(link takes you to an external page) Pay Connector to charge a credit card.

pay-diagram-1-final.<Pay>
  • Create a Twilio Function that handles the payment result and provides new TwiML instructions
  • Buy a Twilio phone number
  • Configure the Twilio phone number to use the TwiML Bin for incoming calls
  • Test capturing credit card details and see the resulting charge on your Stripe account

  • 1. Enable PCI Mode

    1-enable-pci-mode page anchor

    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.

    (error)

    Danger

    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:

    1. Navigate to the Twilio Voice Settings(link takes you to an external page) in the Twilio Console. (In the left navigation pane, click on Voice > Settings > General .)
    2. Click on the Enable PCI Mode button.

      Enable PCI Mode.

      _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.)

    3. Click the Save button at the bottom of the page.

    5. Create a Twilio Function to handle the payment result

    5-create-a-twilio-function-to-handle-the-payment-result page anchor

    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.

    1. Navigate to the Functions > Services page(link takes you to an external page) in your Twilio Console.
    2. Click on the Create Service button to create a new Functions service.
    3. In the Name your Service pop up, give your service the name pay-with-stripe-action-url
    4. Click Next on the Name your Service pop up.
    5. In the Functions pane on the top left, rename the /path_1 Function to /pay and hit Enter.

      Rename the function to '/pay'.Rate this page:

      Need some help?

      Terms of service

      Copyright © 2024 Twilio Inc.