TwiML™ Voice: <Prompt>
The TwiML's <Pay> Verb's <Prompt> noun allows you to customize the default prompts used by <Pay>.
For example, by default when asking a user to input a credit card number <Pay> will say "Please enter your 15 to 16 digit credit card number". You can override that to "Please enter your 15 digit Visa or Mastercard number" with the following TwiML:
Or use the following TwiML to replace Text-to-Speech with a pre-recorded audio file:
<Prompt> Attributes
The following attributes on <Prompt> allow you to customize the messages played by <Pay>:
属性名 | 許容値 | Default Values |
---|---|---|
for | payment-card-number, expiration-date, security-code, postal-code, bank-routing-number, bank-account-number, payment-processing | none, required. |
errorType | timeout, invalid-card-number, invalid-card-type, invalid-date, date-validation-failed, invalid-security-code, invalid bank routing number, invalid bank account number | None. Multiple values can be provided space separated. |
cardType | visa, master-card, amex, maestro, discover, optima, jcb, diners-club, enroute | none, optional. Multiple values can be provided space separated. |
attempt | 1 to 10 | Multiple values can be provided space separated. See examples. |
for
The following are possible values of for
:
for | 概要 |
---|---|
payment-card-number | Use to customize messages played for asking for credit or debit card information. |
expiration-date | Use to customize messages played for asking for expiration date. |
security-code | Use to customize messages played for asking for security code (CVV). |
postal-code | Use to customize messages played for asking for postal code. |
bank-routing-number | Use to customize messages played for asking for Bank Routing Number. |
bank-account-number | Use to customize messages played for asking Bank Account Number. |
payment-processing | Use to customize messages played before processing the payment. |
errorType
The following are possible values of errorType
:
errorType | 概要 |
---|---|
Timeout | <Pay> received a timeout when executing a specific Step. |
invalid-card-number | <Pay> didn’t receive the appropriate number of digits for either credit card number, expiration date, security code or zip code. Or card number entered didn’t pass the validation. This reason can be used to apply further customization on the message to play such as informing payee/caller that the incorrect number of digits were entered. |
invalid-card-type | The card number entered didn’t match the accepted card types. For example, if only visa or master-card are accepted and payee enters amex, InvalidReason parameter will contain this value. |
invalid-date | <Pay> didn’t receive the correct number of digits for the date. |
date-validation-failed | The expiration date entered was in the past or incorrect. |
invalid-security-code | This reason is generated when the payee entered an invalid security code. For example, if Credit Card number is amex and user entered 3 digits for the security code. |
invalid-postal-code | <Pay> didn’t receive the correct number of digits for the postal/zip code. |
invalid-bank-routing-number | <Pay> either didn't receive the appropriate number of digits for the routing number or the routing number provided failed the validation performed by <Pay>. |
invalid-bank-account-number | <Pay> didn't receive the minimum number of digits required for the bank account number. |
cardType
The cardType attribute allows you to override <Prompt> for specific credit card types.
This is useful to customize the prompt when asking for a security code, as different cards handle security codes differently. For example, the following TwiML says a custom message if the credit card number provided by the caller was a Visa card:
The following TwiML says a custom message if the caller provided an American Express credit card number:
attempt
The Attempt attribute allows you to customize prompts for differents attempts within <Pay>.
The following TwiML says different message when asking for expiration date the first time Vs the 2nd or 3rd attempt in case the user timedout.
Example use of <Prompt> to accept credit card payments using <Pay>
The following examples show the TwiML you can use to customize all prompts for <Pay> when accepting a credit card payment:
<Prompt for="payment-card-number">
<Say voice="Polly.Joanna">
Please enter your credit card number.
</Say>
</Prompt>
<Prompt for="payment-card-number" errorType="timeout">
<Say>
I am sorry I didn’t hear anything. Please enter your credit card number.
</Say>
</Prompt>
<Prompt for="payment-card-number" errorType="invalid-card-number">
<Say>
That was an invalid card number. Please try again
</Say>
</Prompt>
<Prompt for="payment-card-number" errorType="invalid-card-type">
<Say>
That was an invalid card type, please try again. We only accept Insert accepted card types.
</Say>
</Prompt>
<Prompt for="expiration-date">
<Say>
Please enter your expiration date, two digits for the month and two digits for the year.
</Say>
</Prompt>
<Prompt for="expiration-date" errorType="timeout">
<Say>
I am sorry I did not hear anything. Please enter your expiration date, two digits for the month and two digits for the year. For example, to enter July twenty twenty two, enter 0 7 2 2.
</Say>
</Prompt>
<Prompt for="expiration-date" errorType="invalid-date">
<Say>
That is an invalid date. Please enter your expiration date, two digits for the month and two digits for the year. For example, to enter July twenty twenty two, enter 0 7 2 2.
</Say>
</Prompt>
<Prompt for="expiration-date" errorType="date-validation-failed">
<Say>
That is an invalid date, expiration date cannot be past date. Please try again.
</Say>
</Prompt>
<!-- If the credit card number type provided only requires 3 digit security code use the following -->
<Prompt for="security-code">
<Say>
Please enter your security code. It’s the 3 digits located in the back of your card.
</Say>
</Prompt>
<!-- If the credit card number type provided requires 4 digit security code use the following-->
<Prompt for="security-code" cardType="Amex">
<Say>
Please enter your security code. It’s the 4 digits located in the front of your card.
</Say>
</Prompt>
<!-- If the credit card number type provided requires 4 digit security code use the following-->
<Prompt for="security-code" errorType="timeout">
<Say>
I am sorry I didn’t hear anything. Please enter your security code. It’s the 4 digits located in the front of your card.
</Say>
</Prompt>
<!-- If the credit card number type provided only requires 3 digit security code use the following-->
<Prompt for="security-code" errorType="timeout">
<Say>
I am sorry I didn’t hear anything. Please enter your security code. It’s the 3 digits located in the back of your card.
</Say>
</Prompt>
<!-- If the Payee supposed to enter 3 digits but entered either less or greater than 3 digits -->
<Prompt for="security-code" errorType="invalid-security-code">
<Say>
That was an invalid security code. The security code must be 3 digits. Please try again
</Say>
</Prompt>
<!-- If the Payee supposed to enter 4 digits but entered either less or greater than 4 digits -->
<Prompt for="security-code" errorType="invalid-security-code">
<Say>
That was an invalid security code. The security code must be 4 digits. Please try again
</Say>
</Prompt>
<Prompt for="postal-code">
<Say>
Please enter your 5 digit billing zip code.
</Say>
</Prompt>
<Prompt for="postal-code" errorType="timeout">
<Say>
I am sorry I didn’t hear anything. Please enter your 5 digit billing zip code.
</Say>
</Prompt>
<Prompt for="postal-code" errorType="invalid-postal-code">
<Say>
That was an invalid billing zip code. The billing zip code must be 5 digits. Please try again
</Say>
</Prompt>
<Prompt for="payment-processing">
<Say>
Thank you, please wait while we process your payment
</Say>
</Prompt>
</Pay>
</Response>
Example use of <Prompt> to accept ACH payments using <Pay>
The following examples show the TwiML you can use to customize all prompts for <Pay> when accepting an ACH payment:
<Pay input=”dtmf” timeout=”5” maxAttempts=”3” paymentMethod=”ach” language=”en-US”>
<Prompt for=”bank-routing-number”>
<Say>
Please enter your bank routing number.
</Say>
</Prompt>
<Prompt for=”bank-routing-number” errorType=”timeout”>
</Say>
I am sorry I didn’t hear anything. Please enter your bank routing number.
</Say>
</Prompt>
<Prompt for=”bank-routing-number” errorType=”invalid-bank-routing-number”>
<Say>
That was an invalid bank routing number. Please try again.
</Say>
</Prompt>
<Prompt for=”bank-account-number”>
<Say>
Please enter your bank account number.
</Say>
</Prompt>
<Prompt for=”bank-account-number” errorType=”timeout”>
<Say>
I am sorry I did not hear anything. Please try again.
</Say>
</Prompt>
<Prompt for=”payment-processing”>
<Say>
Thank you, please wait while we process your payment
</Say>
</Prompt>
</Pay>
ヘルプが必要ですか?
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.