Skip to content

Cyan.mount

widget.js adds one global, Cyan, with one function: mount. For a walkthrough, start with Accept a payment in your chat.

<script src="https://pay.cyan.cash/v1/widget.js"></script>

Puts a checkout in an element and returns a handle to it.

const checkout = Cyan.mount("#payment", {
url: link.url,
appearance: { theme: "auto", accent: "#0e7490", corners: "rounded" },
onReady() {},
onPaid({ link }) {},
onProcessing({ link }) {},
onError({ message }) {},
});
Parameter Type Description
target string or Element Where the checkout goes: an element, or a CSS selector for one.
options.url string Required. A payment link’s url, as the API returned it.
options.appearance object Optional. How the checkout looks. See below.
options.onReady function Optional. Called when the payment form is ready.
options.onPaid function Optional. Called with { link } when the payment succeeds.
options.onProcessing function Optional. Called with { link } when the payment is accepted and the bank is confirming it.
options.onError function Optional. Called with { message } when a payment attempt fails.

In onPaid and onProcessing, link is the payment link’s ID, such as "pl_019d0a1b2c3d4e5f60718293a4b5c6d7".

Option Values Default
theme "auto", "light", "dark" "auto", which follows your customer’s device
accent A six-digit hex color, such as "#0e7490" A neutral that suits the theme
corners "rounded", "square" "rounded"

See Customize the checkout for what each option changes.

A handle with two methods:

Method Description
update({ appearance }) Restyles the checkout without reloading the payment form. It sets the whole appearance, so pass every option you want to keep.
unmount() Removes the checkout from the page.

Cyan.mount throws if it can’t start:

Message Cause
Cyan.mount: target element not found target didn’t match an element.
Cyan.mount: url must be a payment link's url from this Cyan server url is missing, or isn’t a payment link’s url.
Callback Runs
onReady Once, when the payment form is ready to use.
onPaid When a payment succeeds. Also when you mount a link that is already paid.
onProcessing When a payment is accepted and still being confirmed. Also when you mount a link in that state.
onError Each time an attempt fails. Your customer can try again in the same form.

Because onPaid can run more than once for the same link, make your handler safe to repeat.

The callbacks run in your customer’s browser. Use them to update your chat, and confirm the payment on your server.

The checkout always shows the right state for the payment link:

Link status The checkout shows
pending Your name and logo, the amount, what it’s for, and the payment form.
processing “Payment processing”, while the bank confirms.
paid “Payment complete”.
canceled “Link expired”.

While it loads, the checkout shows a placeholder in its own shape, then sizes itself to its content. Give the element you mount it in a width, and leave the height alone.

The checkout runs in a frame on Cyan’s domain. Card details are entered there and never reach your page, your scripts or your servers.