RELAYCall

pay

View as MarkdownOpen in Claude

Start a payment collection session on the call. Collects credit card or other payment information from the caller via DTMF. Returns a PayAction that you can use to stop the payment flow or wait for it to complete.

This method emits calling.call.pay events. See Call Events for payload details.

Parameters

payment_connector_url
strRequired

URL of the payment connector service that processes the payment.

control_id
Optional[str]

Custom control ID. Auto-generated if not provided.

input_method
Optional[str]

How the caller provides payment info.

  • "dtmf" — caller enters digits on the keypad
  • "speech" — caller speaks the payment information
status_url
Optional[str]

URL to receive payment status webhooks.

payment_method
Optional[str]

Payment method type. Valid values: "credit-card".

timeout
Optional[str]

Timeout for the payment session.

max_attempts
Optional[str]

Maximum number of input attempts before failing.

security_code
Optional[str]

Whether to collect CVV.

  • "true" — prompt the caller for the security code
  • "false" — skip security code collection
postal_code
Optional[str]

Whether to collect postal code.

  • "true" — prompt the caller for the postal code
  • "false" — skip postal code collection
min_postal_code_length
Optional[str]

Minimum length for the postal code.

token_type
Optional[str]

Tokenization type for the payment data.

charge_amount
Optional[str]

Amount to charge (e.g., "29.99").

currency
Optional[str]

Currency code (e.g., "USD", "EUR").

language
Optional[str]

Language for payment prompts (e.g., "en").

voice
Optional[str]

Voice for TTS prompts during the payment flow.

description
Optional[str]

Description of the payment/charge.

valid_card_types
Optional[str]

Comma-separated list of accepted card types (e.g., "visa,mastercard,amex").

parameters
Optional[list[dict]]

Additional parameters to pass to the payment connector.

prompts
Optional[list[dict]]

Custom prompts for the payment flow.

on_completed
Optional[Callable[[RelayEvent], Any]]

Callback invoked when the payment operation completes.

Returns

PayAction — An action handle with stop() and wait() methods.

Example

1from signalwire.relay import RelayClient
2
3client = RelayClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7 contexts=["default"],
8)
9
10@client.on_call
11async def handle_call(call):
12 await call.answer()
13 await call.play([{"type": "tts", "text": "We will now collect your payment."}])
14
15 action = await call.pay(
16 payment_connector_url="https://example.com/payment-connector",
17 charge_amount="29.99",
18 currency="USD",
19 security_code="true",
20 postal_code="true",
21 )
22 event = await action.wait()
23
24 state = event.params.get("state", "")
25 if state == "finished":
26 await call.play([{"type": "tts", "text": "Payment processed successfully."}])
27 else:
28 await call.play([{"type": "tts", "text": "Payment failed. Please try again later."}])
29
30 await call.hangup()
31
32client.run()