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)| Hook | Description |
|---|---|
| onEvent | Each CashierEvent, in order (Events). |
| onAmountChange | The live amount (Live amount). |
| methodFilter | Keeps and reorders payment methods (Method filter). |
| fieldRules | Extra checks on fields (Field rules and adjustments). |
| skippedFieldChecks | Field checks to turn off, per method key (Field rules and adjustments). |
| fieldAdjustments | Hide 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.
| Name | Raw value | When |
|---|---|---|
| initSession | initSession | The session was read. |
| initApp | initApp | The Cashier was set up. |
| cashierLoaded | cashier_loaded | The Cashier is ready. |
| paymentMethodSelected | payment_method_selected | A method was selected. |
| createPaymentPage | createPaymentPage | The form of the selected method is ready. |
| hostedPaymentFieldsLoaded | hosted_payment_fields_loaded | The card fields showed. |
| hostedFieldsValid / hostedFieldsInvalid | hpf_form_valid / hpf_form_invalid | The card fields became valid or invalid. |
| methodFieldsLoaded | apm_fields_loaded | The method fields showed. |
| methodFieldsValid / methodFieldsInvalid | apm_form_valid / apm_form_invalid | The method fields became valid or invalid. |
| submit | cashier_submit | The payment was handed off. |
| transactionAttempted | transaction_attempted | The payment answer arrived and is OK. |
| redirection | redirection | A provider page opened. |
| transaction | transaction | A transaction status arrived. |
| thankYouPageLoaded | thank_you_page_loaded | The final result showed. |
| createResultPage | createResultPage | The result page was made. |
| transactionFailed | transaction_failed | The payment ended on an error. |
| loadingFailed | cashier_loading_failed | The Cashier could not load, or ended on an error screen. |
| layoutIncomplete | layout_incomplete | Your layout leaves out a block the payment needs. See Blocks and containers. |
| configurationValueIgnored | configuration_value_ignored | A 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. |
| termsAcceptedByCode | terms_accepted_by_code | Your app ticked the terms box. |
| backButton | cashier_back_button | The 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_errorcode.
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")
]
)| Type | Description |
|---|---|
| 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.
Updated 8 days ago