--- url: https://docs.youcan.shop/youcan-pay/yp-js/getting-started.md --- # yp.js: Getting Started `yp.js` is a self-contained JavaScript library that renders the YouCan Pay payment form in the browser. It loads from a CDN and exposes a global `yp` function. It ships as a UMD bundle, so it works with a plain ` ``` ## Quick Start You need a payment token from your server first. See the [Payment Flow](/youcan-pay/payment-flow). ```html
``` ## API ### `yp(publicKey, options?)` Creates a client. Returns an object with an `elements` method. | Parameter | Type | Description | | --- | --- | --- | | `publicKey` | `string`, required | Your account public key. Prefixed with `pub_`. | | `options.locale` | `string`, optional | Form language: `en`, `fr`, or `ar`. Defaults to `en`. `ar` renders right-to-left. | > **Note:** Sandbox mode is detected from the token. You do not set it. See [Sandbox & Testing](/youcan-pay/yp-js/sandbox). ### `client.elements(options)` Creates a payment element. Returns a `PaymentElement`. | Parameter | Type | Description | | --- | --- | --- | | `token` | `string`, required | The payment token from your server. | | `container` | `string` | `HTMLElement`, required | A CSS selector or element that holds the form. | | `gateways` | `string[]`, optional | Limits and orders the payment methods. See [Gateways](#gateways). Omit to show every method the account allows. | | `appearance` | `object`, optional | Theming for the form. See [Appearance](/youcan-pay/yp-js/appearance). | ### `element.mount()` Renders the form inside the container. Returns a `Promise` that resolves when the form is ready. It rejects if the account is inactive, the host is not allowed, or no payment method is available. ### `element.confirm()` Confirms the payment for the selected method. Returns a `Promise