Skip to content

Events

Implement callbacks to customise your payment flow.

Overview

Components surface callbacks from shopper interaction and validation. You attach closures on configuration types in PXPCheckoutSDK so your app can run business rules and refresh the UI while the SDK handles PCI scope, tokenisation, optional 3DS, and transport.

Callbacks enable you to:

  • Validate business rules before payments proceed.
  • Display custom error, failure, or success messages.
  • Tailor the interface to match your app.
  • Integrate with fraud tools or your own customer systems.
  • Control how shoppers experience both successful and failed transactions.
  • Drive loading states, token lists, saved-card flows, and 3DS where you enable it.

All events are optional and can be mixed and matched based on your business needs.

Supported events

Use the matrices below to see which pre-built or standalone surface supports each callback; expand a cell for scope. Session-wide hooks live on CheckoutConfig (onGetShopper, onGetShippingAddress, analyticsEvent — see Analytics). Pay lifecycle hooks live on CardSubmitComponentConfig, usually nested under NewCardComponentConfig.submit or ClickOnceComponentConfig.cardSubmitComponentConfig (About configuration, Card submit).

The following table lists all events supported by the different pre-built card components.

EventBilling addressCard-on-fileClick-onceNew card
onBlur
Nested fields only

New card only
onCardBrandCannotRecognised
Card number field only
onCardBrandDetected
Card number field only
onChange
Nested fields only

New card only
onClick
Click Once cardSubmitComponentConfig only

New card submit only
onCollectEnd
Click Once cardSubmitComponentConfig only

New card submit only
onCollectStart
Click Once cardSubmitComponentConfig only

New card submit only
onCustomValidation
Click Once cardSubmitComponentConfig only

New card submit only
onDeleteTokenFailed
onDeleteTokenSuccess
onFocus
Nested fields only

New card only
onGetFingerprintResult
Click Once cardSubmitComponentConfig only

New card submit only
onOnceCardClick
onPostAuthentication
Click Once cardSubmitComponentConfig only

New card submit only
onPostAuthorisation
Click Once cardSubmitComponentConfig only

New card submit only
onPostInitiateAuthentication
Click Once cardSubmitComponentConfig only

New card submit only
onPostTokenisation
Also on nested submit when used
onPreAuthentication
Click Once cardSubmitComponentConfig only

New card submit only
onPreAuthorisation
Click Once cardSubmitComponentConfig only

New card submit only
onPreDeleteToken
onPreInitiateAuthentication
Click Once cardSubmitComponentConfig only

New card submit only
onPreRenderTokens
onPreTokenisation
Click Once cardSubmitComponentConfig only

New card submit only
onRetrieveTokensFailed
onSelectToken
onSubmitError
Click Once cardSubmitComponentConfig only

New card submit only
onUpdateTokenFailed
onUpdateTokenSuccess
onValidation
onValidationPassed
Nested fields only

New card only
onValidationFailed
Nested fields only

New card only
tokenItemBuilder
tokenLabelBuilder
onPaste
Secured fields under fields only
onRetrieveTokensSuccess
onStartSubmit
Click Once cardSubmitComponentConfig only

New card submit only
onValidationError
buttonBuilder
selectTokenItemBuilder

Billing address means the pre-built billing address form: nested CountrySelectionComponentConfig, PostcodeComponentConfig, and AddressComponentConfig under fields. The pre-fill billing checkbox is a standalone component (see the Standalone tab). Dynamic card image is configured on the new card flow for presentation only; it doesn't expose events on DynamicCardImageComponentConfig.

buttonBuilder

Builds the primary action control for Click Once standalone flows. Also supported on pre-built Click Once when shown in the matrix.

Use this to match your app’s button styling for one-tap checkout.

Signature

(ClickOnceButtonBuilderElements) -> AnyView (see SDK types and Click Once).

onBlur

Runs when a billing or card field loses focus (FieldComponentConfig and SecuredFieldComponentConfig subclasses).

