Skip to content

Add Take payments on a call guide - #867

Open
Manny-r31 wants to merge 18 commits into
mainfrom
Manny/Take-Payments-On-Call-Guide
Open

Manny-r31 wants to merge 18 commits into
mainfrom
Manny/Take-Payments-On-Call-Guide

Conversation

@Manny-r31

@Manny-r31 Manny-r31 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #770. Part of #765.

Merge after #833. Both PRs edit the SWML pay and cXML <Pay> reference pages. This PR only adds a one-sentence backlink to each, so I'll rebase once #833 merges.

Summary

  • New task-first capability guide, Take payments on a call (voice/take-payments). It covers:
    • which product to use for taking payments
    • how a payment works, with a themed diagram and a mermaid twin
    • building your own payment connector (stub servers in Python and TypeScript)
    • a first payment walkthrough
    • charging a card and saving a card as a token
    • prompt and card options, and handling the result
    • stopping collection from Relay
    • taking a payment from an AI agent with FunctionResult.pay
    • PCI compliance
  • The surfaces covered are SWML and Relay. REST, the Browser SDK and Call Flow Builder are marked unavailable. The Compatibility API <Pay> is left out of the guide to keep the platform page SWML-native, and the <Pay> reference links to the guide instead.
  • The Dashboard has no payment connector setup to document. The guide treats the connector as an HTTPS endpoint you host and shows how to build one.
  • Cross-links:
    • a voice overview card, and a link from the overview's PCI FAQ
    • the llms.txt "Secure payments" bullet now points to the guide
    • backlinks from the SWML pay reference, the cXML <Pay> reference, Relay call.pay (Python and TypeScript), FunctionResult.pay (Python and TypeScript), the content redaction guide and Record calls
  • No nav change (the voice folder is folder-driven), no redirects, and no changelog entry, since this is documentation work.

Notes for reviewers

  • Relay PayAction.wait() and on_completed never resolve for pay in signalwire-sdk==3.4.1 or @signalwire/sdk@2.0.5. The SDK waits for a state field that calling.call.pay events don't carry. The guide's Relay samples wait for the final calling.call.pay event, the one carrying result. The existing Relay pay and PayAction reference examples call action.wait(), so they wait forever. That needs an upstream SDK fix and a reference update.

  • A declined card still plays the "payment completed" prompt. The closing prompt plays on any HTTP 200 from the connector, so a decline returned as a 200 sounds like a success to the caller, while pay_result is internal-error with payment_error: card-declined. Worth raising with the platform team. The guide branches on pay_result and doesn't rely on the prompt.

  • REST: calling.pay and calling.pay.stop work through POST /api/calling/calls, but they aren't in the API spec, so the guide marks REST as unavailable. Adding them to the spec would be a follow-up.

  • Connector signing and token_id: the guide documents current platform behavior. Connector requests are signed with X-SignalWire-Signature, and the connector's token_id comes back as payment_token. Pay fixes (SWML + cXML) #833 currently says connector requests aren't signed; my review there suggests corrected wording. Both platform changes need changelog entries dated to when they shipped, which I'll add separately once the dates are confirmed.

  • SWML pay reference errors that Pay fixes (SWML + cXML) #833 doesn't cover (not changed in this PR):

    • security_code is typed as a boolean, but the platform requires the strings "true" or "false".
    • prompts[].attempts should be attempt.
    • validation-error is described as "Card details failed validation", but failed card checks end in too-many-failed-attempts.

    Pay fixes (SWML + cXML) #833 already fixes the rest: the missing parameters, the masked card in the connector request example, and payment-completed being sent for declines.

  • Other docs and SDK inconsistencies:

    • Both SWML builders type security_code as a boolean, and the Python builder rejects "false" at runtime. The guide's "Skip the security code" example therefore uses add_verb/addVerb for that one field.
    • The content redaction guide's JSON shows security_code and postal_code as booleans.
    • The TypeScript validateWebhookSignature reference page documents a function that @signalwire/sdk@2.0.5 doesn't export. The TypeScript connector checks the signature with node:crypto.
  • Recording during collection: the guide doesn't claim that recordings pause automatically while card details are entered. It tells readers to pause recording and transcription themselves.

  • Rule drift: .claude/rules/mdx-capability-guides.md says platform.yml lists pages/calling/ pages explicitly. The voice folder is folder-driven now.

