Confirm payments
Before you ship an order, book an appointment or unlock a feature, confirm the payment on your server.
The checkout tells your customer the payment went through, and onPaid tells your chat page. Both happen in the browser, where a tab can close early and a message can be faked. Your server is where the decision belongs.
Check the payment link
Section titled “Check the payment link”Read the link from your server. Its status is always current.
const response = await fetch(`https://api.cyan.cash/v1/payment-links/${linkId}`, { headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` },});const link = await response.json();const paid = link.status === "paid";{ "id": "pl_019d0a1b2c3d4e5f60718293a4b5c6d7", "amount": 3600, "currency": "USD", "status": "paid"}The response is shortened here. See the payment link for every field.
Check the link at these moments:
- When the widget calls
onPaid. Your page sends the link’s ID to your server, and your server makes sure the status ispaid. - While the checkout is on screen. Check every few seconds until the link is
paid. This also catches a payment made in another tab. - When your agent is asked. “Did my payment go through?” is one call away.
| Status | Meaning | What to do |
|---|---|---|
pending |
Not paid yet. | Wait. Your customer can still pay, or try another card. |
processing |
Accepted, and the bank is confirming. | Wait for paid. |
paid |
The payment succeeded. | Fulfill the order. |
canceled |
The link was canceled. | Create a new link if your customer still wants to buy. |
Catch payments after the tab closes
Section titled “Catch payments after the tab closes”Sometimes a customer pays and closes the tab before your page can tell your server. Cyan doesn’t call your server when a payment completes, so keep checking open links from your server:
// Run every minute, for example from a scheduled job.for (const order of await ordersAwaitingPayment()) { const response = await fetch(`https://api.cyan.cash/v1/payment-links/${order.linkId}`, { headers: { Authorization: `Bearer ${process.env.CYAN_API_KEY}` }, }); const link = await response.json(); if (link.status === "paid") await fulfillOrder(order); if (link.status === "canceled") await closeOrder(order);}Stop checking a link once it’s paid or canceled: neither changes again. To stop waiting on a link nobody paid, cancel it.
Make fulfillment safe to run twice. Your page and your scheduled check can both report the same payment.
Refunds and disputes
Section titled “Refunds and disputes”Refund a payment in your Stripe Dashboard, the same way you refund any other. Disputes arrive there too.
The Cyan app keeps track for you: Transactions shows which payments were refunded, in full or in part. In the API, a refunded link keeps the status paid.