Use this to hide inline help or run your own validation pass after the shopper leaves the field.

Signature

() -> Void — no payload; read values from your own state if needed.

Example implementation

CardNumberComponentConfig(
    label: "Card number",
    onBlur: { /* update UI */ }
)

onCardBrandCannotRecognised

Runs on the card number field when digits don't match a known brand pattern.

Use this to show generic card art or guidance for unknown BIN ranges.

Signature

(CardBrandDetectionEvent) -> Void

Event data

PropertyDescription
cardBrandCardBrandInfo from the SDK.
isCardBrandAcceptedWhether the brand is allowed, when the SDK can determine it.

onCardBrandDetected

Runs when the card number field recognises a scheme.

Use this to swap card art, show accepted-brand messaging, or log analytics.

Signature

(CardBrandDetectionEvent) -> Void — same payload shape as onCardBrandCannotRecognised.

onChange (fields and billing)

Runs when the shopper edits a billing or card field (not the pay button state).

Use this to sync custom labels, enable dependent fields, or debounce your own checks.

Signature

() -> Void — no payload for these configs.

onChange (submit)

Runs when CardSubmitComponent coarse state changes (idle, loading, success, error).

Use this to drive a global spinner or disable navigation while submit is in flight.

Signature

(ComponentState) -> Void

onClick

Runs when the shopper activates the submit control, before deeper validation.

Use this to log intent, play haptics, or guard double submission at the very start of the tap.

Signature

() -> Void on CardSubmitComponentConfig.

onCollectEnd

Runs when a device-data collection phase finishes during submit.

Use this to clear intermediate UI tied to collection.

Signature

(Any) -> Void — treat the argument as opaque unless your SDK version documents it.

onCollectStart

Runs when a device-data collection phase starts during submit.

  • Show “preparing secure check” style messaging.

Signature

(Any) -> Void

onCustomValidation

Runs after field validation passes; return whether submit may continue.

Use this to re-check basket price, inventory, or session with your backend before tokenisation.

Signature

() async -> Bool — return false to block submit.

onDeleteTokenFailed

Runs when deleting a saved token from the vault fails (CardOnFileComponentConfig).

Use this to show an error and keep the list consistent.

Signature

(DeleteCardTokenResponseFailed) -> Void

onDeleteTokenSuccess

Runs when a saved token was removed successfully.

Use this to refresh your local list and analytics.

Signature

(DeleteCardTokenResponseSuccess) -> Void

onFocus

Runs when a billing or card field receives focus.

Use this to show inline help or scroll the field into view.

Signature

() -> Void

onGetFingerprintResult

Async hook on CardSubmitComponentConfig when the flow needs a fingerprint string.

Use this to return device or session data your processor expects.

Signature

() async -> String

onOnceCardClick

Runs when the shopper uses the Click Once one-tap affordance (standalone or pre-built, per matrix).

Use this to start your server-side path for that flow or log funnel events.

Signature

See ClickOnceStandaloneComponentConfig in Click Once.

onPostAuthentication

Runs after the 3DS authentication step completes (success or failure path), on CardSubmitComponentConfig.

Use this to log authentication outcomes or adjust UI before authorisation continues.

Signature

(AuthenticationResult) -> Void — cast to FailedAuthenticationResult or ExceptionAuthenticationResult on failure paths; see 3DS.

onPostAuthorisation

Runs after the gateway has finished processing the payment (authorised, captured, refused, or failed).

Use this to navigate, show receipts, or reconcile orders.

Signature

(BaseSubmitResult) -> Void

Event data

Downcast result — common types include AuthorisedSubmitResult, CapturedSubmitResult, RefusedSubmitResult, FailedSubmitResult, and MerchantSubmitResult depending on intent and response.

Example implementation

submitConfig.onPostAuthorisation = { result in
    if let success = result as? AuthorisedSubmitResult {
        print("transaction=\(success.fundingData.transactionId ?? "")")
    } else if let refused = result as? RefusedSubmitResult {
        print("refused: \(refused.state ?? "")")
    } else if let failed = result as? FailedSubmitResult {
        print("failed: \(failed.errorCode ?? "") \(failed.errorReason ?? "")")
    }
}

