Component Hierarchy
- Web
- Android
- iOS
- React Native
The components follow a hierarchical structure where parent components provide context to their children. Each parent literally contains its children. The spatial nesting mirrors the DOM nesting.
- Without vault
- With vault
The components follow a hierarchical structure where the checkout controller manages presentation components, which in turn contain SDK UI elements.
- CheckoutSheet
- CheckoutHost
The iOS SDK uses a SwiftUI slot hierarchy. The managed
PrimerCheckout view renders the full flow on its own and exposes no slots. For a composable layout, the .primerCheckoutSession modifier places your PrimerCheckoutSession in the environment. Composable views such as PrimerCardForm and PrimerPaymentMethods resolve it from there.The React Native SDK uses a React context hierarchy.
PrimerCheckoutProvider owns the checkout session, and the Primer components and hooks below it read the session from there. Render PrimerCheckoutSheet inside the provider for the prebuilt flow, or compose your own layout from the components and hooks. Card components also need PrimerCardFormProvider above them.Core Components
- Web
- Android
- iOS
- React Native
| Component | Purpose |
|---|---|
<primer-checkout> | Root component that initializes the SDK and provides checkout context |
<primer-main> | Manages checkout states and provides layout customization |
<primer-payment-method> | Renders a specific payment method (card, PayPal, Apple Pay, etc.) |
<primer-payment-method-container> | Container for filtering and organizing multiple payment methods |
Checkout controllers
| Function | Returns | Purpose |
|---|---|---|
rememberPrimerCheckoutController() | PrimerCheckoutController | Main session controller |
rememberCardFormController() | PrimerCardFormController | Card form state and actions |
rememberPaymentMethodsController() | PrimerPaymentMethodsController | Available payment methods |
rememberVaultedPaymentMethodsController() | PrimerVaultedPaymentMethodsController | Saved payment methods |
Presentation components
Entry points
Composable views
Each composable view exposes slots and resolves its session from the environment injected by.primerCheckoutSession(_:theme:onCompletion:).| Component | Description | API Reference |
|---|---|---|
PrimerCardForm | Card payment form with cardDetails, billingAddress, and submitButton slots | Reference |
PrimerPaymentMethods | Available payment method list with header, method, and emptyState slots | Reference |
PrimerVaultedPaymentMethods | Saved payment method shortcut for returning customers, with header, item, and submitButton slots. It pays with the selected saved method and renders nothing when none is saved. | Reference |
Entry points
| Component | Description | API Reference |
|---|---|---|
PrimerCheckoutProvider | Root component. Starts the checkout session from a client token and provides it, with your theme and callbacks, to the components and hooks below it | Reference |
PrimerCheckoutSheet | Prebuilt bottom sheet that runs the whole checkout | Reference |
usePrimerCheckout | Hook that returns the checkout state, the payment outcome and the checkout actions | Reference |
Composable components
Render these components insidePrimerCheckoutProvider to build your own layout.| Component | Description | API Reference |
|---|---|---|
PrimerPaymentMethodList | The session’s payment methods as buttons. Calls onSelect with the method the shopper taps, and doesn’t start a payment itself | Reference |
PrimerCardFormProvider | Holds the card form state for PrimerCardForm, the card inputs, and usePrimerCardForm | Reference |
PrimerCardForm | Card number, expiry date, CVV, and cardholder name fields | Reference |
PrimerCardNetworkSelector | Network selector for co-badged cards | Reference |
PrimerAcceptedCardNetworks | Row of the card networks the session accepts | Reference |
PrimerKlarnaPaymentView | Klarna’s embedded payment view, for the Klarna flow of usePrimerPaymentMethod | Reference |
Card Form Components
- Web
- Android
- iOS
- React Native
| Component | Purpose |
|---|---|
<primer-card-form> | Container that provides context for card inputs |
<primer-input-card-number> | Secure hosted input for card number |
<primer-input-card-expiry> | Secure hosted input for expiry date |
<primer-input-cvv> | Secure hosted input for CVV |
<primer-input-card-holder-name> | Input for cardholder name |
<primer-card-form-submit> | Submit button with built-in loading states |
<primer-input-label> | Label component for card inputs |
<primer-input-wrapper> | Wrapper for styling and layout of inputs |
<primer-billing-address> | Billing address collection form |
Defaults objects
| Object | Parent Component | Sub-components |
|---|---|---|
PrimerCheckoutSheetDefaults | PrimerCheckoutSheet | Splash, Loading, Success, Error, PaymentMethodSelection, VaultedMethods, PaymentMethods |
CardFormDefaults | PrimerCardForm | CardNumberField, ExpiryField, CvvField, CardholderField, CardNetworkField, CountryCodeField, billing fields, SubmitButton |
PaymentMethodsDefaults | PrimerPaymentMethods | SectionHeader, Method, EmptyState |
State types
| Type | Purpose | Values |
|---|---|---|
PrimerCheckoutState | Checkout lifecycle and payment outcomes | Loading, Ready, Success, Failure |
PrimerCardFormController.State | Card form state | Field values, validation, loading |
Defaults namespaces
Each composable view falls back to itsDefaults namespace when a slot is omitted. You can also call these helpers inside your own slots to keep the SDK rendering while adding custom layout.| Namespace | Parent component | Section helpers | Per-field building blocks |
|---|---|---|---|
CardFormDefaults | PrimerCardForm | cardDetails, billingAddress, submitButton | cardNumber, expiryDate, cvv, cardholderName, cardNetwork, countryCode, firstName, lastName, addressLine1, addressLine2, city, state, postalCode |
PaymentMethodsDefaults | PrimerPaymentMethods | header, method, emptyState | — |
VaultedPaymentMethodsDefaults | PrimerVaultedPaymentMethods | header, item, submitButton | — |
CardFormDefaults per-field block takes the PrimerCardFormSession and returns a view: CardFieldContent, or CardNetworkFieldContent for cardNetwork. Every block except cardNetwork renders nothing unless its field is part of the active CardFormConfiguration. cardNetwork is a standalone co-badged card network selector. It renders only when the card has more than one available network. The cardNumber block and the full cardDetails section already show the network selector inside the card number field. Do not add cardNetwork next to either, or two selectors appear. Use cardNetwork only when you want the selector outside the card number field.Sessions
| Session | Purpose | Key members |
|---|---|---|
PrimerCardFormSession | Card form state and actions | state, updateCardNumber(_:), updateCountryCode(_:), selectCardNetwork(_:), submit() |
PrimerSelectionSession | Payment method selection | state, select(_:), selectVaulted(_:) (pays with a saved method), vaultedPaymentMethods |
State types
| Type | Purpose | Key properties |
|---|---|---|
PrimerCheckoutState | Checkout lifecycle and outcome | .initializing, .ready, .success, .failure, .dismissed |
PrimerCardFormState | Card form state | isValid, isLoading, fieldErrors, selectedNetwork, selectedCountry, data |
PrimerPaymentMethodSelectionState | Payment method list | Available and selected payment methods |
Field presence and styling
There is no per-field configuration or styling struct. Which fields appear is Dashboard-driven throughCardFormConfiguration (read from session.state.configuration), and visual styling is theme-driven via PrimerCheckoutTheme design tokens. To recompose a layout, arrange the CardFormDefaults per-field building blocks inside your own slot:PrimerCardForm(
cardDetails: { session in
VStack(spacing: 12) {
CardFormDefaults.cardNumber(session)
HStack(spacing: 12) {
CardFormDefaults.expiryDate(session)
CardFormDefaults.cvv(session)
}
CardFormDefaults.cardholderName(session)
}
}
)
Card inputs
Each input renders one card field that is already wired to the card form. Place the inputs insidePrimerCardFormProvider.| Component | Field | API Reference |
|---|---|---|
PrimerCardNumberInput | Card number. Shows the co-badged network selector when the card has more than one accepted network | Reference |
PrimerExpiryDateInput | Expiry date, as MM/YY | Reference |
PrimerCVVInput | Security code | Reference |
PrimerCardholderNameInput | Cardholder name | Reference |
PrimerTextInput | Text input with the look of the card inputs, for your own fields | Reference |
Hooks
| Hook | Purpose | Key members |
|---|---|---|
usePrimerCardForm | Card form state and actions | cardNumber, updateCardNumber(value), isValid, errors, isSubmitting, submit(), reset() |
usePrimerCardNetwork | Detected card network | network, descriptor, iconSource |
usePrimerCardNetworkSelection | Network selection on co-badged cards | availableNetworks, selectedNetwork, isSelectorVisible, selectNetwork(identifier) |
State types
| Type | Purpose | Key properties |
|---|---|---|
PrimerCheckoutContextValue | Return value of usePrimerCheckout() | isReady, error, clientSession, paymentOutcome |
PaymentOutcome | Result of the latest payment attempt | status ('success', 'pending' or 'error'), data, error |
UsePrimerCardFormReturn | Card form state | Field values, isValid, errors, isSubmitting, isCardholderNameVisible, descriptor |
Field presence and styling
PrimerCardForm shows the card fields in a fixed order and hides the cardholder name when the client session’s CARD_INFORMATION checkout module turns it off. Visual styling comes from the theme prop of PrimerCheckoutProvider, and each input also takes its own theme of type PrimerTextInputTheme. To change the layout, arrange the card inputs yourself:import { View } from 'react-native';
import {
PrimerCardholderNameInput,
PrimerCardNumberInput,
PrimerCVVInput,
PrimerExpiryDateInput,
usePrimerCardForm,
} from '@primer-io/react-native';
function CardFields() {
const cardForm = usePrimerCardForm();
return (
<View style={{ gap: 12 }}>
<PrimerCardNumberInput />
<View style={{ flexDirection: 'row', gap: 12 }}>
<PrimerExpiryDateInput style={{ flex: 1 }} />
<PrimerCVVInput label={cardForm.descriptor.cvvLabel} style={{ flex: 1 }} />
</View>
{cardForm.isCardholderNameVisible && <PrimerCardholderNameInput />}
</View>
);
}
PrimerCardNumberInput already shows the co-badged network selector. Don’t add PrimerCardNetworkSelector next to it, or two selectors appear. Render PrimerCardholderNameInput when isCardholderNameVisible is true, as above. Render CardFields inside PrimerCardFormProvider, and start the card payment method with start() from usePrimerPaymentMethod('PAYMENT_CARD').Utility Components
- Web
- Android
- iOS
- React Native
| Component | Purpose |
|---|---|
<primer-error-message-container> | Displays payment error messages |
<primer-vault-manager> | Manages saved payment methods |
<primer-show-other-payments> | Toggle button to show additional payment methods |
Theming
| Class | Purpose |
|---|---|
PrimerTheme | Root theme container |
LightColorTokens | Light mode colors |
DarkColorTokens | Dark mode colors |
SpacingTokens | Spacing values |
TypographyTokens | Font styles |
RadiusTokens | Corner radius |
WidthTokens | Border widths |
SizeTokens | Component sizes |
Theming
| Struct | Purpose |
|---|---|
PrimerCheckoutTheme | Root theme container |
ColorOverrides | Brand, background, text, border, icon, focus, and loader colors. Set light mode with colors and dark mode with darkColors. A color left nil in darkColors uses Primer’s dark default, even when colors sets it. |
RadiusOverrides | Corner radius values |
SpacingOverrides | Spacing values |
SizeOverrides | Component sizes |
TypographyOverrides | Font styles and sizes |
WidthOverrides | Border widths for the default, focus, error, and selected states |
Slot closures
Customization points are the slots on the composable views. Each slot receives the relevant session (or model) and returns your view.PrimerCardForm and PrimerPaymentMethods slots are @ViewBuilder closures. PrimerVaultedPaymentMethods slots return AnyView, so wrap your content in AnyView(...).| Slot | Receives | On |
|---|---|---|
cardDetails, billingAddress, submitButton | PrimerCardFormSession | PrimerCardForm |
header, emptyState | PrimerSelectionSession | PrimerPaymentMethods |
method | CheckoutPaymentMethod, () -> Void | PrimerPaymentMethods |
header | PrimerSelectionSession | PrimerVaultedPaymentMethods |
item | VaultedMethod, Bool (is selected), () -> Void (on select) | PrimerVaultedPaymentMethods |
submitButton | Bool (is loading), Bool (is enabled), () -> Void (on submit) | PrimerVaultedPaymentMethods |
Theming
| Type | Purpose |
|---|---|
PrimerThemeOverride | Type of the provider’s theme prop. Holds light and dark overrides, and every token group is set per mode |
PrimerColorTokens | Brand, background, text, border, icon, focus, loader, and overlay colors |
PrimerSpacingTokens | Spacing values |
PrimerTypographyTokens | Font family and text styles |
PrimerRadiusTokens | Corner radius values |
PrimerSizeTokens | Component sizes |
PrimerWidthTokens | Border widths for the default, focus, selected, and error states |
PrimerTextInputTheme | Style overrides for a single input, through its theme prop |
usePrimerTheme() returns the tokens in effect, so you can style your own components to match. See PrimerThemeOverride.Status screens and hooks
Customization points are the components you render and the hooks you build your own UI on.| API | Purpose |
|---|---|
| Status screens | PrimerLoadingScreen, PrimerSuccessScreen, PrimerErrorScreen, and PrimerStatusScreenLayout: the loading and result screens of the prebuilt sheet, for your own layout |
usePrimerPaymentMethods | The session’s payment methods as data, for your own list |
usePrimerPaymentMethod | One hook for any payment method: check its kind, then start it |
usePrimerVaultManager | The customer’s saved payment methods: list, select, pay, and delete |
usePrimerLocalization | Translated strings, and currency and date formatting in the device language |
Basic Usage
- Web
- Android
- iOS
- React Native
<primer-checkout client-token="your-client-token">
<primer-main slot="main">
<div slot="payments">
<!-- Payment methods appear here -->
<primer-payment-method type="PAYMENT_CARD"></primer-payment-method>
<primer-payment-method type="PAYPAL"></primer-payment-method>
<!-- Error display -->
<primer-error-message-container></primer-error-message-container>
</div>
<div slot="checkout-complete">
<h2>Payment successful!</h2>
</div>
</primer-main>
</primer-checkout>
@Composable
fun CheckoutScreen(clientToken: String) {
val checkout = rememberPrimerCheckoutController(clientToken)
val state by checkout.state.collectAsStateWithLifecycle()
LaunchedEffect(state) {
when (val s = state) {
is PrimerCheckoutState.Success -> navigateToConfirmation(s.checkoutData)
is PrimerCheckoutState.Failure -> {
Log.e("Checkout", "Failed: ${s.primerError.description}")
}
else -> Unit
}
}
PrimerCheckoutSheet(
checkout = checkout,
onDismiss = { navigateBack() },
)
}
struct CheckoutView: View {
let clientToken: String
var body: some View {
PrimerCheckout(
clientToken: clientToken,
primerSettings: PrimerSettings(paymentHandling: .auto),
primerTheme: PrimerCheckoutTheme(
colors: ColorOverrides(primerColorBrand: .blue)
),
onCompletion: { state in
switch state {
case .success(let result):
print("Payment: \(result.paymentId)")
case let .failure(error, _):
print("Failed: \(error.errorId)")
case .dismissed:
print("Dismissed")
default:
break
}
}
)
}
}
import { useEffect, useState } from 'react';
import { Button } from 'react-native';
import {
PrimerCheckoutProvider,
PrimerCheckoutSheet,
usePrimerCheckout,
} from '@primer-io/react-native';
import type { PrimerSettings, PrimerThemeOverride } from '@primer-io/react-native';
const settings: PrimerSettings = {
uiOptions: { appearanceMode: 'SYSTEM' },
};
const theme: PrimerThemeOverride = {
light: { colors: { brand: '#2F6FED' } },
dark: { colors: { brand: '#6B9BFF' } },
};
function PaymentResult() {
const { paymentOutcome } = usePrimerCheckout();
useEffect(() => {
if (paymentOutcome?.status === 'success') {
console.log('Payment:', paymentOutcome.data.payment?.id);
} else if (paymentOutcome?.status === 'error') {
console.log('Failed:', paymentOutcome.error.errorId);
}
}, [paymentOutcome]);
return null;
}
export function CheckoutScreen({ fetchClientToken }: { fetchClientToken: () => Promise<string> }) {
const [clientToken, setClientToken] = useState<string | null>(null);
const [visible, setVisible] = useState(false);
const openCheckout = async () => {
setClientToken(await fetchClientToken());
setVisible(true);
};
return (
<>
<Button title="Checkout" onPress={openCheckout} />
{clientToken !== null && (
<PrimerCheckoutProvider clientToken={clientToken} settings={settings} theme={theme}>
<PaymentResult />
<PrimerCheckoutSheet
visible={visible}
onRequestDismiss={() => setVisible(false)}
onDismiss={() => setClientToken(null)}
/>
</PrimerCheckoutProvider>
)}
</>
);
}
How Components Communicate
Components communicate through:- Context inheritance - Child components receive context from their parents (e.g., card inputs receive form context from their parent card form)
- Events - Components emit events that you can listen to for state changes
- Customization points (Slots on Web, Composable lambdas on Android, slot closures on iOS, composition with components and hooks on React Native) - Allow you to inject custom content at specific points
For details on events, see the Events guide.
Customization at Each Level
- Web
- Android
- iOS
- React Native
<primer-checkout>- SDK options, theming, global configuration<primer-main>- Layout structure through customization points<primer-payment-method>- Payment method-specific options<primer-card-form>- Complete control over card form layout and styling
PrimerCheckoutSheet/PrimerCheckoutHost- Presentation mode and event handlingPrimerCheckoutSheetDefaults- Override default screens (splash, loading, success, error)CardFormDefaults- Customize individual card form fieldsPrimerTheme- Colors, typography, spacing, and border radius
PrimerCheckout- Client token, settings, theme, and completion handling for the managed flowPrimerCheckoutSession+.primerCheckoutSession- Inline, composable layouts and completion handling throughonCompletionPrimerPaymentMethods-header,method, andemptyStateslots for the payment method listPrimerCardForm-cardDetails,billingAddress, andsubmitButtonslots, recomposed fromCardFormDefaultsPrimerCheckoutTheme- Light and dark colors, typography, spacing, sizes, radius, and border widths
PrimerCheckoutProvider- Client token, settings, theme, and theonCheckoutComplete,onError, andonBeforePaymentCreatecallbacksPrimerCheckoutSheet- The prebuilt flow, opened and closed throughvisibleandonRequestDismissPrimerPaymentMethodList- Which payment methods to show, withincludeandexclude, and what happens ononSelectPrimerCardFormand the card inputs - The card form, or the inputs in your own layout with their ownlabel,placeholder, andthemePrimerThemeOverride- Colors, typography, spacing, sizes, radii, and border widths, each set separately for light and dark mode
See also
Using Slots
Learn how to customize layout with slots
Build a custom card form
Step-by-step tutorial for card form customization
Styles
Customize appearance with CSS variables
SDK Reference
Detailed API documentation for all components