9. Slots: change the drop-in cashier

Slots change the drop-in cashier a little without writing your own layout: replace the header or the footer, hide a block, or insert your own content between blocks. They are view modifiers; put them on CashierView, on .cashierSheet, or on the layout you hand to them.

CashierView(token: token, environment: environment) { result in
    handle(result)
}
.cashierHeader { BrandHeader() }
.cashierHide(.quickAmounts)
.cashierInsert(after: .selectedMethod) { LoyaltyHint() }
BlockReplaceHideInsert before or after
Header, footeryesyesyes
Quick amounts, promotionsnoyesyes
Amount, selected method, amount change note, total to pay, terms, main buttonnonoyes
Step title, card form, saved card code, wallet switch, method fields, bank picker, save-card note, billing formnonoyes, around the block
Resultnonoyes
Card fields inside the card formnonono
  • Only blocks without legal or payment meaning can be hidden: header, footer, quickAmounts, promotions.
  • Insert anchors: header, amount, quickAmounts, promotions, selectedMethod, amountChangeNote, totalToPay, terms, mainButton, footer, stepTitle, cardForm, savedCardCode, walletSwitch, methodFields, bankPicker, the save-card note, the billing form and the result.
  • Inserted content sits between blocks in its own clipped container and shows only while its anchor block draws. It never goes inside a block: the card fields are sealed.
  • Several inserts for the same anchor show in the order you wrote them.
  • promotions covers both pieces: the bonus list (drawn above the selected method) and the promotion code (drawn right below it). One cashierHide(.promotions) hides either.

What slot content can read

Slot content never gets the CashierSession. Read the slot context instead: the snapshot and the commands back(), close() and next(), which carry no data.

struct BrandHeader: View {
    @Environment(\.cashierSlotContext) private var cashier

    var body: some View {
        HStack {
            Spacer()
            Button("Close") { cashier?.close() }
        }
    }
}
🚧

Important

Inside slot content the session Environment value is nil, so a non-optional @Environment(CashierSession.self) there stops the app at run time. Use @Environment(\.cashierSlotContext).

In UIKit, build the same changes with a CashierSlots value (header, footer, hide, insert) and pass it to CashierViewController(token:environment:configuration:slots:onResult:).


Did this page help you?