onPostInitiateAuthentication

Runs after the 3DS pre-initiate call returns.

Use this to inspect coarse stateData or handle FailedAuthenticationResult.

Signature

(AuthenticationResult) -> Void — see 3DS.

onPostTokenisation

Runs after tokenisation completes. Appears on NewCardComponentConfig and on CardSubmitComponentConfig when nested as submit (see Supported events).

Use this to store gatewayTokenId for subscriptions or card on file.

Signature

(CardTokenizationResult) -> Void — cast to CardTokenizationResultSuccess or CardTokenizationResultFailed.

Example implementation

submitConfig.onPostTokenisation = { result in
    if let ok = result as? CardTokenizationResultSuccess {
        print("token=\(ok.gatewayTokenId)")
    } else if let fail = result as? CardTokenizationResultFailed {
        print("token failed: \(fail.errorCode) \(fail.errorReason ?? "")")
    }
}

onPreAuthentication

Async hook before 3DS authentication runs; return initiate payload or nil to abort.

Use this to supply merchant country, legal name, challenge window, shopper contact, and optional ThreeDSRecurring for recurring setups.

Signature

() async -> InitiateIntegratedAuthenticationData? — see 3DS.

onPreAuthorisation

Runs before the authorisation request is sent. Required for the authorisation step to complete as expected.

Use this to return TransactionInitiationData (PSD2 exemptions, risk payloads) or nil to stop.

Signature

(PreAuthorizationData?) async -> TransactionInitiationData?

Event data

PreAuthorizationData in this build exposes gatewayTokenId and schemeTokenId where applicable.

Example implementation

submitConfig.onPreAuthorisation = { preAuth in
    // This is an async closure - you can use await here if needed
    // await someAsyncOperation()
    _ = preAuth?.gatewayTokenId
    return TransactionInitiationData()
}

onPreDeleteToken

Runs before the SDK deletes a saved token; return whether to proceed.

Use this to confirm with your server or show a final confirmation sheet.

Signature

(BaseCardToken) async -> Bool

onPreInitiateAuthentication

Async hook before 3DS pre-initiate; return data or nil to skip 3DS for that attempt.

Use this to supply providerId, requestor indicator, and timeouts.

Signature

() async -> PreInitiateIntegratedAuthenticationData? — pair with onPreAuthentication per 3DS and Non-3DS.

onPreRenderTokens

Runs when the saved-card list is about to render; return mappings for display.

Use this to filter or reorder tokens for the current session (CardOnFileComponentConfig; also Click Once retrieve flows per matrix).

Signature

(RetrieveCardTokensResponseSuccess) -> [CardTokenMapping]

onPreRetrySoftDecline

Runs when the SDK offers a soft-decline retry path.

Use this to decide whether to retry with adjusted data.

Signature

(BaseSubmitResult) -> SoftDeclineRetryResult — see Card submit.

onPreTokenisation

Runs immediately before tokenisation; return whether to continue.

Use this to gate on consent when you don't use CardConsentComponent, or block when fraud checks fail.

Signature

() -> Bool — return false to cancel.

onRetrieveTokensFailed

Runs when loading saved tokens fails (card on file or Click Once, per matrix).

Use this to show retry UI or fall back to new-card entry.

Signature

(RetrieveCardTokensResponseFailed) -> Void on card on file; Click Once uses ClickOnceRetrieveTokensError — see Click Once.

onRetrieveTokensSuccess

Runs when saved tokens were loaded successfully.

Use this to bind your model to gatewayTokens / schemeTokens.

Signature

(RetrieveCardTokensResponseSuccess) -> Void on card on file; Click Once uses ClickOnceRetrieveTokensSuccess — see Click Once.

onSelectToken

Runs when the shopper picks a saved token in card on file.

Use this to highlight the row and pass the token id to submit.