Verification

  • yarn fern-md-check: all 2831 MDX files are valid. I didn't run yarn fern-check, since no yml or redirects changed.
  • I extracted every code sample and validated it against the pinned SDKs:
    • Python: py_compile and pyflakes clean on all 12 files.
    • TypeScript: tsc --strict clean on all 12 files, and each also passes node --check as .mjs.
    • Every YAML and JSON block parses, and the cURL block passes bash -n.
    • The Python and TypeScript SWML builder output is identical to the hand-written JSON for every document.
  • I ran both stub connectors with signed requests: a charge, a zero-amount token, and a forged signature, which returned 403.
  • I checked SDK method and parameter names against the installed packages.
  • I checked every internal link against its target's slug: and every #anchor by hand. That includes the three guide anchors other pages link to: #build-a-payment-connector, #take-a-payment-from-an-ai-agent and #payments-and-pci-compliance.
  • Please check the diagram in light and dark mode, since no check covers how it renders.

Preview URLs

  • /docs/platform/voice/take-payments
  • /docs/platform/voice
  • /docs/platform/voice/record-calls
  • /docs/platform/ai/content-redaction
  • /docs/swml/reference/calling/pay
  • /docs/compatibility-api/cxml/reference/voice/pay
  • /docs/server-sdks/reference/python/relay/call/pay
  • /docs/server-sdks/reference/typescript/relay/call/pay
  • /docs/server-sdks/reference/python/agents/function-result/pay
  • /docs/server-sdks/reference/typescript/agents/function-result/pay

🤖 Generated with Claude Code

Manny-r31 and others added 2 commits October 27, 2026 14:39
New task-first capability guide at voice/take-payments covering SWML pay,
Relay call.pay, AI agents via FunctionResult.pay, the payment connector
protocol, results, and PCI. Cross-link it from the voice overview, llms.txt,
and the SWML, cXML, Relay, FunctionResult, content redaction, and record
calls pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

@Manny-r31 Manny-r31 mentioned this pull request Oct 27, 2026
6 of 13 tasks

@hey-august hey-august left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Requesting changes. The guide is in good shape, but four statements contradict the platform, three code samples fail on first run, and two smaller items need a touch. Platform behavior below is verified against source.

Blocking

  • Custom prompts do not replace SignalWire's retry prompts (take-payments.mdx:1192). The sentence "Each entry in prompts replaces SignalWire's prompt for one step" holds only for the first attempt. Prompt selection weights any error-matched prompt above a plain one, so the built-in timeout and invalid-* prompts outrank a custom prompt with no error_type. The page's own example, a plain payment-card-number prompt with max_attempts: 3, plays the stock timeout prompt on retry. State that a prompt needs the matching error_type to replace a retry prompt.
  • The HMAC is computed over the URL with credentials removed (take-payments.mdx:115 and :244). The page says the signature covers the URL "exactly as you passed it". The platform strips any user:password@ before signing and sends those as Basic auth. A reader who protects the connector with basic auth and sets the CONNECTOR_URL variable to the credentialed string gets a 403 on every request. One sentence fixes it.
  • The result table omits validation-error (take-payments.mdx:1665). The table is introduced as the full set but leaves out the validation-error value. The SWML reference this page links does list it. Add the row.
  • The reference defines payment-connector-error differently from the guide (swml/.../pay/index.mdx:753). The reference says the connector returned an error. In practice a reachable connector that answers non-200 ends as internal-error, and payment-connector-error survives only when the connector is unreachable, which is what the guide says at lines 643 and 1669. Align the reference with the guide.
  • The TypeScript connector corrupts multi-byte request bodies (take-payments.mdx:320). The statement rawBody += chunk stringifies each Buffer on its own. A UTF-8 character split across two chunks becomes U+FFFD, and the HMAC check fails intermittently on non-ASCII descriptions. Call req.setEncoding("utf8") before the loop, or collect Buffers and use Buffer.concat.
  • The stop timer leaves a promise rejection unhandled (take-payments.mdx:1931). The call setTimeout(() => void action.stop(), 120_000) discards the promise from stop(). If the platform refuses the stop, Node 15 and later terminates the handler mid-call. Add .catch(() => {}).
  • The call.pay method raises rather than returning an error (take-payments.mdx:652). The troubleshooting text says call.pay returns an error. The Python SDK raises and the TypeScript SDK rejects, and neither Relay sample catches it. An http:// connector URL produces a traceback and a hung call. Reword the sentence, and consider wrapping call.pay in a try block in both samples.

Non-blocking

  • The connector-body table should mark parameters as optional (take-payments.mdx:205). The platform omits the parameters key when none are set, the same as description. The sample body labeled as the Bayview fare body includes parameters, which the first run never sends.
  • The Python sample disables schema validation for the whole document (take-payments.mdx:1576). The sample passes schema_validation=False to SWMLService. The mdx-capability-guides rule says to bypass validation for the one verb only. The TypeScript twin already does that with addVerb.

