Events and hooks

CashierHooks

Put your code in CashierHooks and pass it in CashierConfiguration(hooks:). Every hook runs on the main actor.

let hooks = CashierHooks(
    onEvent: { event in analytics.track(event.name.rawValue, traceID: event.traceID) },
    onAmountChange: { update in
        if let total = update.total ?? update.totalCharge { cartView.show(total, update.currency) }
    },
    methodFilter: { methods in methods.filter { !$0.isInMaintenance }.map(\.id) },
    fieldRules: [CashierFieldRule(field: "zip", minimumLength: 4)]
)
let configuration = CashierConfiguration(hooks: hooks)
HookDescription
onEventEach CashierEvent, in order (Events).
onAmountChangeThe live amount (Live amount).
methodFilterKeeps and reorders payment methods (Method filter).
fieldRulesExtra checks on fields (Field rules and adjustments).
skippedFieldChecksField checks to turn off, per method key (Field rules and adjustments).
fieldAdjustmentsHide a field, make it required, or give it a start value (Field rules and adjustments).

Events

Event names are the web Payment Page SDK names, so you can track the app and the web the same way. A few events exist only in the SDK: layout_incomplete, configuration_value_ignored and terms_accepted_by_code. Read the name with event.name.rawValue.

NameRaw valueWhen
initSessioninitSessionThe session was read.
initAppinitAppThe Cashier was set up.
cashierLoadedcashier_loadedThe Cashier is ready.
paymentMethodSelectedpayment_method_selectedA method was selected.
createPaymentPagecreatePaymentPageThe form of the selected method is ready.
hostedPaymentFieldsLoadedhosted_payment_fields_loadedThe card fields showed.
hostedFieldsValid / hostedFieldsInvalidhpf_form_valid / hpf_form_invalidThe card fields became valid or invalid.
methodFieldsLoadedapm_fields_loadedThe method fields showed.
methodFieldsValid / methodFieldsInvalidapm_form_valid / apm_form_invalidThe method fields became valid or invalid.
submitcashier_submitThe payment was handed off.
transactionAttemptedtransaction_attemptedThe payment answer arrived and is OK.
redirectionredirectionA provider page opened.
transactiontransactionA transaction status arrived.
thankYouPageLoadedthank_you_page_loadedThe final result showed.
createResultPagecreateResultPageThe result page was made.
transactionFailedtransaction_failedThe payment ended on an error.
loadingFailedcashier_loading_failedThe Cashier could not load, or ended on an error screen.
layoutIncompletelayout_incompleteYour layout leaves out a block the payment needs. See Blocks and containers.
configurationValueIgnoredconfiguration_value_ignoredA configuration value you set was ignored, for example an invalid color, a negative amount or a URL that is not https. ignoredName names the field.
termsAcceptedByCodeterms_accepted_by_codeYour app ticked the terms box.
backButtoncashier_back_buttonThe customer tapped the header back button on the first page. This button shows only when header.showsBackButton is true. The Cashier stays open, so your app can react, for example by closing it.

There is no event for a step change (read CashierSnapshot.step), no click event and no per-field event.

Event fields. Every field of CashierEvent, with its format, is listed in the SDK Reference. Events carry the method type, action type, status, error code, card brand, validity, amount and currency, trace ID, the ignored value name, the layout_incomplete reason and the intents; a field is nil when the event does not use it. cashier_loaded always carries currency (the account's base currency, else the session currency) and amount (the session amount, nil when there is none). The two withdrawal error pages send transaction_failed, not cashier_loading_failed.

Deposits and withdrawals. event.intent is the intent of the tab the customer is on (.deposit or .withdrawal), so you can track withdrawals apart from deposits. A card authorization session reports a deposit. secondaryIntents is set on cashier_loaded and cashier_loading_failed in sessions that offer more than one intent.

Live amount

onAmountChange gets a CashierAmountUpdate while the amount section shows an amount: first when it shows, then each time the amount, charge, display amount, fee, total or currency changes. On a withdrawal, displayAmount is what leaves the balance and total is what the customer receives. When the customer sees only the base currency and the method charges in another currency, displayAmount, fee and total are in the method's currency while currency stays the base currency.

Every field of CashierAmountUpdate is listed in the SDK Reference.

Method filter

methodFilter gets the methods the picker would offer ([CashierMethodInfo]) and returns the ids to keep, in the order to show. It can remove and reorder methods, but not add one. Unknown ids are ignored. A saved card or account has the opaque id saved-<n>.

⚠️

If your filter returns no id from the list it got, the Cashier shows its error screen and ends with the configuration_error code.

Field rules and adjustments

Field names are the names Praxis sends for a method's fields, for example account_number or zip.

let hooks = CashierHooks(
    fieldRules: [
        CashierFieldRule(field: "account_number", methods: ["example_wallet"], pattern: "^[0-9]+$", minimumLength: 6)
    ],
    skippedFieldChecks: ["example_wallet": ["address"]],
    fieldAdjustments: [
        .hide(field: "state", method: "example_wallet"),
        .require(field: "phone", method: "example_wallet"),
        .defaultValue("GB", field: "country", method: "example_wallet")
    ]
)
TypeDescription
CashierFieldRule(field:methods:pattern:minimumLength:isRequired:errorTextKey:)Adds a check to a method or billing field: a regular expression, a minimum length, or a required value. methods nil means every method. errorTextKey picks the message from CashierTexts.
skippedFieldChecks[method key: Set
CashierFieldAdjustment.hide(field:method:), .require(field:method:), .defaultValue(_:field:method:).

The SDK applies these inside. Your code never sees what the customer types.

What never reaches your code

Events and hooks never carry card numbers, CVVs, card tokens, customer data (name, email, phone, address), field values, server messages or the session token.


Did this page help you?