Signature

(BaseCardToken) -> Void — cast to GatewayToken or SchemeToken as needed.

Example implementation

cofConfig.onSelectToken = { token in
    if let gateway = token as? GatewayToken {
        print("Selected: \(gateway.gatewayTokenId)")
    }
}

onStartSubmit

Runs after field validation passes and before tokenisation on CardSubmitComponentConfig.

Use this to show a full-screen or inline loading state for the pay journey.

Signature

() -> Void

onSubmitError

Runs when the SDK reports a failure during submit (validation, vault, network, 3DS runtime, and similar).

Use this to clear loading UI and map errorCode to shopper-safe copy.

Signature

(BaseSdkException) -> Void — use errorCode and errorMessage.

Example implementation

submitConfig.onSubmitError = { error in
    switch error.errorCode {
    case "SDK0503", "SDK0505":
        showAuthenticationRetryUI()
    default:
        showGenericPaymentError(error.errorMessage)
    }
}

onUpdateTokenFailed

Runs when updating token metadata on the vault fails.

Use this to show an error toast and revert UI.

Signature

(UpdateCardTokenResponseFailed) -> Void

onUpdateTokenSuccess

Runs when a saved token was updated successfully.

Use this to refresh labels (for example new expiry).

Signature

(UpdateCardTokenResponseSuccess) -> Void

onValidation

Aggregates linked field validation for submit (CardSubmitComponentConfig), or appears on NewCardComponentConfig for container-level results — prefer submit and per-field callbacks for most UX (New card).

Use this to enable or disable the pay button from one snapshot.

Signature

([ValidationResult]) -> Void

Example implementation

let newCardConfig = NewCardComponentConfig(
    fields: fields,
    submit: submit,
    onValidation: { results in
        let ok = results.allSatisfy(\.valid)
        updatePayButtonEnabled(ok)
    }
)

onValidationFailed

Runs when a field fails validation for that field’s config.

Use this to show inline errors from ValidationResult.errors.

Signature

([ValidationResult]) -> Void

onValidationPassed

Runs when a field passes validation for that field’s config.

Use this to clear error state for that field.

Signature

([ValidationResult]) -> Void

Example implementation

CountrySelectionComponentConfig(
    label: "Country",
    onValidationFailed: { results in
        for result in results where !result.valid {
            result.errors?.values.forEach { print($0.code, $0.message) }
        }
    }
)

onValidationError

Runs for SDK validation-style errors on card-on-file or Click Once (for example CVC format), as BaseSdkException.

Use this to map errorCode / errorMessage next to the saved-card entry UI.

Signature

(BaseSdkException) -> Void

onPaste

Runs when the shopper pastes into a secured field (PAN, expiry, CVC).

Use this to track paste-assisted entry or adjust formatting hints.

Signature

() -> Void on SecuredFieldComponentConfig subclasses.

selectTokenItemBuilder

Builds each token row in Click Once token selection UI.

Use this to render scheme icons and masked PAN in SwiftUI.

Signature

See ClickOnceStandaloneComponentConfig in Click Once.

tokenItemBuilder

Builds each saved card row for card on file.

Use this to customise list layout beyond default styling.

Signature

(CardTokenBuilderElements) -> AnyView

tokenLabelBuilder

Produces the subtitle or label string for a saved token row.

Use this to show Scheme •••• 1234 style text.

Signature

(BaseCardToken) -> String

Example implementation

cofConfig.tokenLabelBuilder = { token in
    let last4 = String(token.maskedPrimaryAccountNumber.suffix(4))
    return "\(token.cardScheme.rawValue) •••• \(last4)"
}

FieldComponent.onTriggerFieldValidation

Optional instance hook on FieldComponent (not on FieldComponentConfig). The SDK may set it internally.

Use this to react to imperative validation triggers if you attach to the component after creation.

Prefer onValidationPassed / onValidationFailed on configs for normal flows.

For session setup, weak references, and environment details, use About configuration and Analytics alongside this page.