- Explain prompt precedence: error_type outranks card_type outranks a
  plain prompt, and SignalWire's retry and Amex prompts count, so a
  plain prompt replaces only the first try. The options example now
  covers timeout retries of the card number.
- The signature covers the connector URL without user:password@, which
  SignalWire sends as Basic auth instead.
- Add validation-error to the result table; align the SWML reference's
  payment-connector-error, validation-error, and internal-error
  definitions with platform behavior, and document prompt precedence.
- TypeScript connector decodes the body across chunks (setEncoding), so
  split multi-byte characters no longer break the HMAC check.
- Catch a rejected stop() in the stop-collection samples.
- call.pay fails rather than returning an error: reword troubleshooting.
- Mark the connector body's parameters as optional, and say the sample
  body includes a ride ID.
- Python skip-security-code sample bypasses the builder check for the
  pay verb only instead of disabling validation for the document.
@Devon-White

Copy link
Copy Markdown
Collaborator

@hey-august thanks for the careful review. All of it is addressed in 794c1bb.

  1. Retry prompts: fixed. The options section now explains that a matching error_type outranks a matching card_type, which outranks a plain prompt, and that SignalWire's own retry and Amex security-code prompts count too. So a plain prompt replaces only the first try. The example's retry prompt now lists timeout, and the pay reference documents the same ranking.
  2. Signed URL without credentials: fixed. The signature paragraph, the placeholder table, and both connectors' comments now say SignalWire signs the URL without user:password@ and sends those as Basic auth.
  3. validation-error: fixed. Added to the result table. As a final result it only occurs when payment_method or bank_account_type holds an unsupported value; card entries that keep failing end in too-many-failed-attempts. I corrected the reference's definition to match.
  4. payment-connector-error in the reference: fixed. It now means "couldn't reach the connector or got no response", and internal-error covers non-200 replies, error replies, and replies without a valid ID.
  5. Multi-byte bodies: fixed with req.setEncoding("utf8"). I reproduced the failure with a body split mid-character: 403 before the fix, 200 after.
  6. Unhandled stop() rejection: fixed. The TypeScript sample now catches it, and I wrapped the Python twin's stop() the same way to keep them parallel.
  7. call.pay raises: fixed in the troubleshooting text, which also tells the reader to end the call on their phone if it's still connected. Not changed: I didn't add try blocks to the samples. The first-run walkthrough keeps samples free of error handling, and an http:// URL is a setup mistake the troubleshooting now covers.
  8. Optional parameters: fixed in the table, and the sample body is now introduced as including a ride ID from the options example.
  9. Python validation bypass: fixed. Validation stays on, and the sample sets security_code on the built pay verb. The Python SDK has no per-verb skip option.

yarn fern-md-check passes. A follow-up commit will move the guide's samples to the latest Server SDK release, unpinned.

Drop the signalwire-sdk==3.4.1 and @signalwire/sdk@2.0.5 pins. Move the
TypeScript REST dial to the positional dial(from, to, options) form, and
build the skip-security-code TypeScript sample with validation on, then
set security_code on the built pay verb, matching the Python sample.

@Devon-White Devon-White left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current head (c61ab0a) against the deployed mod_infrastructure (4733e1ce99d8, in calling13-20261028; relay_pay.c is identical on master), switchblade stable, prime-rails, and the latest Server SDKs (signalwire-sdk 3.7.6, @signalwire/sdk 3.7.1).

All nine items from the earlier review are addressed. The one change Devon declined (try blocks around call.pay) is now covered in the troubleshooting text.

Verified correct: connector request body and the parameters/description omission (pay_post_payment_request). Signing over the credential-stripped URL plus body, both headers, hex. The success rule (200 + charge_id, or token_id only for a plain-zero amount, no error). Result values and card-declined/700. pay_payment_results and final-event shapes, and the progress-event fields. Defaults, the max_attempts ≤ 3 and timeout ≥ 3 limits, and card type names. The prompt ranking (+1 card_type, +2 error_type, ties go to the later prompt). Masking and sensitive_dtmf. https enforcement in both the SWML and Relay schemas. Every SWML builder sample outputs exactly the YAML and JSON beside it, and both FunctionResult.pay samples produce the JSON at line 2057. Python samples pass pyflakes, and every SDK method and parameter used exists with the shown signature. Links and anchors resolve.

Inline: two behavior mismatches (Relay stop semantics; first-run troubleshooting behind ngrok), two convention items, and one PCI question.

