Send a payment link
Every payment link comes with a checkout page hosted by Cyan. Send your customer the link, and they pay in their browser. There is nothing to build.
Use it when the conversation happens somewhere you can’t show a checkout: email, SMS, WhatsApp, or a follow-up after a voice call.
Create and send the link
Section titled “Create and send the link”Create a payment link on your server:
const response = await fetch("https://api.cyan.cash/v1/payment-links", { method: "POST", headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}`, "Idempotency-Key": order.id, "Content-Type": "application/json", }, body: JSON.stringify({ amount: 12000, description: "Deposit for March 14", customer_name: "Ada Lovelace", }),});const link = await response.json();amount is in cents: 12000 is $120. The Idempotency-Key makes a retry safe: send the same request again and you get the same link, never a second one.
The response has a url. That’s the checkout page. Have your agent send it to the customer:
{ "id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7", "url": "https://pay.cyan.cash/pl_019d0a1b2c3d4e5f60718293a4b5c6d7"}The response is shortened here. See the payment link for every field.
What your customer sees
Section titled “What your customer sees”A clean checkout page with:
- The amount and your description of what it’s for.
- “Payment request for Ada Lovelace”, when you pass a
customer_name. - A card form, and Apple Pay when their device has it.
When the payment goes through, the page confirms it and your customer can close the tab.
If a card is declined, the page says why and they can try another card. If the link was already paid, the page says so, which means a link can never be paid twice.
Know when it’s paid
Section titled “Know when it’s paid”The page tells your customer the payment went through. To tell your own system, read the link’s status from your server. See Confirm payments.
Cancel a link
Section titled “Cancel a link”A link stays open until it’s paid. To withdraw one, cancel it:
await fetch(`https://api.cyan.cash/v1/payment-links/${link.id}/cancel`, { method: "POST", headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` },});Your customer then sees “Link expired”. A link that is already paid can’t be canceled: refund it in your Stripe Dashboard instead.
Prefer to keep customers in your product?
Section titled “Prefer to keep customers in your product?”Show the same checkout inside your chat instead. See Accept a payment in your chat.