4. Show the cashier (SwiftUI, sheet, UIKit)
Present the cashier in one of three ways. All three take the token, the environment, an optional configuration and one onResult closure, called once on the main actor when the cashier closes.
SwiftUI — full screen
struct DepositButton: View {
@State private var launch: Launch?
var body: some View {
Button("Deposit") {
Task { launch = Launch(token: try await myServer.createCashierSession()) }
}
.fullScreenCover(item: $launch) { launch in
CashierView(token: launch.token, environment: environment) { result in
handle(result)
self.launch = nil
}
}
}
}
struct Launch: Identifiable {
let id = UUID()
let token: String
}SwiftUI — sheet presented by the SDK
The cashier closes its session when it is dismissed, and turns the binding false when the customer closes it from inside.
Button("Deposit") { showsCashier = true }
.cashierSheet(isPresented: $showsCashier, token: token, environment: environment) { result in
handle(result)
}UIKit
let cashier = CashierViewController(token: token, environment: environment) { [weak self] result in
self?.dismiss(animated: true)
self?.handle(result)
}
present(cashier, animated: true)CashierViewController takes a CashierSlots value to change the header, the footer or the blocks, as the SwiftUI slot modifiers do (section 9).
While a payment runs
- From the moment the customer pays until the result shows, the cashier hides its close button and refuses a swipe down, so one tap cannot abandon the payment. This covers
.cashierSheet,CashierViewControllerand a sheet you present yourself aroundCashierView. - If your app needs an earlier way out (for example after a time you choose), call
close()on a session you made, or dismiss the cashier. The result is then pending, because the payment may still complete; check its final status on your server.
Notes
- With an empty token the cashier sends no request, shows the token error and ends with the code
invalid_token. - CashierView is generic over its layout. A stored property needs the full type, for example
CashierView<Cashier.AmountFirstLayout>. - Creating a CashierSession is cheap and does no network work. The network starts when the cashier first appears, or when you call
start().
Updated about 8 hours ago
Did this page help you?