Minor, no inline comment: the TypeScript — REST client first-run sample fails tsc --strict on swml, (TS2741: the SDK types SwmlBuilder.build() as Record<string, unknown>, but calling.dial expects SWMLObject). It runs fine as .mjs, as its header says, so this is an SDK typing gap and not a doc bug. It may be worth noting for readers who save it as .ts.

@Devon-White
Devon-White self-requested a review November 9, 2026 14:50
- Describe Relay stop semantics accurately: no closing prompt after a
  stop, and a stop during the last card detail still sends the card to
  the connector. Update the matching sample comments.
- Lead the first-run troubleshooting with internal-error, which a
  stopped tunnel or connector produces, and narrow
  payment-connector-error to no response at all.
- Switch the TypeScript connector to validateWebhookSignature from
  @signalwire/sdk and move its highlight range.
- Keep prose and tables generic to the Server SDKs: drop the
  per-language status webhook row and per-language option names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Manny-r31
Manny-r31 requested a review from hey-august November 9, 2026 16:09
Manny-r31 and others added 2 commits November 9, 2026 12:12
SignalWire pauses recordings on the paying call while it collects card
details. Taps, streams, live transcription, and live translation keep
receiving audio, so the PCI section now tells readers to stop them
before pay and to pause recordings on any other call themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Manny-r31

Copy link
Copy Markdown
Collaborator Author

@Devon-White I've made the changes you requested. Could you take another look and re-review or approve when you have a moment? Thanks!

@Devon-White Devon-White left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Manny. All five threads from my last review are addressed, and I checked the new PCI paragraph against platform behavior: recordings on the paying call are paused during collection, and taps, streams, live transcription, and live translation keep running, as the page now says. Two small follow-ups from the fixes below, then this is good to go.

Manny-r31 and others added 3 commits November 16, 2026 09:05
Co-authored-by: Devon <86693904+Devon-White@users.noreply.github.com>
Co-authored-by: Devon <86693904+Devon-White@users.noreply.github.com>
Devon-White
Devon-White previously approved these changes Nov 16, 2026

@Devon-White Devon-White left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Manny. Both follow-ups are in: the TypeScript highlight now covers the signature check ({18-22}), and the recording card matches the PCI section. Approving. August's earlier change request still needs August to re-review before this can merge.

@hey-august hey-august left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eight of my nine points are fixed, one is half fixed, and three new problems need one more round. Re-reviewed at 966bd17, with every sample run again on the current releases (Python 3.12.0, TypeScript 3.9.0) and every platform claim re-read against today's source. The guide is close: the prompt ranking, the result values, the signing scheme, the PCI claims, the stop semantics and both connector stubs all check out, and the split-character and forged-signature cases behave as the page says. The three blockers below are all small to fix, but two of them break the guide's own first run.

B = must fix, N = your call. Evidence is collapsed at the end.

B1. The signed URL is the normalised URL, not the string you passed — take-payments.mdx:115, :245-253, :270, :319, :378-381. The page says the signature covers the URL "exactly as you pass it" and tells readers to use the ngrok Forwarding URL "character for character". Before signing, the platform normalises the URL: a URL with no path gets a trailing /, the scheme is lowercased, and ./.. segments are resolved. The SWML pay reference on this same branch already says so (pay/index.mdx:530). ngrok prints a URL with no path, so a reader who follows the first run gets a 403 from the sample connector and internal-error on the call. Reproduced with both SDK helpers: they reject https://abc-123.ngrok-free.app against a signature over the same URL with a trailing /, and accept it with the slash. Fix: tell readers to give the connector a path (…/connector) or add the trailing /, and say the platform normalises the URL, pointing at the reference paragraph. The credential-stripping part of my earlier point is fixed everywhere.

B2. The page's agent result tells the agent a blank status — take-payments.mdx:2053-2085. The JSON has set before pay, and the sentence above it says the result "sets ai_response … then runs pay". set resolves ${pay_result} when it runs, and an unset variable resolves to nothing, so in that order ai_response becomes "The payment status is , do not mention…" before any card is collected; on a second payment in the same call it carries the previous result. The Python SDK emits pay then set, which works, so the Python tab doesn't produce the JSON shown. The TypeScript SDK emits set then pay, which the JSON matches, so the TypeScript tab produces a result that never reports the status. Fix: show the pay-then-set JSON and reword the sentence; for TypeScript, until the SDK is fixed, build the two-verb document yourself and pass it to executeSwml, or say the order is wrong on the current release. SDK issue: signalwire/signalwire-typescript#248. Verified from source; no live call.

B3. The TypeScript REST sample fails tsc --strict on 3.9.0 — take-payments.mdx:459 (swml, in the dial call; TS2741, the builder's build() type isn't the type dial expects). The PR body says all 12 TypeScript samples pass; it's 11. It runs as .mjs and sends the same body as Python and cURL, so JSON.parse(builder.render()), the form the other guides use since #908, is the one-line fix.

