Blocks and containers
Overview
This section is the reference for blocks, containers and the rules they follow. For complete examples (the predefined template written out, payment method first, one page, several pages, express checkout), see Layouts and examples.
The predefined template is Cashier.AmountFirstLayout. When slots are not enough, build your own layout from the same blocks: SwiftUI views in the Cashier namespace, such as Cashier.Amount() or Cashier.MainButton(). Each block reads what it needs from the session and draws nothing when it does not apply. Blocks take no data.
Pass your layout to CashierView, .cashierSheet or CashierViewController. Each wraps it in a CashierScope for you.
A payment has up to three sections: the amount, the method details and billing. The session decides which sections a payment needs. A container decides how they show:
Cashier.Steps: one page per section; sections the payment does not need are skipped.Cashier.SinglePage: every section the payment needs on one page. The main button always pays.
Both containers show Cashier.Outcome for loading, processing, results and errors.
Several pages
CashierView(session: session) {
Cashier.Steps {
Cashier.StepPage(scrolling: .wholePage) {
Cashier.Header()
Cashier.Amount()
Cashier.SelectedMethod()
} bottom: {
Cashier.TotalToPay()
Cashier.Terms()
Cashier.MainButton()
}
} details: {
Cashier.StepPage(scrolling: .contentOnly) {
Cashier.Header()
Cashier.StepTitle()
Cashier.MethodDetails()
} bottom: {
Cashier.Terms() // shows here only on the terms step of a decline recovery
Cashier.SaveCardNote()
Cashier.MainButton()
}
} billing: {
Cashier.StepPage(scrolling: .contentOnly) {
Cashier.Header()
Cashier.StepTitle()
Cashier.BillingForm()
} bottom: {
Cashier.Terms()
Cashier.MainButton()
}
}
}Cashier.StepPage gives a page a scrolling content area and a bottom area that stays above the keyboard. .wholePage scrolls the header with the content; .contentOnly keeps the header in place. Cashier.Steps has exactly one page per section; to combine sections on one page, use Cashier.SinglePage.
One page
CashierView(session: session) {
Cashier.SinglePage {
Cashier.Header()
Cashier.Amount()
Cashier.BonusSection()
Cashier.SelectedMethod()
Cashier.PromoCode()
Cashier.MethodDetails()
Cashier.BillingForm()
} bottom: {
Cashier.TotalToPay()
Cashier.Terms()
Cashier.MainButton()
}
}Without the containers. If you place blocks in your own stack, tell the SDK how you present the sections with .cashierPresentation(.single) or .cashierPresentation(.paged). Without it, the SDK treats the layout as paged, opens only the amount section, and sends layout_incomplete with the reason "presentation".
Blocks
| Block | What it shows | Section |
|---|---|---|
| Header | The title bar, back and close buttons | Every page |
| Footer | The footer under the first page | Amount |
| Amount | AmountField, CurrencyLine and AmountLimitHint together | Amount |
| AmountField | The amount | Amount |
| CurrencyLine | The currency, and the currency sheet when it can change | Amount |
| AmountLimitHint | The method's lowest and highest amount | Amount |
| QuickAmounts | Ready amount buttons | Amount |
| Promotions | BonusSection or PromoCode, as promotions.style decides | Amount |
| BonusSection | The bonuses the customer can pick | Amount |
| PromoCode | The promotion code field | Amount |
| SelectedMethod | The selected method and the method picker | Amount |
| AmountChangeNote | A note when the method changes the amount | Amount |
| TotalToPay | The fee and the total | Amount |
| Terms | The terms box | Amount; details and billing during a decline recovery |
| MainButton | Continue or Pay | Every page |
| StepTitle | The title of a later page | Details, billing |
| MethodDetails | The details of the selected method: one of the four blocks below | Details |
| CardForm | The card fields for a new card | Details |
| SavedCardCode | The CVV field for a saved card | Details |
| MethodFields | The fields of a non-card method | Details |
| BankPicker | The bank list of a bank wire | Details |
| SaveCardNote | The note that a new card is saved | Details |
| BillingForm | Billing and contact fields | Billing |
| Outcome | Every screen after the form: loading, processing, retry and recovery pages, results, errors | Outcome |
| Loading, Processing, TransactionResult, BankDetails, PartialApproval, ErrorScreen, NoMethods | The single outcome screens | Outcome |
Sealed: the block captures or shows card or personal data. You can place it, but you cannot rebuild it, read its values or put content inside it.
Required blocks
Some blocks carry legal or payment meaning. When a section that needs one is open, it must be on screen:
| Needed when | Block |
|---|---|
| Always | MainButton |
| The terms box shows | Terms |
| The total shows | TotalToPay |
| A new card | CardForm (or MethodDetails) |
| A saved card | SavedCardCode (or MethodDetails) |
| The method has fields | MethodFields (or MethodDetails) |
| A bank wire | BankPicker (or MethodDetails) |
| The billing section | BillingForm |
When a required block is missing, the main button is disabled, no payment is sent, and the SDK sends layout_incomplete with the reason "requiredBlock". Two card blocks on screen at once (two CardForm, or CardForm with SavedCardCode) give the reason "duplicateSealed" and stop the payment. The predefined template has every block.
Terms on later pagesIn a paged layout, put
Termsin the bottom area of the details and billing pages too. The terms box shows there for the terms step of a decline recovery; without the block, the main button stays disabled on that step.
Test your layout with every payment method your account offers. The SDK checks for common mistakes but cannot catch every misuse.
Your views next to the blocks
Views inside your layout can read the session and the theme:
struct MyHeader: View {
@Environment(CashierSession.self) private var cashier
@Environment(\.cashierResolvedTheme) private var theme
var body: some View {
Text(cashier.snapshot.amount?.formatted() ?? "")
.foregroundStyle(theme.color(.primaryText))
}
}They can read CashierSession.snapshot, the read-only state of the Cashier, and send its commands, such as next() or selectMethod(id:). The snapshot never holds card data or personal data. Every property and command is listed in the SDK Reference (CashierSession).
Updated 8 days ago