Layouts and examples

This page shows how to build the Cashier: from the predefined template to your own layout (this page), and the blocks and containers a layout is made of (Blocks and containers).

Choose your approach

There are five levels of integration. Start at the top and go down only as far as you need. Every level keeps card and customer data inside the SDK.

LevelWhat you writeWhat you can changeExample
1. Predefined templateOne viewNothing in the layout. Your configuration (settings, theme, texts) and the payment methods set at Praxis still applyThe predefined template as is
2. Template + configurationA CashierConfigurationFeatures on or off, theme, texts, close button, behavior after the resultThe template with configuration
3. Template + slotsA few view modifiersYour header and footer, hidden blocks, your own views between blocksThe template with slots
4. Your own layoutA layout built from SDK blocksThe order of blocks, one page or several, your views next to blocks, your result frameYour own layout from blocks
5. Your own controlsYour views over CashierSnapshot and CashierSession commandsFor example your own method list or amount buttonsPayment method first, with your own method list

The building parts are described in Blocks and containers: blocks (Cashier.Amount(), Cashier.SelectedMethod(), …), containers (Cashier.Steps, Cashier.SinglePage, Cashier.StepPage) and the required-block rule.

Quick integration: the predefined template

The SDK ships one predefined template, Cashier.AmountFirstLayout. CashierView, .cashierSheet and CashierViewController use it when you pass no layout.

It shows up to three pages. Pages a payment does not need are skipped, for example the billing page when the method needs no billing data.

PageContentBottom area
1. AmountHeader, amount and currency, quick amounts, bonuses, selected payment method, promotion code, amount change noteTotal to pay, terms, main button. Footer below
2. Method detailsHeader, step title, method details (card form, saved card CVV, method fields or bank list)Terms (decline recovery only), save-card note, main button
3. BillingHeader, step title, billing formTerms (decline recovery only), main button

After the payment, the template shows processing, 3-D Secure or provider pages, partial approval, decline recovery and result screens.

The predefined template as is

CashierView(token: token, environment: environment) { result in
    handle(result)
}

The same in a sheet, and in UIKit:

.cashierSheet(isPresented: $showsCashier, token: token, environment: environment) { result in
    handle(result)
}

let cashier = CashierViewController(token: token, environment: environment) { result in handle(result) }
present(cashier, animated: true)

The template with configuration

Change what the template shows without touching the layout. Turning a feature off, or leaving promotions unset, also stops the SDK from fetching their data.

// A fixed-amount deposit in your brand colors: no amount editing or currency change, no quick amounts or promotions
// (both are off unless you set them up).
let configuration = CashierConfiguration(
    features: CashierFeatures.default.subtracting([.editableAmount, .currencyChange]),
    theme: CashierTheme(brandColorLight: "#0F768A", brandColorDark: "#3FB6CC", buttonShape: .pill),
    header: CashierHeaderOptions(balance: .hidden),
    texts: CashierTexts(depositButton: "Deposit now"),
    returnsAfterResult: true        // close as soon as the result is known and show your own result screen
)

CashierView(token: token, environment: environment, configuration: configuration) { result in
    handle(result)
}

Which feature or setting controls which part of the template:

Feature or settingBlocks it affects
.editableAmountAmountField: editable, or the session amount as fixed text
presetAmountEditableAmountField: a session amount prefilled and editable instead of fixed text
.amountLimitsAmountLimitHint, and the amount check
.currencyChangeCurrencyLine: the currency sheet
.savedInstrumentsSaved cards and accounts in SelectedMethod's picker
headerHeader: balance, Deposit / Withdraw tabs, back and close buttons
amount.quickAmountsQuickAmounts: no buttons unless you set lists or basedOnLastDeposit
paymentMethodsSelectedMethod's picker: order, limits, fees, card expiry, removal
promotions.stylePromotions: BonusSection for .bonusList, PromoCode for .codeField, nothing for nil
billingFieldsBillingForm: each field editable, read-only or hidden
resultTransactionResult (in Outcome): the payment details shown
footerFooter: shows when at least one link is set

All options are listed in Configuration.

The template with slots

Keep the template and add your branding. See Slots for every slot.