N1. validation-error can't happen on SWML or Relay — take-payments.mdx:1689. The row is accurate for the engine, but both surfaces reject an unsupported payment_method or bank_account_type before collection starts, so a reader of this guide never sees the value. Either say so or leave it.

N2. The sample connector body includes postal_code — :172-189, introduced as the fare from Payment options, where postal_code is "false" (:1223-1250). With it off, the key is omitted. Drop it from the body or say the postal code was collected.

N3. A declined card still hears "Payment completed" when the connector declines with an HTTP 200, which is what the page tells readers to do. Only the PR body mentions it. One sentence (override the payment-completed prompt, or expect the stock prompt before your own) would save readers a surprise. Filed for the platform as signalwire/cloud-product#22548.

N4. record-calls.mdx:692: the backlink is two sentences and names take_payment and takePayment outside code. Everything else in the guide is clean on per-language names.

N5. Out-of-range max_attempts and timeout fall back to the defaults silently — :1187-1188 give the limits without saying what happens outside them. Optional.

N6. PR body is stale: "Merge after #833" (merged Oct 28), the 3.4.1 / 2.0.5 pins, "the TypeScript connector checks with node:crypto" (it uses the SDK helper now), "add_verb/addVerb" for the security-code sample (it edits the built verb), and the two SWML-reference errors listed as unfixed (security_code is a string and prompts[].attempt is singular on this branch).

Outside this PR: the Relay call.pay reference pages still show await action.wait(), which never returns on current SDKs (#957). The Content redaction guide's pay example has the same set-before-pay order and boolean security_code / postal_code (#956).

What was checked
  • Head 966bd17, 12 files, 46 fenced blocks on the guide (the other 11 files add none): 12 Python (py_compile, pyflakes, executed on 3.12.0), 12 TypeScript (tsc --strict on 3.9.0, node --check as .mjs for the 11 that claim it, executed), 15 JSON and 4 YAML parsed, 2 bash bash -n; the four builder families render identical documents. Both connector stubs ran as servers against signed requests: a charge, a zero-amount token, a forged signature (403), a non-ASCII body, and a body split mid-character on the socket (200 with setEncoding, 403 without it). Relay samples ran against a fake Relay server emitting the progress and final events; REST samples against a stubbed HTTP layer. The Python connector ran against a stand-in for Flask, which isn't installed here.
  • Platform claims re-read at today's checkout: connector body and omitted keys, signing (headers, digests, credential stripping, normalisation), the success rule, every result value and its trigger, the progress and final event fields, defaults and limits, prompt ranking and ties, masking and keypad handling, https enforcement, the PCI claims (recordings on the paying call pause; taps, streams, live transcription and translation keep running), Relay stop semantics (no canceled prompt; a stop during the last entry doesn't cancel). One backend change since the earlier review (connector credentials kept out of logs, variables expanded in the URL) changes nothing on the page.
  • Nine items from my earlier review: 1, 3, 4, 5, 6, 7, 8, 9 fixed; 2 partly (B1). For 7, neither SDK rejects an http:// URL before the call, so the troubleshooting path stays.
  • Links and anchors on the 12 files resolve; the page is in the folder-driven voice nav; the llms.txt bullet points at the slug. yarn fern-md-check passes. #833 is merged and the two reference-page hunks apply cleanly.
  • Not verified: the mermaid and SVG renders (no renderer here), Dashboard labels and trial-mode limits, whether a call stays up after the Relay client disconnects, live behaviour of anything.

@Devon-White Devon-White left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 4a85a79. The guide is unchanged since August's review on Nov 18; the only new commit merges main. I checked August's round-2 findings against the platform and the latest Server SDKs (signalwire-sdk 3.12.0, @signalwire/sdk 3.9.0). All three blockers hold, so this needs one more round before merge. Details and suggested text are inline.

Blocking

  • B1, signed URL normalization (:115, :249, :378-381). A bare ngrok URL fails the signature check on the guide's own first run. Append / instead of adding a path: the Flask connector only serves /.
  • B2, set before pay (:2053-2085). The agent is told a blank status. Python 3.12.0 already emits the right order; TypeScript 3.9.0 doesn't (signalwire/signalwire-typescript#248). The inline comment has a TypeScript workaround that compiles.
  • B3, TypeScript REST sample (:455-460). The only one of the 12 TypeScript blocks that fails tsc --strict. One-line fix.

