Web components
@biaspay/elements registers light-DOM custom elements for an embedded Bias checkout. Use it with plain HTML or any framework that supports custom elements.
Install
Importing the package in a browser registers every bias-* element. Svelte is bundled as an implementation detail and is not a peer dependency.
The entry point is safe to import without a DOM. Registration is skipped until the package runs in a browser. defineBiasElements() is also exported for explicit registration and is safe to call more than once for the same Elements version.
Provider configuration
<bias-provider> owns the session, field state, and payment lifecycle for its descendants.
| Property | Attribute | Type | Required |
|---|---|---|---|
clientSecret | client-secret | string | Yes |
initialCheckoutSession | — | CheckoutSession | No |
appearance | — | Appearance | No |
onComplete | — | () => void | No |
Use properties for objects and functions. Assign them before inserting a provider when they must be present on its first connection:
initialCheckoutSession is a one-time hydration seed. Its client_secret must match clientSecret. Elements shows a matching seed after activation and refreshes it from the API; later seed changes for the same secret are ignored.
Changing clientSecret starts a new session and resets session-owned state.
Child elements
| Element | Properties | Defaults |
|---|---|---|
<bias-express-checkout-element> | disabled?: boolean, showSeparator?: boolean, appearance?: Appearance | false, false |
<bias-payment-element> | paymentMethodLayout?: "tabs" | "radio", appearance?: Appearance | "tabs" |
<bias-card-element> | appearance?: Appearance | — |
<bias-us-bank-account-element> | appearance?: Appearance | — |
<bias-contact-element> | appearance?: Appearance | — |
<bias-address-element> | scope?: "billing" | "shipping", collectPhone?: boolean, appearance?: Appearance | "billing", false |
<bias-discount-code-element> | appearance?: Appearance, onDiscountCodeChange?: (session) => void | Promise<void> | — |
<bias-submit-button> | disabled?: boolean, label?: string | false, session label |
The string and boolean properties also have kebab-case attributes: show-separator, payment-method-layout, scope, collect-phone, disabled, and label. Assign appearance as a property.
Mount <bias-express-checkout-element> before contact and shipping fields for Apple Pay. It is separate from the ordinary card/bank form. Use exactly one of <bias-payment-element>, <bias-card-element>, or <bias-us-bank-account-element> under each provider. See components and appearance for composition and theming rules.
The discount-code element displays its input only when allow_discount_codes is enabled and keeps already-entered codes available for removal. onDiscountCodeChange is awaited after Elements has accepted the API’s updated session, which lets a host synchronize an expanded order summary without allowing payment submission against stale UI.
State and methods
The provider exposes read-only checkout state:
| Property | Type |
|---|---|
sessionState | SessionState |
discountCodeState | DiscountCodeState |
paymentMethod | "card" | "us_bank_account" | undefined |
status | "idle" | "submitting" | "succeeded" | "failed" |
canSubmit | boolean |
submissionError | BiasElementsError | null |
Actions are methods:
submit() validates the current form and creates the payment when validation passes. Calls made while a submission is already running or after it succeeds are ignored. setPaymentMethod() ignores a method that the checkout session does not enable. refreshSession() retries a session refresh when a usable session has been retained.
Events
Provider events bubble, so they can be handled on the provider or an ancestor.
| Event | detail | When it fires |
|---|---|---|
biasready | void | The provider controller is attached; the session may still be loading. |
biaschange | BiasElementsState | Any public checkout state changes. |
biascomplete | BiasElementsState | Submission changes to succeeded. |
biaserror | BiasElementsError | A new session, configuration, frame, or payment error occurs. |
Rendering and multiple checkouts
Elements render into the page’s light DOM. Every bias-* host uses display: contents, and the provider stays hidden while it has no usable session. A provider registry associates each child with its nearest provider, so multiple checkout trees on one page keep independent state.
TypeScript exports
The package exports element interfaces, typed event aliases, provider configuration and field binding types, plus the shared checkout types:
The package also augments HTMLElementTagNameMap and HTMLElementEventMap for the registered tags and events.