CashierView(token: token, environment: environment, configuration: configuration) { result in
    handle(result)
}
.cashierHeader { BrandHeader() }                               // your header on every page
.cashierFooter { Text("Payments are processed by Praxis") }   // your footer on the amount page
.cashierHide(.quickAmounts)                                    // hide a block
.cashierInsert(after: .selectedMethod) { LoyaltyHint() }       // your view between blocks

In a sheet, put the slots on the template inside .cashierSheet:

.cashierSheet(isPresented: $showsCashier, token: token, environment: environment, onResult: { handle($0) }) {
    Cashier.AmountFirstLayout()
        .cashierHide(.quickAmounts)
        .cashierInsert(after: .selectedMethod) { LoyaltyHint() }
}

In UIKit, use CashierSlots (see Slots in UIKit: CashierSlots).

📘

Replacing the header

Cashier.Header shows the back and close buttons, the Deposit / Withdraw tabs of a session with both intents, and the balance on a withdrawal. If you replace it, give your header a close button (CashierSlotContext.close()) and, on later pages, a back button (back()). Do not replace it in sessions with more than one intent, or the customer cannot switch tabs.

Your own layout from blocks

Pass your layout as the last closure of CashierView, .cashierSheet, or CashierViewController(session:layout:). The SDK runs the same payment flow whatever the layout: it decides which sections a payment needs, what each block shows, and when the main button continues or pays.

Rules to keep in mind for every example below:

  • One page per section in a paged layout. Cashier.Steps has exactly three pages: amount, method details, billing. The amount and the payment method are both in the amount section, so you can order them as you like, but you cannot move the method details onto the amount page. Use Cashier.SinglePage for that.
  • Required blocks. MainButton on every page; Terms and TotalToPay where they can show; the details and billing blocks on their pages. Put Terms in the bottom area of the details and billing pages too: it shows there for the terms step of a decline recovery. See Required blocks.
  • Test every method your account offers with your layout. A missing block disables the main button and sends the layout_incomplete event.

The predefined template, several pages

The predefined template written out, as a starting point to change. The customer enters the amount, picks the method, then fills in the method details and billing on their own pages.

struct TemplateCheckout: View {
    var body: some View {
        Cashier.Steps {
            Cashier.StepPage(scrolling: .wholePage) {
                Cashier.Header()
                Cashier.Amount()
                Cashier.QuickAmounts()
                Cashier.BonusSection()
                Cashier.SelectedMethod()
                Cashier.PromoCode()
                Cashier.AmountChangeNote()
            } bottom: {
                Cashier.TotalToPay()
                Cashier.Terms()
                Cashier.MainButton()
            } below: {
                Cashier.Footer()
            }
        } details: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.MethodDetails()
            } bottom: {
                Cashier.Terms()
                Cashier.SaveCardNote()
                Cashier.MainButton()
            }
        } billing: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.BillingForm()
            } bottom: {
                Cashier.Terms()
                Cashier.MainButton()
            }
        }
    }
}

CashierView(token: token, environment: environment, onResult: handle) {
    TemplateCheckout()
}
📘

The predefined template also sets spacing and screen margins. In your own layout, add .padding and stacks as your design needs. Use @Environment(\.cashierResolvedTheme) and theme.spacing(_:) to match the Cashier's spacing.

Payment method first, several pages

The customer picks the payment method first, then the amount. Only the order of blocks on the first page changes. AmountLimitHint shows the limits of the selected method under the amount.

struct MethodFirstCheckout: View {
    var body: some View {
        Cashier.Steps {
            Cashier.StepPage(scrolling: .wholePage) {
                Cashier.Header()
                Cashier.SelectedMethod()      // 1. the method; a tap opens the method picker
                Cashier.AmountField()         // 2. the amount
                Cashier.CurrencyLine()
                Cashier.AmountLimitHint()     //    the limits of the selected method
                Cashier.QuickAmounts()
                Cashier.AmountChangeNote()
                Cashier.Promotions()          // 3. the bonus list or the promotion code, as promotions.style decides
            } bottom: {
                Cashier.TotalToPay()
                Cashier.Terms()
                Cashier.MainButton()
            }
        } details: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.MethodDetails()
            } bottom: {
                Cashier.Terms()
                Cashier.SaveCardNote()
                Cashier.MainButton()
            }
        } billing: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.BillingForm()
            } bottom: {
                Cashier.Terms()
                Cashier.MainButton()
            }
        }
    }
}
📘

