Skip to navigation

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.

For a walkthrough that takes a payment end to end, see the take payments on a call guide.

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

import { RelayClient } from '@signalwire/sdk';
const client = new RelayClient({
project: process.env.SIGNALWIRE_PROJECT_ID!,
token: process.env.SIGNALWIRE_API_TOKEN!,
contexts: ['default']
});
client.onCall(async (call) => {
await call.answer();
await call.play([{ type: 'tts', text: 'We will now collect your payment.' }]);
const action = await call.pay('https://example.com/payment-connector', {
chargeAmount: '29.99',
currency: 'USD',
securityCode: 'true',
postalCode: 'true',
});
const event = await action.wait();
const state = (event.params.state ?? '') as string;
if (state === 'finished') {
await call.play([{ type: 'tts', text: 'Payment processed successfully.' }]);
} else {
await call.play([{ type: 'tts', text: 'Payment failed. Please try again later.' }]);
}
await call.hangup();
});
await client.run();