PlexySDK DOCS
Web SDK

Components

Build a custom checkout flow with individual Plexy payment components

Components

When Drop-in's pre-built UI doesn't fit, mount individual Plexy Components on their own and orchestrate the flow yourself. Each Component renders its own UI and exposes lifecycle callbacks.

'use client';

import { useEffect, useRef } from 'react';
import { PlexyCheckout, Card } from '@plexy/plexy-web';
import '@plexy/plexy-web/styles/plexy.css';
import type { CoreConfiguration, UIElement } from '@plexy/plexy-web';

export function CardOnly({
  session,
}: {
  session: { id: string; sessionData: string };
}) {
  const ref = useRef<HTMLDivElement>(null);
  const initialized = useRef(false);

  useEffect(() => {
    if (initialized.current || !ref.current) return;
    initialized.current = true;

    const options: CoreConfiguration = {
      clientKey: process.env.NEXT_PUBLIC_CLIENT_KEY!,
      environment: 'test',
      countryCode: 'KZ',
      locale: 'en-US',
      amount: { value: 10000, currency: 'KZT' },
      session,
    };

    PlexyCheckout(options).then((checkout) => {
      new Card(checkout, {
        hasHolderName: true,
        onChange(state: { isValid: boolean }, element: UIElement) {
          // Update your pay-button state here.
        },
        onSubmit(state, element: UIElement) {
          // Only fires in the Advanced flow — forward to your backend.
        },
        onError(error) {
          console.error(error);
        },
      }).mount(ref.current!);
    });
  }, [session]);

  return <div ref={ref} />;
}

A standalone Component works with either flow. In the Sessions flow the Component communicates with Plexy directly; in the Advanced flow onSubmit fires with the state your backend should POST to /payments.

On this page