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

paymentConnectorUrl
stringRequired

URL of the payment connector service that processes the payment.

controlId
string | undefined

Custom control ID. Auto-generated if not provided.

inputMethod
string | undefined

How the caller provides payment info.

  • "dtmf" — caller enters digits on the keypad
  • "speech" — caller speaks the payment information
chargeAmount
string | undefined

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

currency
string | undefined

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

securityCode
string | undefined

Whether to collect CVV ("true" or "false").

postalCode
string | undefined

Whether to collect postal code ("true" or "false").

statusUrl
string | undefined

URL to receive payment status webhooks.

paymentMethod
string | undefined

Payment method type (e.g., "credit-card").

timeout
string | undefined

Timeout for the payment session.

maxAttempts
string | undefined

Maximum number of retry attempts for failed input.

minPostalCodeLength
string | undefined

Minimum length required for the postal code.

tokenType
string | undefined

Type of payment token to generate.

language
string | undefined

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

voice
string | undefined

Voice for payment prompts.

description
string | undefined

Description of the payment or charge.

validCardTypes
string | undefined

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

parameters
Record<string, unknown>[] | undefined

Additional payment connector parameters.

prompts
Record<string, unknown>[] | undefined

Custom prompt overrides for the payment flow.

onCompleted
(event: RelayEvent) => void | Promise<void>

Callback invoked when the payment operation completes.

Returns

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

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_TOKEN!,
6 contexts: ['default']
7});
8
9client.onCall(async (call) => {
10 await call.answer();
11 await call.play([{ type: 'tts', text: 'We will now collect your payment.' }]);
12
13 const action = await call.pay('https://example.com/payment-connector', {
14 chargeAmount: '29.99',
15 currency: 'USD',
16 securityCode: 'true',
17 postalCode: 'true',
18 });
19 const event = await action.wait();
20
21 const state = (event.params.state ?? '') as string;
22 if (state === 'finished') {
23 await call.play([{ type: 'tts', text: 'Payment processed successfully.' }]);
24 } else {
25 await call.play([{ type: 'tts', text: 'Payment failed. Please try again later.' }]);
26 }
27
28 await call.hangup();
29});
30
31await client.run();