- Create a payment link for a client
🔐 Required role:
PAYLNK_CorAPI_ADMIN📖 Data dictionary: Payment
Create a single-use quick payment link that lets a client pay in the Aiwyn payment portal
The client is resolved by clientRef, the same identifier the client carries in the firm's practice management system. Exactly one active client must match.
The link is locked to the arguments given: the payer sees the selected invoices, the amount and the note prefilled and cannot change them, and the link accepts one payment. Use it to gate a deliverable behind a specific invoice. At least one of invoiceIds, invoiceNumbers, amount, note, returnUrl, returnLabel, returnAutomatically, metadata or expiresInDays must be present; a body carrying only clientRef is rejected with 400, because this route never issues a link to the client's full account. Invoices must belong to the client and must be unpaid; use GET /api/v1/invoices/unpaid to list them. The link id (the qpLink query parameter of the returned URL) is shown only in this response and is never stored: the Payment webhook events the payment raises carry its lowercase hex SHA-256 as metadata.paymentLinkPlIdSha256 and the link's id as metadata.paymentLinkId, so a payment can be matched to the link that produced it by hashing the qpLink value. The events no longer carry metadata.paymentLinkPlId.
metadata attaches up to 20 key-value pairs of your own to the link, such as the id of the return or the order the payment is for. Keys are 1 to 40 letters, digits, underscores or hyphens; values are strings of at most 500 printable characters. The payer never sees them. They are echoed back unchanged as metadata.paymentLinkMetadata on the Payment webhook events the link's payment raises, so you can match the payment to your records without storing the link id. Only your own subscriptions (those of the API user that created the link) receive them; another API user of the firm with a firm-wide Payment subscription gets the event without them. Use identifiers, not taxpayer names or other personal data.
A link stays payable for 14 days after it is created. expiresInDays sets a different lifetime: one of 7, 14, 30, 60 or 90. Any other value is rejected with 400 and extensions.details.reason INVALID_EXPIRY, and no link is created. Create the link with a lifetime that covers the time the payer needs; once it expires, create a new one.
A quick payment link can carry a returnUrl. After a successful payment the portal sends the payer back to it (the URL is disclosed only on the charge result, never when the link is opened). The URL must be https and its host must be on the firm's payment_return_url_allowed_hosts configuration; a firm without that configuration rejects any returnUrl with 400. A link that carries a returnUrl must also name invoices (invoiceIds or invoiceNumbers) or an amount: the portal releases the URL only once the link is paid in full, and a link with neither has no full amount to check, so it is rejected with 400 and extensions.details.reason RETURN_URL_REQUIRES_OBLIGATION. returnLabel names that destination on the return button. returnAutomatically: true asks the portal to return on its own after the confirmation, after a short countdown, instead of waiting for the payer to press the button: it navigates to returnUrl when the link has one, and otherwise closes the payment tab, which it can do only when your system opened that tab by script.
The body is decoded strictly: a key that is not one of clientRef, invoiceIds, invoiceNumbers, amount, note, returnUrl, returnLabel, returnAutomatically, metadata, expiresInDays is rejected with 400 instead of being ignored.
Client reference of the client the link is for. Exactly one active client must match.
Unpaid invoices of the client to lock the link to, by invoice id. At most 100 invoices per link, counted together with invoiceNumbers.
[ 125890 ]
Unpaid invoices of the client to lock the link to, by invoice number. Resolved to the same invoices as invoiceIds; an invoice given both ways is counted once.
[ "INV-2026-4850" ]
Amount the payer is asked for, decimal with at most two decimal places. Accepted as a JSON number as well. Omit to let the invoices' outstanding balance drive the amount.
Free text shown to the payer. Treated as sensitive; it is never written to logs.
Where the portal sends the payer once the link is paid in full. https only, host must be allow-listed for the firm. Requires invoiceIds, invoiceNumbers or amount.
Name of the destination shown on the return control, plain text. Requires returnUrl.
Return on its own after the payment confirmation, after a short countdown, instead of waiting for the payer to press the return button. With returnUrl the portal navigates there; without one it closes the payment tab, which only works when your system opened the tab by script. Makes the link a quick payment link even on its own.
Your own key-value pairs, echoed back as metadata.paymentLinkMetadata on the Payment webhook events. At most 20 keys; each key 1 to 40 letters, digits, underscores or hyphens; each value at most 500 printable characters. Never shown to the payer, and delivered only to the subscriptions of the API user that created the link; do not put personal data in it. Makes the link a quick payment link even on its own.
{ "returnId": "R-42", "taxYear": "2025" }
- Sandbox (requires Cloudflare Access headers)https://api.sandbox.aiwyn.app/api/v1/clients/v1/link/payment
- Staging (requires Cloudflare Access headers)https://api.staging.aiwyn.app/api/v1/clients/v1/link/payment
- Production (your live firm data; no Cloudflare Access headers)https://api.aiwyn.ai/api/v1/clients/v1/link/payment
curl -i -X POST \
https://api.sandbox.aiwyn.app/api/v1/clients/v1/link/payment \
-H 'Authorization: Bearer <YOUR_JWT_HERE>' \
-H 'CF-Access-Client-Id: YOUR_API_KEY_HERE' \
-H 'CF-Access-Client-Secret: YOUR_API_KEY_HERE' \
-H 'Content-Type: application/json' \
-d '{
"clientRef": "ACME-001",
"invoiceIds": [
125890
],
"note": "2025 individual tax return",
"returnUrl": "https://app.safesend.example/returns/42",
"returnLabel": "SafeSend",
"returnAutomatically": true,
"metadata": {
"returnId": "R-42"
}
}'{ "response": "https://acme.aiwyn.app/client-portal/payments?qpLink=qpl_9f1c2a7b3d4e5f60718293a4b5c6d7e8" }