pay

View as MarkdownOpen in Claude

Collect and process a credit card payment during the call. Generates a SWML pay verb that walks the caller through entering card details via DTMF or voice, then submits to your payment connector endpoint.

Parameters

payment_connector_url
strRequired

URL of your payment processing endpoint. SignalWire sends the collected card data to this URL for processing.

input_method
strDefaults to dtmf

How the caller provides card details.

  • "dtmf" — caller enters digits on the keypad
  • "voice" — caller speaks the numbers
status_url
Optional[str]Defaults to None

URL to receive payment status change webhook notifications.

payment_method
strDefaults to credit-card

Payment method type. Currently only "credit-card" is supported.

timeout
intDefaults to 5

Seconds to wait for the next DTMF digit before timing out.

max_attempts
intDefaults to 1

Number of retry attempts if payment collection fails.

security_code
boolDefaults to True

Whether to prompt the caller for the card’s security code (CVV).

postal_code
bool | strDefaults to True

Whether to prompt for the billing postal code. Pass True to prompt, False to skip, or a string with the actual postal code to use without prompting.

min_postal_code_length
intDefaults to 0

Minimum number of digits required for the postal code.

token_type
strDefaults to reusable

Payment token type.

  • "one-time" — single-use token
  • "reusable" — token can be charged again later
charge_amount
Optional[str]Defaults to None

Amount to charge as a decimal string (e.g., "49.99").

currency
strDefaults to usd

ISO 4217 currency code (e.g., "usd", "eur").

language
strDefaults to en-US

Language for TTS payment prompts (e.g., "en-US", "es-MX").

voice
strDefaults to woman

TTS voice for payment prompts (e.g., "woman", "man").

description
Optional[str]Defaults to None

Custom description for the payment transaction.

valid_card_types
strDefaults to visa mastercard amex

Space-separated list of accepted card types.

parameters
Optional[list[dict[str, str]]]Defaults to None

Additional name/value pairs to send to the payment connector. Use create_payment_parameter() to build entries.

prompts
Optional[list[dict[str, Any]]]Defaults to None

Custom prompt configurations to override default payment prompts. Use create_payment_prompt() to build entries.

ai_response
Optional[str]Defaults to 'The payment status is ${pay_result}...'

AI response template after payment completes. The ${pay_result} variable is substituted with the payment outcome. Set to None to disable.

Returns

FunctionResult — self, for chaining.

Example

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="collect_payment", description="Collect a credit card payment")
8def collect_payment(args, raw_data):
9 amount = args.get("amount")
10 return (
11 FunctionResult("I'll collect your payment information now.")
12 .pay(
13 payment_connector_url="https://api.example.com/payment",
14 charge_amount=amount,
15 currency="usd",
16 security_code=True,
17 postal_code=True
18 )
19 )
20
21agent.serve()