The method list needs an amount

The Cashier loads the payment methods once an amount above zero and a currency are set. Send amount when you create the session, so the methods are ready when the Cashier opens. The amount is then fixed unless you set presetAmountEditable: true. Without a session amount, the method picker fills in after the customer enters an amount.

Payment method first, with your own method list

Instead of the selected-method card and its picker, show every method as a list in your own design. Your view reads CashierSnapshot.methods and selects a method with CashierSession.selectMethod(id:). It sees only each method's id, name, type, logo and whether it is saved or in maintenance; saved cards appear as saved-<n> with an SDK name and no card digits.

struct MethodList: View {
    @Environment(CashierSession.self) private var cashier
    @Environment(\.cashierResolvedTheme) private var theme

    var body: some View {
        VStack(spacing: theme.spacing(.s8)) {
            ForEach(cashier.snapshot.methods, id: \.id) { method in
                Button {
                    cashier.selectMethod(id: method.id)
                } label: {
                    HStack {
                        AsyncImage(url: method.logoURL) { $0.resizable().scaledToFit() } placeholder: { Color.clear }
                            .frame(width: 32, height: 32)
                        Text(method.name).cashierFont(.body)
                        Spacer()
                        if cashier.snapshot.paymentMethod?.id == method.id {
                            Image(systemName: "checkmark")
                        }
                    }
                    .foregroundStyle(theme.color(.primaryText))
                }
                .disabled(method.isInMaintenance)
            }
        }
    }
}

struct MethodListCheckout: View {
    var body: some View {
        Cashier.Steps {
            Cashier.StepPage(scrolling: .wholePage) {
                Cashier.Header()
                MethodList()                  // your list
                Cashier.Amount()
                Cashier.Promotions()
            } bottom: {
                Cashier.TotalToPay()
                Cashier.Terms()
                Cashier.MainButton()
            }
        } details: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.MethodDetails()
            } bottom: {
                Cashier.Terms()
                Cashier.SaveCardNote()
                Cashier.MainButton()
            }
        } billing: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.BillingForm()
            } bottom: {
                Cashier.Terms()
                Cashier.MainButton()
            }
        }
    }
}

Use the methodFilter hook to remove or reorder methods before they reach the list (see Method filter). selectMethod(id:) ignores unknown ids and expired saved cards. A method in maintenance opens its maintenance dialog when it is selected; this example disables it instead.

One-page Cashier

Everything the payment needs on one scrolling page. The main button always pays: there is no Continue step.

struct OnePageCheckout: View {
    var body: some View {
        Cashier.SinglePage {
            Cashier.Header()
            Cashier.Amount()
            Cashier.QuickAmounts()
            Cashier.BonusSection()
            Cashier.SelectedMethod()
            Cashier.PromoCode()
            Cashier.AmountChangeNote()
            Cashier.MethodDetails()           // card form, saved card CVV, method fields or bank list
            Cashier.BillingForm()             // shows only when the payment needs billing data
        } bottom: {
            Cashier.TotalToPay()
            Cashier.Terms()
            Cashier.SaveCardNote()
            Cashier.MainButton()
        }
    }
}

Blocks that do not apply draw nothing, so the page adapts to the selected method: for example, the card form appears when the customer picks a card, and the billing form only when the method needs it.

Express checkout: fixed amount, one page

For a known amount, such as a top-up of a fixed value, combine a short one-page layout with features that lock the amount and skip what you do not need.

let configuration = CashierConfiguration(
    features: CashierFeatures.default.subtracting([.editableAmount, .currencyChange])
)   // quick amounts and promotions are off by default

CashierView(token: token, environment: environment, configuration: configuration, onResult: handle) {
    Cashier.SinglePage {
        Cashier.Header()
        Cashier.Amount()                      // the session amount as fixed text
        Cashier.SelectedMethod()
        Cashier.MethodDetails()
        Cashier.BillingForm()
    } bottom: {
        Cashier.TotalToPay()
        Cashier.Terms()
        Cashier.MainButton()
    }
}

The amount comes from amount in your server's session request.

Several pages with your own header and result frame

Your own header on the first page, the SDK header on later pages (for the back button), and your branding around the SDK's result screens. The outcome page shows loading, processing, decline recovery, results and errors; wrap Cashier.Outcome rather than replacing it.

