Payment Resource
Agent-assisted payments
Introduction
Agent-assisted payments allow agents to collect customer payment information in a PCI-compliant manner on Twilio voice calls in the contact center. With agent-assisted payments, the agent stays on the phone and guides the customer through the payment flow, requesting the various required pieces of payment information one item at a time.
The agent can control the payment flow asking for payment information in the order they see best for the customer and even re-request information as needed. When the customer is entering their payment information, the agent will not be able to hear the DTMF (Dual-Tone Multi-Frequency) tones, ensuring PCI DSS (Payment Card Industry Data Security Standard) compliance of the payment information and the security of the customer payment information.
Once the agent has progressed through all the steps to gather the payment information from the customer, they complete the capture via Twilio. Twilio sends the payment information directly to the payment connector for processing, ensuring no card information is ever divulged to the agent.
Workflow
- Agent requests some information, including payment method, from the customer and begins a Twilio Pay session.
- Agent triggers API calls through their UI to collect specific pieces of payment information from the customer, e.g., credit card number, expiration date, or bank account number.
- The Caller enters the requested payment information using their phone keypad. Agents are not able to hear any DTMF tones.
- Once the customer is done, the agent sees the result of the customer’s input, e.g.,
xxxx xxxx xxxx 4242
orinvalid-card-number
. - Agent requests the next piece of required payment information and continues to do so until all the information needed is entered.
- The agent can re-request a piece of payment information as needed in any order and at any point during the flow.
- The agent is also able to cancel the payment at any point during the flow.
- Once all the information is collected, the agent completes the Pay session and receives the result of the payment.
API design and workflow
With Agent assistance the key is to capture customer information while the Agent is on the call with the customer. This means the agent can interact with the customer guiding them through the experience of entering their card details. A typical agent flow is outlined below:
- The agent collects and enters information like payment method, charge amount or token type, and then starts the Pay session.
- The agent then calls the Update API (through their own UI) for each piece of payment information in succession.
- If customers make a mistake while entering information, the agent simply calls the Update API again to re-capture that particular information.
- Once all the required payment information has been collected, the Agent completes the Pay session by setting the status to
complete
, which then processes the payment and completes the transaction. The agent can also cancel the Pay session, if required at this stage, by setting the status in the Update API tocancel
. - Resulting information in each of the calls above will be delivered via status callbacks, which can be used to update the agent UI in near real-time.
Payments properties
Resource Properties in REST API format | |
---|---|
account_sid
|
The SID of the Account that created the Payments resource. |
call_sid
|
The SID of the Call the Payments resource is associated with. This will refer to the call sid that is producing the payment card (credit/ACH) information thru DTMF. |
sid
|
The SID of the Payments resource. |
date_created
|
The date and time in GMT that the resource was created specified in RFC 2822 format. |
date_updated
|
The date and time in GMT that the resource was last updated specified in RFC 2822 format. |
uri
|
The URI of the resource, relative to |
Starting a Pay session
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json
Parameters
Parameters in REST API format | |
---|---|
account_sid
Path
|
The SID of the Account that will create the resource. |
call_sid
Path
|
The SID of the call that will create the resource. Call leg associated with this sid is expected to provide payment information thru DTMF. |
idempotency_key
Required
|
A unique token that will be used to ensure that multiple API calls with the same information do not result in multiple transactions. This should be a unique string value per API call and can be a randomly generated. |
status_callback
Required
|
Provide an absolute or relative URL to receive status updates regarding your Pay session. Read more about the expected StatusCallback values |
bank_account_type
Optional
|
Type of bank account if payment source is ACH. One of |
charge_amount
Optional
|
A positive decimal value less than 1,000,000 to charge against the credit card or bank account. Default currency can be overwritten with |
currency
Optional
|
The currency of the |
description
Optional
|
The description can be used to provide more details regarding the transaction. This information is submitted along with the payment details to the Payment Connector which are then posted on the transactions. |
input
Optional
|
A list of inputs that should be accepted. Currently only |
min_postal_code_length
Optional
|
A positive integer that is used to validate the length of the |
parameter
Optional
|
A single-level JSON object used to pass custom parameters to payment processors. (Required for ACH payments). The information that has to be included here depends on the |
payment_connector
Optional
|
This is the unique name corresponding to the Pay Connector installed in the Twilio Add-ons. Learn more about |
payment_method
Optional
|
Type of payment being captured. One of |
postal_code
Optional
|
Indicates whether the credit card postal code (zip code) is a required piece of payment information that must be provided by the caller. The default is |
security_code
Optional
|
Indicates whether the credit card security code is a required piece of payment information that must be provided by the caller. The default is |
timeout
Optional
|
The number of seconds that |
token_type
Optional
|
Indicates whether the payment method should be tokenized as a |
valid_card_types
Optional
|
Credit card types separated by space that Pay should accept. The default value is |
Example 1
StatusCallback
Provide an absolute or relative URL for this parameter. Twilio Pay will make a POST
request to this URL whenever there is an update to the Parameter being captured. The POST
request will have the following parameters:
Parameter |
Description |
|
The unique identifier of the Account responsible for this pay session |
|
The unique identifier for the call associated with the pay session. |
|
The unique identifier of the current Pay session |
|
The date when the Pay session was started |
|
If the |
|
If not tokenizing — i.e., the charge amount is specified and greater than zero — the amount to charge the payment method |
|
The unique name of Payment Connector corresponding to the Pay Connector installed in the Twilio Add-ons |
|
|
|
One-time or reusable if charge amount not specified |
All StatusCallback
requests will contain these fields. Additional StatusCallback
values can be found during the Update
and Complete/Cancel
APIs.
Update a Pay session
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json
Parameters
Parameters in REST API format | |
---|---|
account_sid
Path
|
The SID of the Account that will update the resource. |
call_sid
Path
|
The SID of the call that will update the resource. This should be the same call sid that was used to create payments resource. |
sid
Path
|
The SID of Payments session that needs to be updated. |
idempotency_key
Required
|
A unique token that will be used to ensure that multiple API calls with the same information do not result in multiple transactions. This should be a unique string value per API call and can be a randomly generated. |
status_callback
Required
|
Provide an absolute or relative URL to receive status updates regarding your Pay session. Read more about the Update and Complete/Cancel POST requests. |
capture
Optional
|
The piece of payment information that you wish the caller to enter. Must be one of |
status
Optional
|
Indicates whether the current payment session should be cancelled or completed. When |
Example 1
StatusCallback (Update)
Provide an absolute or relative URL for this parameter. Twilio Pay will make a POST request to this URL whenever the Update API is called and whenever there is an update to the Parameter being captured. The POST request will contain all of common StatusCallback parameters as well as these additional parameters:
Parameter |
Description |
|
The date when the Pay session was last updated |
|
If the |
|
If the |
|
The piece of payment information that Pay was expecting |
|
If not tokenizing — i.e., the charge amount was specified and greater than zero — the amount to charge the payment method |
|
The full list of error types is visible here |
|
If the |
|
|
|
If the |
|
If the |
|
If the |
|
The pieces of payment information that remain to be collected. For example, if postal code and security code are false and credit card number has already been input, then |
|
If the |
Status
Indicate whether the current payment session should be cancelled or completed when this API request is made. When the status is cancel
, the payment session will be cancelled. You will have to use the Start API to start a new payment session. When the status is complete
, Twilio sends the payment information to the selected Pay connector for processing.
Example 2
Example 3
StatusCallback (Cancel/Complete)
Provide an absolute or relative URL for this parameter. Twilio Pay will make a POST
request to this URL whenever the Cancel/Complete API is called. The POST
request will contain all of common StatusCallback parameters as well as these additional parameters:
Parameter |
Description |
|
The date when the Pay session was last updated |
|
This parameter contains the error code/message received from the underlying payment gateway |
|
A numerical error code that gives more details about the error. To learn more about the error, please visit the error page and search for the error code |
|
Payment error for failures. For example, |
|
If the payment method provided was charged and not tokenized, this is the confirmation code from the Payment Gateway |
|
The tokenized value of the credit card or ACH payment data. Payment will not be tokenized if a charge amount is provided. Values:
|
|
The identifier of the customer object to which the payment is associated. Can be used as a token depending on the Connector. Payment will not be tokenized if a charge amount is provided. Values:
|
The result of the transaction. See the table below for all the values |
Result
Result |
Description |
|
Twilio successfully captured the payment data and either tokenized or processed the payment |
|
Twilio Pay experienced an error communicating with Payment Gateway |
|
Caller pressed the * (star) key to interrupt the Pay session |
|
The caller hung up the call |
|
An invalid parameter value, e.g., |
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.