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.
| Level | What you write | What you can change | Example |
|---|---|---|---|
| 1. Predefined template | One view | Nothing in the layout. Your configuration (settings, theme, texts) and the payment methods set at Praxis still apply | The predefined template as is |
| 2. Template + configuration | A CashierConfiguration | Features on or off, theme, texts, close button, behavior after the result | The template with configuration |
| 3. Template + slots | A few view modifiers | Your header and footer, hidden blocks, your own views between blocks | The template with slots |
| 4. Your own layout | A layout built from SDK blocks | The order of blocks, one page or several, your views next to blocks, your result frame | Your own layout from blocks |
| 5. Your own controls | Your views over CashierSnapshot and CashierSession commands | For example your own method list or amount buttons | Payment 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.
| Page | Content | Bottom area |
|---|---|---|
| 1. Amount | Header, amount and currency, quick amounts, bonuses, selected payment method, promotion code, amount change note | Total to pay, terms, main button. Footer below |
| 2. Method details | Header, step title, method details (card form, saved card CVV, method fields or bank list) | Terms (decline recovery only), save-card note, main button |
| 3. Billing | Header, step title, billing form | Terms (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 setting | Blocks it affects |
|---|---|
| .editableAmount | AmountField: editable, or the session amount as fixed text |
| presetAmountEditable | AmountField: a session amount prefilled and editable instead of fixed text |
| .amountLimits | AmountLimitHint, and the amount check |
| .currencyChange | CurrencyLine: the currency sheet |
| .savedInstruments | Saved cards and accounts in SelectedMethod's picker |
| header | Header: balance, Deposit / Withdraw tabs, back and close buttons |
| amount.quickAmounts | QuickAmounts: no buttons unless you set lists or basedOnLastDeposit |
| paymentMethods | SelectedMethod's picker: order, limits, fees, card expiry, removal |
| promotions.style | Promotions: BonusSection for .bonusList, PromoCode for .codeField, nothing for nil |
| billingFields | BillingForm: each field editable, read-only or hidden |
| result | TransactionResult (in Outcome): the payment details shown |
| footer | Footer: 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 blocksIn 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.Headershows 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.Stepshas 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. UseCashier.SinglePagefor that. - Required blocks.
MainButtonon every page;TermsandTotalToPaywhere they can show; the details and billing blocks on their pages. PutTermsin 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_incompleteevent.
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
.paddingand stacks as your design needs. Use@Environment(\.cashierResolvedTheme)andtheme.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 amountThe Cashier loads the payment methods once an amount above zero and a currency are set. Send
amountwhen you create the session, so the methods are ready when the Cashier opens. The amount is then fixed unless you setpresetAmountEditable: 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:
| Goal | Layout | Configuration |
|---|---|---|
| Full Cashier | AmountFirstLayout | .default |
| Returning customers, saved card first | Payment method first, several pages (method first) | .default |
| Fixed top-up | Express checkout: fixed amount, one page | .default minus .editableAmount, .currencyChange; no quick amounts or promotions set |
| No promotions in a market | Any | promotions: CashierPromotionOptions(style: nil) for that market |
| Quick amounts per currency | Any | amount.quickAmounts with one list per currency |
| Card and saved cards only | Any | methodFilter hook keeping card methods and saved- |
| Your own result screen | Any | returnsAfterResult: true, then show your screen from onResult |
Checklist for your own layout
-
MainButtonis on every page, andTermsis in the bottom area of every page. -
TotalToPayis on the page with the amount. - Paged layouts:
MethodDetails(or the single detail blocks) on the details page,BillingFormon the billing page. One-page layouts: both on the page. - Only one card block (
CardForm,SavedCardCodeorMethodDetails) on screen at a time. -
Cashier.Headerkept, 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_incompleteevent in your logs while testing.
Updated 8 days ago