Should fix

  • validation-error row (:1689). It's stronger than August's N1: the case it describes ends as failed in SWML and a rejected request in Relay. Move it to the failed row.
  • Sample body includes postal_code (:182), though the options example turns it off.
  • A 200 decline still plays "payment completed" (:211).

Agree with August, no inline comment

  • N4: the record-calls.mdx:692 backlink names take_payment/takePayment outside code; shorten it to one language-neutral sentence.
  • N6: the PR body is stale. It still has "Merge after #833", the 3.4.1/2.0.5 pins, "node:crypto" for the TypeScript connector, add_verb/addVerb, and two reference errors already fixed on this branch.
  • Outside this PR: #956 (the redaction guide's pay example) and #957 (Relay call.pay reference action.wait()).

Checked and fine: the pay reference's normalization paragraph (pay/index.mdx:530) matches the platform. The other 11 TypeScript blocks pass tsc --strict. The pay_result usage in every SWML and Relay sample comes after pay. Not verified: live calls, and the deployed platform commit. I read the current source, not production.

Comment on lines +378 to +381
ngrok prints an `https://` **Forwarding** URL. That URL is your `<YOUR_PAYMENT_CONNECTOR_URL>`.
Use the same string, character for character, in the connector and in the call, because the
signature covers it. Keep the tunnel running while you test; a new tunnel usually means a new
hostname.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (August's B1, confirmed against the platform): a bare ngrok URL fails the signature check on the first run. Before signing, SignalWire normalizes the connector URL. A URL with no path is signed with a trailing /, the scheme is lowercased, and ./.. segments are resolved. User credentials are removed, the host's case is kept, and so is an explicit port. ngrok prints https://<id>.ngrok-free.app with no path, so a reader who copies it "character for character" signs .../ on SignalWire's side and checks against no slash on theirs. The connector returns 403 and the call ends in internal-error.

Adding a path such as /connector won't work here, because the Flask sample only serves @app.post("/") (line 277), so that would 404. Appending / works with both samples:

Suggested change
ngrok prints an `https://` **Forwarding** URL. That URL is your `<YOUR_PAYMENT_CONNECTOR_URL>`.
Use the same string, character for character, in the connector and in the call, because the
signature covers it. Keep the tunnel running while you test; a new tunnel usually means a new
hostname.
ngrok prints an `https://` **Forwarding** URL. Add a trailing `/` to it, as in
`https://<id>.ngrok-free.app/`, and use that as your `<YOUR_PAYMENT_CONNECTOR_URL>` in the connector
and in the call. The signature covers the URL, and SignalWire signs a URL with no path as if it ended
in `/`. Keep the tunnel running while you test; a new tunnel usually means a new hostname.

`X-SignalWire-Signature` header holds the lowercase hex HMAC-SHA1 of the connector URL you passed in
`payment_connector_url`, followed by the raw request body. If that URL carries credentials, as
`https://user:password@pay.example.com/` does, SignalWire removes them before signing and sends them
as HTTP Basic authentication instead, so the signed URL is `https://pay.example.com/`. An

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same normalization, stated once where the signature is defined. The pay reference on this branch already says this (pay/index.mdx:530), so the guide shouldn't say "exactly as you pass it". Suggest adding one sentence after the credentials sentence:

Suggested change
as HTTP Basic authentication instead, so the signed URL is `https://pay.example.com/`. An
as HTTP Basic authentication instead, so the signed URL is `https://pay.example.com/`. SignalWire
also normalizes the URL before signing: a URL without a path gets a trailing `/`, the scheme is
lowercased, and `.` and `..` path segments are resolved. An

| `<YOUR_API_TOKEN>` | Your API token with the Voice permission, used only in server code |
| `<YOUR_CALLER_ID>` | Your SignalWire phone number, or a [verified caller ID][caller-id], in E.164 format |
| `<YOUR_DESTINATION>` | The phone you'll answer, in E.164 format |
| `<YOUR_PAYMENT_CONNECTOR_URL>` | The public `https://` URL of your payment connector, exactly as you pass it in `payment_connector_url`. SignalWire signs requests against this string, minus any `user:password@` credentials in it. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same point for the placeholder row. "Exactly as you pass it" is what breaks the ngrok first run. Suggest:

Suggested change
| `<YOUR_PAYMENT_CONNECTOR_URL>` | The public `https://` URL of your payment connector, exactly as you pass it in `payment_connector_url`. SignalWire signs requests against this string, minus any `user:password@` credentials in it. |
| `<YOUR_PAYMENT_CONNECTOR_URL>` | The public `https://` URL of your payment connector, ending in `/` if it has no path. Use the same URL in `payment_connector_url` and in your connector, because SignalWire signs requests against it, minus any `user:password@` credentials. |

Comment on lines +455 to +460
.say("The payment result is ${pay_result}.")
.build();

const call = await client.calling.dial("<YOUR_CALLER_ID>", "<YOUR_DESTINATION>", {
swml,
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (August's B3, confirmed): this is the only TypeScript block of the 12 that fails tsc --strict on @signalwire/sdk 3.9.0: TS2741: Property 'sections' is missing in type 'Record<string, unknown>' but required in type 'SWMLObject'. build() is typed as a plain record, but dial's swml expects a document type. The parse form is what make-and-receive-calls and the other guides use since #908, and it compiles cleanly:

Suggested change
.say("The payment result is ${pay_result}.")
.build();
const call = await client.calling.dial("<YOUR_CALLER_ID>", "<YOUR_DESTINATION>", {
swml,
});
.say("The payment result is ${pay_result}.")
.render(); // JSON text; parse it to pass the document object to dial()
const call = await client.calling.dial("<YOUR_CALLER_ID>", "<YOUR_DESTINATION>", {
swml: JSON.parse(swml),
});

Please also update the PR body, which says all 12 pass.

Comment on lines +2053 to +2055
The tool returns this result. Its SWML sets `ai_response`, which tells the agent the payment's
`pay_result` once collection ends, then runs `pay` with your options and the SDK's defaults filled
in. To change what the agent is told, pass your own AI response to `pay`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (August's B2, confirmed): set runs before pay, so the agent hears a blank status. SWML resolves ${pay_result} when set runs, not later. Here ai_response becomes "The payment status is , ..." before any card is collected, or carries the previous result on a second payment in the same call.

Fixes:

  1. Put pay first and set second in the JSON, and reword this sentence:
Suggested change
The tool returns this result. Its SWML sets `ai_response`, which tells the agent the payment's
`pay_result` once collection ends, then runs `pay` with your options and the SDK's defaults filled
in. To change what the agent is told, pass your own AI response to `pay`.
The tool returns this result. Its SWML runs `pay` with your options and the SDK's defaults filled
in, then sets `ai_response`, which tells the agent the payment's `pay_result`. To change what the
agent is told, pass your own AI response to `pay`.
  1. For the TypeScript tab, until clean up #248 ships, build the two steps yourself. I checked that this passes tsc --strict and emits ["pay","set"] on 3.9.0:
handler: () =>
  new FunctionResult("Collecting the payment now.").executeSwml({
    version: "1.0.0",
    sections: {
      main: [
        { pay: { payment_connector_url: "<YOUR_PAYMENT_CONNECTOR_URL>", charge_amount: "24.50", description: "Bayview Taxi fare" } },
        { set: { ai_response: "The payment status is ${pay_result}." } },
      ],
    },
  }),

That drops the SDK-filled defaults from the TypeScript output, so the JSON can show only the Python render. The other option is to keep .pay() and wait for the SDK fix before merging.

| `too-many-failed-attempts` | An entry failed SignalWire's check, or timed out, on every one of the caller's `max_attempts` tries |
| `payment-connector-error` | SignalWire couldn't reach your payment connector, or got no response from it |
| `internal-error` | The payment didn't complete. When your connector declines the card or replies without a valid ID, `payment_error` is `card-declined`. |
| `validation-error` | The payment stopped before collection because `payment_method` or `bank_account_type` held a value SignalWire doesn't support |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More than "can't happen": this row sends readers to the wrong value. An unsupported payment_method or bank_account_type never reaches collection on either surface:

  • SWML: a literal value fails document validation. A ${...} value is re-checked when pay runs and ends as failed, the row below.
  • Relay: call.pay is rejected with a 400, which the SDKs raise as an error.

So a reader branching on validation-error for this case never matches. The value exists only as a temporary state between retries, and every exit replaces it. Suggest dropping the row and adding the case to failed, for example "the pay method couldn't start the payment, for example because payment_method holds an unsupported value." Then the Relay troubleshooting text can mention the rejected request.

"method": "credit-card",
"cardnumber": "4111111111111111",
"cvv": "123",
"postal_code": "94107",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor (August's N2, confirmed): this body is introduced as the fare from Payment options, and there postal_code is "false" (line 1238). With postal code collection off, SignalWire leaves the postal_code key out of the connector body. Drop this line, or introduce the body as one where the caller entered a postal code. If you drop it, the "Only included when collected" wording in the field table at line 201 is worth adding too.


Reply with HTTP `200` and a JSON body. For a charge, return the processor's charge ID in
`charge_id`. For a zero amount, return the saved card's token in `token_id`. To decline, return
`error_code` and `error_message` with no ID.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth one sentence (August's N3, confirmed): the prompt the caller hears depends only on the HTTP status. Any 200, including a decline sent the way this paragraph says to, plays the stock "payment completed" prompt. Only after that is the result set to internal-error with card-declined. A reader testing a decline will hear "completed" and assume something is wrong. Suggest:

Suggested change
`error_code` and `error_message` with no ID.
`error_code` and `error_message` with no ID. The caller still hears SignalWire's payment-completed
prompt for any `200` reply, so override the `payment-completed` prompt or follow it with your own
message when the result isn't `success`.

Comment on lines +1187 to +1188
| `max_attempts` | `1` | How many tries the caller gets at each entry, up to `3`. An entry that fails the check or times out uses a try. |
| `timeout` | `5` | How many seconds SignalWire waits for the caller's next key press before it checks the entry. The minimum is `3`. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional (August's N5, partly confirmed): values outside these limits aren't rejected. Within validation, max_attempts of 0 or more than 3 becomes 1, and a timeout under 3 becomes 5. Negative values are rejected. One clause per row ("Values above 3 fall back to 1." / "Lower values fall back to 5.") saves readers a surprise when max_attempts: 5 quietly gives one try.

@Devon-White
Devon-White self-requested a review November 18, 2026 18:54
Sign the connector URL with a trailing slash, show pay before set in the agent result, fix the TypeScript REST sample under tsc --strict, move the unsupported payment_method case to the failed result, drop postal_code from the sample connector body, note the payment-completed prompt on a 200 decline, state the max_attempts and timeout fallbacks, and make the Record calls backlink language-neutral.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Manny-r31

Copy link
Copy Markdown
Collaborator Author

@Devon-White the round-3 changes are in 03ad263.

  • B1, signed URL. I took your three suggestions as written. The first-run troubleshooting bullet now also tells readers to check that the connector URL ends in /.
  • B2, set before pay. The JSON shows pay then set, and the sentence above it uses your wording. I kept .pay() in the TypeScript tab and skipped the executeSwml workaround, because @signalwire/sdk 3.10.3 now emits pay then set. Its output matches the JSON on the page, and signalwire-sdk 3.12.2 renders the same document.
  • B3, TypeScript REST sample. It now uses .render() and JSON.parse(swml), and passes tsc --strict on 3.10.3.
  • validation-error. I dropped the row and moved the unsupported payment_method case to failed. The Relay result section now says a call.pay request SignalWire can't start fails with an error and sends no final event.
  • Sample connector body. I removed postal_code, and the field table says it's left out when postal_code on pay is "false".
  • Decline on a 200. Added your sentence about the payment-completed prompt.
  • Limits. Added the fallback clauses to the max_attempts and timeout rows.
  • N4. The record-calls backlink no longer names take_payment or takePayment. It is still two sentences.

Two things are unchanged. The PR description still needs its update. The SWML pay reference on this branch still defines validation-error as the unsupported payment_method case, which the guide now gives to failed. Do you want that line changed in this PR?

yarn fern-md-check passes. I re-ran only the samples I changed.

@Devon-White Devon-White left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 03ad263. All nine of my round-3 points are in, and I checked each against current platform and SDK source:

  • Signed URL: the normalization sentence, the trailing-/ guidance (placeholder table, ngrok step, troubleshooting) and the Basic-auth note all match how SignalWire signs the connector URL.
  • pay then set: @signalwire/sdk 3.10.3 FunctionResult.pay() now emits pay then set, the same as signalwire-sdk, so the JSON on the page matches both SDKs and the executeSwml workaround isn't needed. Agreed.
  • TypeScript REST sample: .render() returns the JSON string and JSON.parse(swml) is what dial() needs. Good.
  • validation-error → failed: right. An unsupported payment_method or bank_account_type is rejected before pay starts. In SWML a literal value fails document validation, and a value from a variable makes pay fail, so pay_result is failed. On Relay, call.pay returns an error with no calling.call.pay event. Nothing in practice reaches validation-error.
  • Connector body, 200 decline, limits: all correct. One small precision note is inline on the max_attempts row.

Your question about the SWML pay reference: yes, change it in this PR. Otherwise the reference and the guide contradict each other on the same result value. Suggestion inline.

Still open before merge:

  1. The pay reference line (inline).
  2. The PR description update.
  3. August's re-review, since the changes-requested review is his.

Not blocking: the strings "5", "1" and "0" for timeout, max_attempts and min_postal_code_length in the AI tool JSON are what both SDKs emit, and the platform reads them as strings. The SWML schema in the reference still types them as integer. That's tracked separately in #921, so leave it out of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Take payments on a call

3 participants