struct BrandedCheckout: View {
    var body: some View {
        Cashier.Steps {
            Cashier.StepPage(scrolling: .wholePage) {
                MyHeader()                    // reads @Environment(CashierSession.self)
                Cashier.Amount()
                Cashier.SelectedMethod()
                Cashier.Promotions()
            } bottom: {
                Cashier.TotalToPay()
                Cashier.Terms()
                Cashier.MainButton()
            } below: {
                MyTrustBadges()
            }
        } details: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.MethodDetails()
            } bottom: {
                Cashier.Terms()
                Cashier.SaveCardNote()
                Cashier.MainButton()
            }
        } billing: {
            Cashier.StepPage(scrolling: .contentOnly) {
                Cashier.Header()
                Cashier.StepTitle()
                Cashier.BillingForm()
            } bottom: {
                Cashier.Terms()
                Cashier.MainButton()
            }
        } outcome: {
            VStack(spacing: 0) {
                MyBrandBar()
                Cashier.Outcome()
            }
        }
    }
}

struct MyHeader: View {
    @Environment(CashierSession.self) private var cashier

    var body: some View {
        HStack {
            Image("logo")
            Spacer()
            Button("Close") { cashier.close() }
        }
        .padding()
    }
}

Cashier.SinglePage takes an outcome: closure in the same way.

Your own stack, without the SDK containers

If you place blocks in your own views instead of Cashier.Steps or Cashier.SinglePage, declare how you show the sections with .cashierPresentation(_:). Use .single when all blocks are on screen together.

Without the containers, you also choose when to show the form and when to show the outcome screens (loading, processing, 3-D Secure and provider pages, results and errors). Follow CashierSnapshot.step:

struct MyStackCheckout: View {
    @Environment(CashierSession.self) private var cashier

    var body: some View {
        switch cashier.snapshot.step {
        case .amount, .details, .billing:
            ScrollView {
                VStack(spacing: 16) {
                    Cashier.Header()
                    Cashier.Amount()
                    Cashier.SelectedMethod()
                    Cashier.MethodDetails()
                    Cashier.BillingForm()
                    Cashier.TotalToPay()
                    Cashier.Terms()
                    Cashier.MainButton()
                }
            }
            .cashierPresentation(.single)
        default:
            Cashier.Outcome()   // loading, processing, provider pages, results and errors
        }
    }
}

CashierView(session: session) {
    MyStackCheckout()
}

Without .cashierPresentation, the SDK treats the layout as paged, opens only the amount section and sends layout_incomplete with the reason presentation.

UIKit

Host any of the layouts above in UIKit with a session you hold:

let session = CashierSession(token: token, environment: environment, configuration: configuration) { result in
    handle(result)
}
let cashier = CashierViewController(session: session) {
    OnePageCheckout()
}
present(cashier, animated: true)
// Your app closes this session: session.close() when you no longer need it.

Combining layouts with features

A layout decides where blocks go; features and settings decide whether they show. You can keep one layout and change the Cashier per market or per customer group with configuration only:

GoalLayoutConfiguration
Full CashierAmountFirstLayout.default
Returning customers, saved card firstPayment method first, several pages (method first).default
Fixed top-upExpress checkout: fixed amount, one page.default minus .editableAmount, .currencyChange; no quick amounts or promotions set
No promotions in a marketAnypromotions: CashierPromotionOptions(style: nil) for that market
Quick amounts per currencyAnyamount.quickAmounts with one list per currency
Card and saved cards onlyAnymethodFilter hook keeping card methods and saved- rows
Your own result screenAnyreturnsAfterResult: true, then show your screen from onResult

Checklist for your own layout

  • MainButton is on every page, and Terms is in the bottom area of every page.
  • TotalToPay is on the page with the amount.
  • Paged layouts: MethodDetails (or the single detail blocks) on the details page, BillingForm on the billing page. One-page layouts: both on the page.
  • Only one card block (CardForm, SavedCardCode or MethodDetails) on screen at a time.
  • Cashier.Header kept, or your header has close and back buttons, in sessions with one intent only.
  • Tested with every payment method your account offers, with a deposit and a withdrawal if you use both, and with a declined payment that offers a retry.
  • No layout_incomplete event in your logs while testing.

Did this page help you?