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
str | NoneDefaults to None

Custom control ID. Auto-generated if not provided.

input_method
str | NoneDefaults to None

How the caller provides payment info.

  • "dtmf" — caller enters digits on the keypad
  • "speech" — caller speaks the payment information
status_url
str | NoneDefaults to None

URL to receive payment status webhooks.

payment_method
str | NoneDefaults to None

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

timeout
str | NoneDefaults to None

Timeout for the payment session.

max_attempts
str | NoneDefaults to None

Maximum number of input attempts before failing.

security_code
str | NoneDefaults to None

Whether to collect CVV.

  • "true" — prompt the caller for the security code
  • "false" — skip security code collection
postal_code
str | NoneDefaults to None

Whether to collect postal code.

  • "true" — prompt the caller for the postal code
  • "false" — skip postal code collection
min_postal_code_length
str | NoneDefaults to None

Minimum length for the postal code.

token_type
str | NoneDefaults to None

Tokenization type for the payment data.

charge_amount
str | NoneDefaults to None

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

currency
str | NoneDefaults to None

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

language
str | NoneDefaults to None

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

voice
str | NoneDefaults to None

Voice for TTS prompts during the payment flow.

description
str | NoneDefaults to None

Description of the payment/charge.

valid_card_types
str | NoneDefaults to None

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

parameters
list[dict] | NoneDefaults to None

Additional parameters to pass to the payment connector.

prompts
list[dict] | NoneDefaults to None

Custom prompts for the payment flow.

on_completed
Callable[[RelayEvent], Any] | NoneDefaults to None

Callback invoked when the payment operation completes.

Returns

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

Example

from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
@client.on_call
async def handle_call(call):
await call.answer()
await call.play([{"type": "tts", "params": {"text": "We will now collect your payment."}}])
action = await call.pay(
payment_connector_url="https://example.com/payment-connector",
charge_amount="29.99",
currency="USD",
security_code="true",
postal_code="true",
)
event = await action.wait()
state = event.params.get("state", "")
if state == "finished":
await call.play([{"type": "tts", "params": {"text": "Payment processed successfully."}}])
else:
await call.play([{"type": "tts", "params": {"text": "Payment failed. Please try again later."}}])
await call.hangup()
client.run()