Styled Examples
Four cashiers drawn by the app with Cashier.Pages, with their code.
This page shows four cashiers whose screens are drawn entirely by the app, with Cashier.Pages and the blocks of the Blocks Catalog: Midnight (one page), Signal (two pages), Bloom (three pages) and Relay (four pages). The app draws every pixel it wants to own. The SDK keeps the rules, the limits, the method list, the sealed card inputs and the payment. §1 covers what all four have in common; §2 to §5 show each one, with the code of the techniques that make it look the way it does.
The screenshots are from the iPhone simulator with test data: the amounts and the card are not real.
1. How the examples are built
1.1 The four cashiers
| Cashier | Pages | Look | Techniques |
|---|---|---|---|
| Midnight | 1 | Dark, mint green | Amount with your own currency sheet, method tiles, card inputs on a drawn card, own pay button, own thank-you screen |
| Signal | 2 | White, black and electric blue | Your own amount keypad, card inputs as white pills on a blue card, a summary bar with Edit |
| Bloom | 3 | Soft lavender, round shapes | Method list with saved methods first, amount stepper and quick amounts, a card preview that mirrors the inputs' status |
| Relay | 4 | Warm white, ink and green | Progress header from the page context, a page shown only when needed, a Max amount |
The code is cut to the technique. Views named after the example (MidnightHeader, BloomHeader) and small helpers (currencySign, formatMoney, DetailRow, KeyStyle) are the app's own; a comment next to each says what it draws. Colors such as Midnight.accent are the app's palette.
1.2 Pages and their checks
Cashier.Pages lists your pages in the order the customer goes through them. Each Cashier.Page has a title, the checks its main button runs before the customer may leave it, its content and, optionally, its own pinned bottom area. A page opens the sections of its own checks, and the last page that shows opens every section no earlier page opened. The main button continues on each page before the last and pays on the last page that shows.
Cashier.Pages {
Cashier.Page("Amount", validates: .amount, .method, .terms) {
MyAmountPage()
} bottom: {
Cashier.TotalToPay()
Cashier.Terms()
Cashier.MainButton()
}
Cashier.Page("Details", validates: .methodDetails, .billing) {
MyDetailsPage()
}
} bottom: {
Cashier.MainButton() // for the pages without their own bottom area
} outcome: {
MyOutcome() // loading, processing, results and errors (§1.4)
}| Check | The main button lets the customer leave the page when |
|---|---|
.method | A method is chosen and its details have loaded. The button stays disabled until then. |
.amount | The amount and the currency are set, payable and inside the limits. The button stays disabled until then. |
.methodDetails | The card, the saved card code, the method fields or the bank are valid. A tap shows every error of the page instead. |
.billing | The billing fields are valid. A tap shows every error of the page instead. |
.terms | The terms box is ticked when it is required. A tap shows the terms error instead. |
- A page draws the blocks of its own checks. The last page draws the main button, the terms unless an earlier page checked
.terms, and every input no earlier page checked. Until it does, the main button stays disabled and the eventlayout_incompletenames what is missing. TotalToPaydraws only where the amount section is open: on a page that checks.amountor.method, or on the last page when no earlier page does. Put it there.- Add
.methodto the checks of a page that changes the currency: a new currency can change or clear the method. - Your views read the page the customer is on from
@Environment(\.cashierPage)(§5.2), andcashierPageShown(when:)hides a page the payment does not need (§5.1). - Each page is drawn only while it shows. Keep state that must outlive a page in your app or in the session.
1.3 The theme for the parts the SDK draws
Your views draw most of the screen, but the SDK still draws its parts: the sealed card inputs, the billing form, the total line, the legal text, the sheets and dialogs, and the outcome screens you keep. Set the theme to the same colors, so these parts sit on your pages. Each example has one theme; this is Midnight's:
enum MidnightTheme {
// Midnight.background, .surface, .raised, .border, .text, .muted: the app's own colors.
static let theme = CashierTheme(
brandColorLight: "#5BE7A9", brandColorDark: "#5BE7A9",
brandTextColorLight: "#06281A", brandTextColorDark: "#06281A",
buttonShape: .rounded, appearance: .dark,
roleColors: [
.screenBackground: Midnight.background, .cardSurface: Midnight.surface,
.fieldBackground: Midnight.raised, .fieldBorder: Midnight.border,
.inputBorder: Midnight.border, .cardFieldBorder: Midnight.border,
.primaryText: Midnight.text, .strongText: Midnight.text,
.secondaryText: Midnight.muted, .mutedText: Midnight.muted,
.placeholderText: Midnight.muted, .divider: Midnight.border,
.sheetSurface: Midnight.surface, .dialogSurface: Midnight.surface,
],
cornerRadius: 14)
}
CashierView(token: token, environment: cashierEnvironment,
configuration: CashierConfiguration(theme: MidnightTheme.theme),
onResult: handle) {
MidnightCashier()
}.primaryText is the color of the digits in the sealed card inputs, and .placeholderText the color of their placeholders. See Theme for blocks and sealed parts.
1.4 The outcome page
Each example shows its own thank-you screen with Cashier.TransactionResult { result in … }. The outcome page also shows loading, processing, the partial approval, the bank details of a bank wire, the error screens and the screen with no methods. Build it from the single blocks, as the catalog describes in §9.1: each block draws only on its own screen.
struct BrandOutcome<ThankYou: View>: View {
@ViewBuilder let thankYou: (Cashier.TransactionResultContext) -> ThankYou
var body: some View {
VStack(spacing: 0) {
Cashier.Header() // so the customer can close on every screen
Cashier.Loading()
Cashier.Processing()
Cashier.PartialApproval()
Cashier.BankDetails()
Cashier.TransactionResult { result in thankYou(result) }
Cashier.ErrorScreen()
Cashier.NoMethods()
}
}
}Every example passes it as its outcome: BrandOutcome { result in MidnightThankYou(result: result) }.
Retry, recovery and pending withdrawalsThe retry and recovery pages after a decline, and the list of pending withdrawals, have no block of their own: only
Cashier.Outcome()draws them. If your methods can decline with a retry offer, or you take withdrawals, keepCashier.Outcome()in your outcome page, or usereturnsAfterResultand show your thank-you screen fromonResult. See §11 of the catalog.
Don't show the thank-you screen only whilesnapshot.stepis.result, withCashier.Outcome()for the other steps. The.resultstep also covers processing, the partial approval, the bank details, the retry and recovery pages and the screen with no methods: those screens would stay blank.
2. Midnight: one dark page
Everything on one dark page: a big amount with a currency sheet, method tiles, the card inputs placed on a drawn card face, billing, the terms and a pinned pay button.
| Checkout | Thank you |
|---|---|
![]() | ![]() |
struct MidnightCashier: View {
var body: some View {
Cashier.Pages {
// One page: as the last page, it shows every section and its button pays.
Cashier.Page("Checkout") {
VStack(spacing: 22) {
MidnightHeader() // close button, title, "Secured" badge
MidnightAmount() // §2.1
MidnightMethods() // §2.2
MidnightDetails() // §2.3
Cashier.BillingForm()
MidnightTerms()
}
.padding(.horizontal, 20)
} bottom: {
VStack(spacing: 12) {
Cashier.TotalToPay()
MidnightPayButton() // §2.4
}
.padding(.horizontal, 20)
}
} outcome: {
BrandOutcome { result in MidnightThankYou(result: result) } // §2.5
}
.background(Midnight.background)
.tint(Midnight.accent)
}
}2.1 Amount and currency sheet
Your own field types into the SDK's amount through the AmountField context, so the SDK's format and limits still apply. The currency button opens your own sheet.
struct MidnightAmount: View {
@Environment(CashierSession.self) private var session
@State private var showsCurrencies = false
@FocusState private var isEditing: Bool
var body: some View {
let snapshot = session.snapshot
VStack(alignment: .leading, spacing: 12) {
Cashier.AmountField { field in
HStack(spacing: 12) {
Text(currencySign(field.state.currencyCode)) // "€": the app's formatter
TextField(field.state.placeholder,
text: Binding(get: { field.state.text }, set: { field.setText($0) }))
.font(.system(size: 52, weight: .bold).monospacedDigit())
.keyboardType(.decimalPad)
.focused($isEditing)
.disabled(!field.state.isEditable || field.state.isLocked)
.onChange(of: isEditing) { _, editing in field.setFocused(editing) }
Button { showsCurrencies = true } label: { CurrencyCapsule(code: snapshot.currency) }
.disabled(snapshot.currencies.count < 2)
}
}
Cashier.AmountLimitHint() // the minimum or maximum, when outside
}
.sheet(isPresented: $showsCurrencies) { MidnightCurrencySheet(isPresented: $showsCurrencies) }
}
}The sheet lists snapshot.currencies with a search field, and a pick calls selectCurrency(_:):
struct MidnightCurrencySheet: View {
@Environment(CashierSession.self) private var session
@Binding var isPresented: Bool
@State private var search = ""
var body: some View {
let snapshot = session.snapshot
let codes = snapshot.currencies.filter { search.isEmpty || $0.localizedCaseInsensitiveContains(search) }
VStack(alignment: .leading, spacing: 16) {
Text("Choose currency").font(.title2.bold())
TextField("Search currency", text: $search)
ScrollView {
ForEach(codes, id: \.self) { code in
Button {
session.selectCurrency(code)
isPresented = false
} label: {
CurrencyRow(code: code, isSelected: code == snapshot.currency)
}
}
}
}
.padding(20)
}
}
Midnight replacesCashier.CurrencyLine()with its own sheet. If your sessions show amounts in a base currency, keepCashier.CurrencyLine(): only it draws the exchange line. See Currency.
2.2 Method tiles
There is no method list block: the tiles come from snapshot.methods, and a tap calls selectMethod(id:). Mark the tile that equals snapshot.paymentMethod, because the SDK can change it after a new currency.
struct MidnightMethods: View {
@Environment(CashierSession.self) private var session
var body: some View {
let snapshot = session.snapshot
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 10) {
ForEach(snapshot.methods, id: \.id) { method in
let isOn = method.id == snapshot.paymentMethod?.id
Button { session.selectMethod(id: method.id) } label: {
MethodTile(icon: myIcon(for: method), name: method.name, isSelected: isOn)
}
.disabled(method.isInMaintenance)
.accessibilityAddTraits(isOn ? .isSelected : [])
}
}
}
}
}myIcon(for:) is the app's own mapping from the method's type and name to an icon. To show the server logo instead, use method.logoURL.
2.3 Card inputs on a drawn card face
The card face is your view; each input on it is a Cashier.CardField with your caption and underline around the sealed input. The brand on the face comes from the number input's state.brand. Next to the card, the SDK draws the details of the other methods.
struct MidnightDetails: View {
@Environment(CashierSession.self) private var session
var body: some View {
if let method = session.snapshot.paymentMethod, isCardMethod(method) {
MidnightCardFace()
}
// The details of the other methods. Each block draws nothing when it does not apply.
Cashier.WalletSwitch()
Cashier.MethodFields()
Cashier.BankPicker()
}
}
struct MidnightCardFace: View {
@State private var brand: CashierCardBrand?
var body: some View {
VStack(alignment: .leading, spacing: 18) {
Text(brand.map { $0.rawValue.uppercased() } ?? "CARD")
Cashier.CardField(.number) { field in
faceField(field, caption: "Card number")
.onChange(of: field.state.brand, initial: true) { _, new in brand = new }
}
HStack(alignment: .top, spacing: 16) {
Cashier.CardField(.expiry) { field in faceField(field, caption: "Expires") }
Cashier.CardField(.securityCode) { field in faceField(field, caption: "CVC") }
}
Cashier.CardField(.holder) { field in faceField(field, caption: "Name on card") }
}
.padding(20)
.background(CardFaceBackground()) // your card: rounded rectangle, chip, rings
}
}Each input on the face: a small caption that focuses the input, the sealed input, and an underline that lights up with the focus or turns red with an issue.
extension MidnightCardFace {
func faceField(_ field: Cashier.CardFieldContext, caption: String) -> some View {
let state = field.state
let line = state.issue != nil ? Midnight.error : state.isFocused ? Midnight.accent : Midnight.border
return VStack(alignment: .leading, spacing: 4) {
Text(caption.uppercased())
.font(.caption.weight(.medium))
.accessibilityHidden(true) // the sealed input reads the SDK's label
.onTapGesture { field.focus() }
field.input.frame(height: 30) // sealed: the SDK draws the digits
Rectangle().fill(line).frame(height: state.isFocused || state.issue != nil ? 2 : 1)
if let issue = state.issueText {
Text(issue).font(.caption).foregroundStyle(Midnight.error)
}
}
}
}
isCardMethod(_:)is the app's own rule, from the method'stypeandname. Make sure it matches every card method of your account, saved cards included: a card method whoseCardFields are not on the page cannot pay (layout_incomplete). TheCardFields themselves draw nothing for a method that takes no card.
2.4 Pay button
The pay button is your view over Cashier.MainButtonContext. When Apple Pay pays, place the sealed Apple Pay button instead.
struct MidnightPayButton: View {
var body: some View {
Cashier.MainButton { button in
if let applePay = button.applePay {
applePay.frame(height: 56).clipShape(.rect(cornerRadius: 18))
} else {
Button { button.perform() } label: {
HStack(spacing: 8) {
if button.state.isBusy { ProgressView() } else { Image(systemName: "lock.fill") }
Text(button.state.label) // "Deposit", in the session language
}
.frame(maxWidth: .infinity).frame(height: 56)
.background(button.state.isEnabled ? Midnight.accent : Midnight.raised,
in: .rect(cornerRadius: 18))
.foregroundStyle(button.state.isEnabled ? Midnight.onAccent : Midnight.muted)
}
}
}
}
}The button looks disabled from isEnabled but still takes the tap: on a disabled button, perform() shows what is missing.
2.5 Thank-you screen
The title, the amount and the buttons come from the result context; the status, the method and the reference from snapshot.result.
struct MidnightThankYou: View {
let result: Cashier.TransactionResultContext
@Environment(CashierSession.self) private var session
var body: some View {
let outcome = session.snapshot.result
let status = outcome?.status
let isSuccess = status == .completed || status == .authorized || status == .pending
VStack(spacing: 22) {
StatusRings(isSuccess: isSuccess) // the check mark in rings
Text(result.state.title ?? (isSuccess ? "Payment complete" : "Payment failed"))
if let amount = result.state.amount, let currency = result.state.currency {
Text(amount.formatted(.currency(code: currency)))
}
DetailRow("Method", outcome?.cardBrand?.capitalized ?? outcome?.paymentMethod ?? "")
if let id = outcome?.transactionID { DetailRow("Reference", id) }
Spacer()
ForEach(result.state.buttons, id: \.action) { button in
Button(button.label) { result.perform(button.action) }
}
if result.state.buttons.isEmpty {
Button("Done") { session.close() }
}
}
}
}Midnight treats pending as success: the payment will complete. Give pending its own look if your methods often stay pending.
3. Signal: two pages
Page 1 is a big amount typed on the app's own keypad, with the method chips. Page 2 puts the card inputs in white pills on a blue card, under a summary bar.
| Amount | Card | Thank you |
|---|---|---|
![]() | ![]() | ![]() |
struct SignalCashier: View {
var body: some View {
Cashier.Pages {
Cashier.Page("Amount", validates: .amount, .method, .terms) {
VStack(alignment: .leading, spacing: 20) {
SignalHeader(step: 1) // close or back, "Step 1 of 2"
Text("How much?")
SignalCurrencySwitch() // a segmented control over snapshot.currencies
SignalAmountPad() // §3.1
SignalMethodChips() // a two-column grid, as in §2.2
}
.padding(.horizontal, 20)
} bottom: {
VStack(spacing: 12) {
Cashier.TotalToPay()
SignalTerms()
SignalButton()
}
.padding(.horizontal, 20)
}
Cashier.Page("Details", validates: .methodDetails, .billing) {
VStack(alignment: .leading, spacing: 18) {
SignalHeader(step: 2)
SignalSummary() // §3.3
SignalCardDetails() // §3.2
Cashier.WalletSwitch()
Cashier.MethodFields()
Cashier.BankPicker()
Cashier.BillingForm()
}
.padding(.horizontal, 20)
} bottom: {
SignalButton().padding(.horizontal, 20)
}
} outcome: {
BrandOutcome { result in SignalThankYou(result: result) }
}
.tint(Signal.accent)
}
}3.1 Your own amount keypad
No system keyboard: each key sends the new text with setText(_:). The SDK reads it as it reads its own field, with its separators, decimals and limits, and the big number shows state.text.
struct SignalAmountPad: View {
private static let keys = ["1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "0"]
var body: some View {
Cashier.AmountField { field in
VStack(spacing: 18) {
Text(currencySign(field.state.currencyCode) + (field.state.text.isEmpty ? "0" : field.state.text))
.font(.system(size: 64, weight: .bold).width(.expanded).monospacedDigit())
.accessibilityLabel("Amount")
.accessibilityValue(field.state.text)
if field.state.isEditable && !field.state.isLocked {
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 8), count: 3), spacing: 8) {
ForEach(Self.keys, id: \.self) { key in
Button(key) { field.setText(field.state.text + key) }
.buttonStyle(KeyStyle())
}
Button { field.setText(String(field.state.text.dropLast())) } label: {
Image(systemName: "delete.left")
}
.buttonStyle(KeyStyle())
.accessibilityLabel("Delete")
}
}
}
}
}
}The keypad shows only while the amount can change: a locked amount shows as a number only.
3.2 Card inputs in pills on a blue card
The blue card is your view. Each input is a white pill: the SDK's label above it, the sealed input inside, a ring with the focus, and the issue below in a light red that reads on blue. The sealed input draws its digits in the theme's .primaryText, Signal's near-black, so they read on the white pill.
struct SignalCardDetails: View {
@Environment(CashierSession.self) private var session
var body: some View {
if let method = session.snapshot.paymentMethod, isCardMethod(method) {
VStack(alignment: .leading, spacing: 14) {
Label("Card details", systemImage: "lock.fill").foregroundStyle(.white)
Cashier.CardField(.number) { field in pill(field) }
HStack(alignment: .top, spacing: 12) {
Cashier.CardField(.expiry) { field in pill(field) }
Cashier.CardField(.securityCode) { field in pill(field) }
}
Cashier.CardField(.holder) { field in pill(field) }
}
.padding(18)
.background(Signal.accent, in: .rect(cornerRadius: 22))
}
}
private func pill(_ field: Cashier.CardFieldContext) -> some View {
let state = field.state
let ring = state.issue != nil ? Signal.errorOnBlue : state.isFocused ? Color.white : .clear
return VStack(alignment: .leading, spacing: 6) {
Text(state.label)
.foregroundStyle(.white.opacity(0.85))
.accessibilityHidden(true)
.onTapGesture { field.focus() }
HStack(spacing: 8) {
field.input.frame(height: 30)
if state.isValid && !state.isEmpty {
Image(systemName: "checkmark.circle.fill").foregroundStyle(Signal.success)
}
}
.padding(.horizontal, 14).padding(.vertical, 8)
.background(.white, in: .rect(cornerRadius: 14))
// The ring sits 4 points outside the pill, so a white ring still shows around a white pill.
.padding(4)
.overlay(RoundedRectangle(cornerRadius: 18).stroke(ring, lineWidth: 2).allowsHitTesting(false))
.padding(-4)
if let issue = state.issueText {
Text(issue).foregroundStyle(Signal.errorOnBlue)
}
}
}
}3.3 Summary bar with Edit
Page 2 starts with what page 1 chose: the amount and the method from the snapshot. Edit goes back to page 1.
struct SignalSummary: View {
@Environment(CashierSession.self) private var session
var body: some View {
let snapshot = session.snapshot
HStack {
VStack(alignment: .leading, spacing: 2) {
Text(formatMoney(snapshot.amount, snapshot.currency))
Text(snapshot.paymentMethod?.name ?? "")
}
Spacer()
Button("Edit") { session.back() }
}
.foregroundStyle(.white)
.padding(.horizontal, 16).frame(height: 60)
.background(Signal.ink, in: .rect(cornerRadius: 16))
}
}The thank-you screen follows §2.5, with a blue header and a timeline of rows. Its "Back to the app" button is the fallback for a result with no buttons: it calls session.close().
4. Bloom: three pages
Method, then amount, then card, on a soft lavender page with round shapes. The card page has a violet card preview that mirrors the status of each input, never its content.
| Method | Amount | Card | Thank you |
|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
struct BloomCashier: View {
var body: some View {
Cashier.Pages {
Cashier.Page("Method", validates: .method) {
BloomMethodScreen().padding(.horizontal, 20) // §4.1
}
Cashier.Page("Amount", validates: .amount, .method, .terms) {
BloomAmountScreen().padding(.horizontal, 20) // §4.2
} bottom: {
VStack(spacing: 12) {
Cashier.TotalToPay()
BloomTerms()
BloomMainButton()
}
.padding(.horizontal, 20)
}
Cashier.Page("Card", validates: .methodDetails, .billing) {
BloomCardScreen().padding(.horizontal, 20) // §4.3
}
} bottom: {
BloomMainButton().padding(.horizontal, 20) // the method and card pages
} outcome: {
BrandOutcome { result in BloomThankYou(result: result) }
}
.tint(Bloom.accent)
.fontDesign(.rounded)
}
}
The method list loads for an amount above 0. When the method page comes before the amount, start the session with an amount. See Your own method list.
4.1 Method rows, saved methods first
The same data as the tiles of §2.2, split by isSaved into two groups.
struct BloomMethodScreen: View {
@Environment(CashierSession.self) private var session
var body: some View {
let snapshot = session.snapshot
let saved = snapshot.methods.filter(\.isSaved)
let others = snapshot.methods.filter { !$0.isSaved }
VStack(alignment: .leading, spacing: 10) {
BloomHeader(step: 1) // the Method, Amount, Card dots
Text("How would you like to pay?").font(.largeTitle.bold())
if !saved.isEmpty {
SectionTitle("Saved")
ForEach(saved, id: \.id) { MethodRow(method: $0, isSelected: $0.id == snapshot.paymentMethod?.id) }
}
if !others.isEmpty {
SectionTitle(saved.isEmpty ? "Ways to pay" : "Other ways to pay")
ForEach(others, id: \.id) { MethodRow(method: $0, isSelected: $0.id == snapshot.paymentMethod?.id) }
}
}
}
}MethodRow is a button that calls session.selectMethod(id: method.id), disabled with "Under maintenance" while method.isInMaintenance is true.
4.2 Amount stepper and quick amounts
The amount field sits between a minus and a plus button. Each step, like each quick amount, sets the amount with setAmount(_:), through the same rules as typing. The currency menu above it is a Menu over snapshot.currencies that calls selectCurrency(_:).
struct BloomStepButton: View {
let symbol: String
let step: Decimal
@Environment(CashierSession.self) private var session
var body: some View {
Button {
let current = session.snapshot.amount ?? 0
session.setAmount(max(current + step, 0))
} label: {
Image(systemName: symbol).frame(width: 52, height: 52)
}
}
}
// HStack { BloomStepButton(symbol: "minus", step: -5); Cashier.AmountField { … }; BloomStepButton(symbol: "plus", step: 5) }The quick amounts leave out amounts above the method's maximum:
struct BloomQuickAmounts: View {
@Environment(CashierSession.self) private var session
private let values: [Decimal] = [25, 50, 75, 100, 250, 500]
var body: some View {
let snapshot = session.snapshot
let limits = snapshot.amountLimits
let maximum = limits?.currency == snapshot.currency ? limits?.maximum : nil
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 8), count: 3), spacing: 8) {
ForEach(values.filter { value in maximum.map { value <= $0 } ?? true }, id: \.self) { value in
let isOn = snapshot.amount == value
Button(formatWhole(value, snapshot.currency)) { session.setAmount(value) } // "€50"
.buttonStyle(ChipStyle(isSelected: isOn))
.accessibilityAddTraits(isOn ? .isSelected : [])
}
}
}
}4.3 A card preview that mirrors the inputs
Each card field reports its flags (focused, valid, empty, brand) under its kind with a preference key. The preview above the inputs reads them: the brand, and for each input a pill that says done, typing or still to do. Flags are all the app gets: the digits stay in the sealed inputs.
struct CardInputFlags: Equatable {
let isFocused: Bool
let isValid: Bool
let isEmpty: Bool
let brand: CashierCardBrand?
}
struct CardInputsKey: PreferenceKey {
static let defaultValue: [String: CardInputFlags] = [:]
static func reduce(value: inout [String: CardInputFlags], nextValue: () -> [String: CardInputFlags]) {
value.merge(nextValue()) { _, new in new }
}
}
struct BloomField: View {
let field: Cashier.CardFieldContext
var body: some View {
let state = field.state
BloomFieldFrame(field: field) // the app's own: label, the sealed input, focus ring, issue text
.preference(key: CardInputsKey.self, value: [state.kind.rawValue: CardInputFlags(
isFocused: state.isFocused, isValid: state.isValid, isEmpty: state.isEmpty, brand: state.brand)])
}
}The card page collects them:
struct BloomCardScreen: View {
@State private var inputs: [String: CardInputFlags] = [:]
var body: some View {
VStack(alignment: .leading, spacing: 16) {
BloomHeader(step: 3)
BloomCardPreview(inputs: inputs) // shows inputs.values.compactMap(\.brand).first
VStack(spacing: 12) {
Cashier.CardField(.number) { BloomField(field: $0) }
HStack(alignment: .top, spacing: 12) {
Cashier.CardField(.expiry) { BloomField(field: $0) }
Cashier.CardField(.securityCode) { BloomField(field: $0) }
}
Cashier.CardField(.holder) { BloomField(field: $0) }
}
.onPreferenceChange(CardInputsKey.self) { inputs = $0 }
Cashier.SaveCardNote()
Cashier.WalletSwitch()
Cashier.MethodFields()
Cashier.BankPicker()
Cashier.BillingForm()
}
}
}In Bloom, the preview and the card fields show only for a card method, with the rule of §2.3.
4.4 Status on the thank-you ticket
The ticket follows §2.5 and adds the status from snapshot.result:
let status = session.snapshot.result?.status
let isSuccess = status == .completed || status == .authorized || status == .pending
HStack {
Text("Status")
Spacer()
Text(status?.description.capitalized ?? "") // "Completed"
.padding(.horizontal, 10).frame(height: 26)
.background(isSuccess ? Bloom.successSoft : Bloom.error.opacity(0.12), in: Capsule())
}5. Relay: four pages
The method, then the amount and the currency, then the card, then a review with billing and the terms. No screenshots: Relay shows how the pages read where the customer is, and how a page hides when the payment does not need it.
struct RelayCashier: View {
var body: some View {
Cashier.Pages {
Cashier.Page("Method", validates: .method) { RelayPage { RelayMethodPage() } }
Cashier.Page("Amount", validates: .amount, .method) {
RelayPage {
RelayAmountPage()
Cashier.TotalToPay() // the amount section is open on this page
}
}
Cashier.Page("Card", validates: .methodDetails) { RelayPage { RelayCardPage() } }
.cashierPageShown { page in page.isNeeded } // skipped for a method without details
Cashier.Page("Review", validates: .billing) {
RelayPage {
RelayReview() // method and amount rows
Cashier.BillingForm()
Cashier.Terms()
}
}
} bottom: {
RelayButton().padding(.horizontal, 20).padding(.vertical, 12)
} outcome: {
BrandOutcome { result in RelayDone(result: result) }
}
}
}RelayPage puts the progress header of §5.2 above each page's content.
5.1 A page shown only when needed
cashierPageShown(when:) asks again whenever the method, the amount or the currency changes. page.isNeeded is true when the page runs a check the payment needs now: a wallet or a method without details needs no card page. A hidden page is skipped by the main button and by back, and the progress header counts only the pages that show.
5.2 Progress header from the page context
@Environment(\.cashierPage) gives the page the customer is on: its title, its place among the pages that show, and back().
struct RelayProgress: View {
@Environment(CashierSession.self) private var session
@Environment(\.cashierPage) private var page
var body: some View {
VStack(alignment: .leading, spacing: 14) {
HStack {
Button {
if !page.back() { session.close() } // the first page has no page before it
} label: {
Image(systemName: page.isFirst ? "xmark" : "chevron.left")
}
.accessibilityLabel(page.isFirst ? "Close" : "Back")
Spacer()
Text("Step \(page.index + 1) of \(page.count)")
}
HStack(spacing: 6) {
ForEach(0..<page.count, id: \.self) { index in
Capsule().fill(index <= page.index ? Relay.accent : Relay.line).frame(height: 4)
}
}
Text(page.title).font(.system(size: 30, weight: .bold, design: .serif))
}
}
}5.3 A Max amount, and a method lost to a new currency
The amount page adds a Max chip from the method's maximum. A new currency can clear the method: the page then offers a way back to the method page, and its .method check keeps the button disabled meanwhile.
/// The quick amounts, then MAX: the method's maximum, in the same currency.
func chips(_ snapshot: CashierSnapshot) -> [(Decimal, String)] {
let quick: [Decimal] = [25, 50, 100]
guard let maximum = snapshot.amountLimits?.maximum, snapshot.amountLimits?.currency == snapshot.currency else {
return quick.map { ($0, formatWhole($0, snapshot.currency)) }
}
return quick.filter { $0 < maximum }.map { ($0, formatWhole($0, snapshot.currency)) } + [(maximum, "MAX")]
}
// In the amount page, which reads @Environment(\.cashierPage) private var page:
if snapshot.paymentMethod == nil {
Button("Choose a payment method again") { page.back() }
}6. What every example shares
- No card data in the app. The card inputs are sealed
CardFieldinputs inside your frames. Your views read flags, the brand and the SDK's texts, never the digits. The thank-you screens show the brand and the method name fromsnapshot.result. - Checks per page. Each page lists what it validates. The amount page also checks
.method, because a new currency can change the method; the page that checks.termsshows the terms. - The theme covers what the SDK draws. One
CashierThemeper example colors the sealed inputs, the billing form, the total line, the legal text and the outcome screens to match the app's views. - SDK texts, as they come. Labels, issue texts, button labels and result titles come from the SDK in the session language. The app's own words ("How much?", "Edit") are the app's to translate into
snapshot.language. - Every screen after the form. The outcome page keeps the SDK's loading, processing, partial approval, bank details, error and no-method screens around the own thank-you screen (§1.4). The result on screen never credits the customer: your server waits for the Payment Notification.
What's next
- Blocks Catalog: every block these examples use, with its state and actions.
- Layouts: the predefined template, slots and the blocks and containers.
- Configuration & Customization: the theme, the texts and every setting.
- Results, Errors & Troubleshooting
- SDK Reference
Updated about 18 hours ago








