ComponentCallback
Last updated: December 2, 2026
1/// - Parameters:2/// - onReady: A closure that is triggered when the payment method is ready. Defaults to `nil`.3/// - handleTap: A closure that is used to validate conditions before processing the payment. Useful for handling pre-payment checks like T&C validation. Defaults to `nil`.4/// - onChange: A closure that is triggered when the payment method is changed and any new updates.5/// - onCardBinChanged: A closure that is triggered when the card bin is changed and card metadata is successfully fetched.6/// - onSubmit: A closure that is triggered when the payment method is submitted. Defaults to `nil`.7/// - onAuthorized: A closure that is triggered after the customer authorizes an Apple Pay payment, before it is submitted. Defaults to `nil`.8/// - onTokenized: A closure that is triggered when an item can be tokenized, providing the token details.9/// - handleSubmit: A closure that is used to submit a customized payment session10/// - onSuccess: A closure that is triggered when the payment is successful, passing the payment method and a unique `PaymentId`.11/// - onError: A closure that is triggered when an error occurs during the payment process.1213public init(onReady: (@Sendable (Describable) -> Void)? = nil,14handleTap: (@Sendable (Describable) async -> Bool)? = nil,15onChange: (@Sendable (any Describable & Tokenizable & Submittable) -> Void)? = nil,16onCardBinChanged: (@Sendable (CardMetadata) -> CallbackResult)? = nil,17onSubmit: (@Sendable (Describable) -> Void)? = nil,18onAuthorized: (@Sendable (WalletAuthorization) -> CallbackResult)? = nil,19onTokenized: (@Sendable (TokenizationResult) -> CallbackResult)? = nil,20handleSubmit: (@Sendable (SessionData) async -> APICallResult)? = nil,21onSuccess: (@Sendable (Describable, PaymentID) -> Void)? = nil,22onError: (@Sendable (CheckoutComponents.Error) -> Void)? = nil)
Triggered when a component is initialized and is ready for the customer to interact with.
Describable is the payment method that triggered the event.
1let callbacks = CheckoutComponents.Callbacks(onReady: { paymentMethod in2// Hide loading overlay3hideLoadingOverlay();4}56let configuration = CheckoutComponents.Configuration(callbacks: callbacks)
Triggered when you or the customer trigger a component submission.
Describable is the payment method that triggered the event.
1let callbacks = CheckoutComponents.Callbacks(onSubmit: { paymentMethod in2// Show loading overlay to prevent further user interaction3showLoadingOverlay();4}56let configuration = CheckoutComponents.Configuration(callbacks: callbacks)
Triggered when the payment has been synchronously or asynchronously completed. For example, after a successful 3DS authentication.
The callback contains the following payment information:
Describable– The payment method component that triggered the eventPaymentID– The payment's unique identifier
1let callbacks = CheckoutComponents.Callbacks(onSuccess: { paymentMethod, paymentID in2// Payment with ID: paymentID has gone through successfully3}45let configuration = CheckoutComponents.Configuration(callbacks: callbacks)
Triggered when an error occurs. See the CheckoutError reference for more information.
Describable is the payment method component that triggered the event.
1let callbacks = CheckoutComponents.Callbacks(onError: { error in2switch error.errorCode {3case .paymentRequestDeclined:4showErrorMessage("Payment could not be processed. Please try again.")5default:6showErrorMessage("An error occurred") // Or refine more specific error strings for different error codes7}8}9)1011let configuration = CheckoutComponents.Configuration(callbacks: callbacks)
Triggered when the customer selects a payment button.
You can use this to perform checks before beginning the payment process.
1handleTap: { paymentMethod async -> Bool in2return isTermsAndConditionsAccepted(for: paymentMethod)3}
Triggered when a supported PaymentMethodComponent item is tokenized and provides the TokenizationResult object.
- type – The name of the payment method that triggered the tokenization. Always set this to
card. - data – The card tokenization response.
- cardMetadata – An optional Card metadata lookup response object included when you receive a card metadata API response during customer input.
- preferredScheme – The customer's preferred payment scheme when multiple schemes are supported for the card. For example, Visa and Cartes Bancaires. This can be
nilif no preference is selected, or if the scheme choice was not offered. - storeForFutureUse – The customer's save-card consent choice, exposed only while the save-card consent checkbox is shown.
truewhen the customer checked the checkbox,falsewhen they left it unchecked, andnilwhen no consent was collected. - risk – The Risk data collected for the token. It contains
deviceSessionId, the Risk device session ID. This isnilunless you setcardConfiguration.includeRiskDataInTokenizationtotrue, and alsonilwhen Risk data could not be collected, for example because it timed out.
Tip
When storeForFutureUse is present, forward it as source.store_for_future_use on your payment request. Sending nothing means the card is not stored, regardless of what the customer chose.
Whether the consent checkbox displays, and what storeForFutureUse reports, depends on the session value of store_payment_details on the card payment method:
| Session value of store_payment_details | Consent checkbox shown? | storeForFutureUse |
|---|---|---|
| Yes |
|
| No. Remember Me collects consent through its own flow. |
|
| No. The backend forces storage on. |
|
| No. The backend forces storage off. |
|
Note
If your payment session request omits customer.email, the backend silently downgrades store_payment_details: collect_consent to disabled. If you are not seeing the consent checkbox, check your session request before troubleshooting your integration.
To receive risk, set cardConfiguration.includeRiskDataInTokenization to true in your component options. The onTokenized callback for a newly entered card then waits for the Risk data, for up to 5 seconds, before it triggers. If the Risk data cannot be collected in that time, the callback still triggers and risk is nil. Tokenization does not fail. Tokens for saved cards do not include Risk data.
Tip
When risk is not nil, forward risk.deviceSessionId as risk.device_session_id in your payment request.
Flow for mobile accepts the card if you do not provide the callback. Additionally, depending on your preferred action, you can provide the corresponding object:
- Accept the card –
return .accepted - Reject the card –
return .reject(message: "Error message")
If you reject the card, you can display a custom error message using the optional errorMessage object.
Note
If you attempt to tokenize an unsupported Tokenizable item, the onError() callback triggers instead.
1onTokenized: { tokenizationResult in2if tokenizationResult.data.cardType == "CREDIT" {3return .rejected(message: "Credit cards are not accepted.")4}5return .accepted6}7)89let configuration = CheckoutComponents.Configuration(..., callbacks: callbacks)
Triggered when a component's inputs change after a customer interaction.
Note
If you attempt to submit an unsupported Submittable component, you'll trigger the onError() callback.
Note
The component handed to this callback is a snapshot of the component's state, not the live component. To tokenize, call tokenize() on the component instance itself, not on the value received here.
1let callbacks = CheckoutComponents.Callbacks(onTokenized: { tokenizationResult in2handleToken(tokenizationResult.data) // Or use other token details for your own fraud checks3})4let configuration = CheckoutComponents.Configuration(..., callbacks: callbacks)
Raised when the customer inputs or changes the first eight digits of a card.
You can use this event to perform checks on a card based on its metadata or to observe changes to the bank identification number (BIN).
The CardMetadata object contains the Card Metadata lookup response.
Flow for mobile accepts the card if you do not provide the callback. Additionally, depending on your preferred action, you can provide the corresponding object:
- Accept the card –
return .accepted - Reject the card –
return .rejected(message: "Error message")
If you reject the card, you can display a custom error message using the optional errorMessage object.
1let callbacks = CheckoutComponents.Callbacks(2onCardBinChanged: { cardMetadata in3// Reject credit cards4if cardMetadata.cardType == "credit" {5return .rejected(message: "Credit cards are not accepted.")6}7// Otherwise, allow the payment to proceed8return .accepted9}10)1112let configuration = CheckoutComponents.Configuration(..., callbacks: callbacks)
Raised after the customer authorizes an Apple Pay payment, before Flow for mobile submits it.
Use this event to check the card the customer selected in the Apple Pay sheet. For example, to refuse credit cards or a specific card scheme.
The WalletAuthorization object contains the card details Apple Pay provides. Each property is an optional string:
displayName– The card description shown in the Apple Pay sheet. For example,Visa 1234.scheme– The card network as reported by Apple Pay. For example,Visa,MasterCard, orAmEx. This is Apple's own value, so it can differ from theschemeinCardMetadata.cardType– The card funding type that the SDK forwards from Apple Pay. For example,credit,debit,prepaid,store, oreMoney. It'sunknownwhen Apple Pay does not report a type, andnilfor a value this version of the SDK does not recognize.
Flow for mobile accepts the payment if you do not provide the callback. Additionally, depending on your preferred action, you can provide the corresponding object:
- Accept the payment –
return .accepted - Reject the payment –
return .rejected(message: "Error message")
If you reject the payment:
- Flow for mobile does not submit the payment.
- The Apple Pay sheet stays open and prompts the customer to try a different card. The customer can select another card or close the sheet.
- Flow for mobile displays your message below the Apple Pay button. If you do not provide a message, it displays Payment declined – try again or use another payment method.
onErroris not called. If the customer then closes the Apple Pay sheet,onErroris called withpaymentCancelled.
Information
Base your decision on the WalletAuthorization object and avoid network requests in the callback. The callback is synchronous, meaning the Apple Pay sheet waits for the result.
1let callbacks = CheckoutComponents.Callbacks(2onAuthorized: { authorization in3// Reject credit cards4if authorization.cardType == "credit" {5return .rejected(message: "Credit cards are not accepted.")6}7// Otherwise, allow the payment to proceed8return .accepted9}10)1112let configuration = CheckoutComponents.Configuration(..., callbacks: callbacks)
You can use this callback to submit a customized payment, using the Submit a Payment Session endpoint.
If no callback is provided, the payment is processed as normal, and Flow for mobile sends the request.
The SubmitData object contains session_data, which is a unique token representing the additional customer data that Flow for mobile captured. You must provide this token when you submit the customized payment session request.
You must provide the unmodified response body returned by the endpoint.
1let callbacks = CheckoutComponents.Callbacks(2handleSubmit: { sessionData in3submitPaymentSession(sessionData)4}5)67let configuration = CheckoutComponents.Configuration(..., callbacks: callbacks)