The main entry point for displaying the payment sheet in your iOS app. Initialize PaymentAction once in your view controller, then call paymentSheet(style:) or bankPaymentSheet() to create a sheet and present(from:paymentSheet:animated:) to display it modally.
On successful tokenization, the delegate's didSucceed method is called with either a TokenizedResponse (plain tokenization) or a PaymentSheetResponse (preferred, exposes 3DS results).
Initializer
PaymentAction(
credentials: FinixCredentials,
delegate: PaymentActionDelegate,
configuration: PaymentInputController.Configuration? = nil
)| Parameter | Type | Required | Description |
|---|---|---|---|
credentials | FinixCredentials | Yes | Your Finix Application ID and environment. See FinixCredentials below. |
delegate | PaymentActionDelegate | Yes | Receives tokenization success and failure callbacks. See PaymentActionDelegate below. |
configuration | PaymentInputController.Configuration? | No | Customize branding, sheet title, button label, card scanning, and 3DS. See Configuration. |
FinixCredentials
FinixCredentials(
applicationId: String,
environment: FinixAPIEndpoint
)| Property | Type | Description |
|---|---|---|
applicationId | String | Your Finix Application ID, found in the Finix Dashboard. |
environment | FinixAPIEndpoint | .Sandbox for testing, .Live for live payments. |
Application IDs are environment-specific. Use the one that matches your chosen environment value.
environment
Controls which Finix environment the SDK connects to.
| Value | Environment |
|---|---|
.Sandbox | Sandbox |
.Live | Production |
Your applicationId must belong to the same environment.
PaymentActionDelegate
Implement PaymentActionDelegate to receive tokenization results. The protocol exposes two optional success callbacks and two required failure/cancel callbacks:
@objc public protocol PaymentActionDelegate {
@objc optional func didSucceed(paymentController: PaymentInputController, response: PaymentSheetResponse)
@objc optional func didSucceed(paymentController: PaymentInputController, instrument: TokenizedResponse)
@objc func didCancel(paymentController: PaymentInputController)
@objc func didFail(paymentController: PaymentInputController, error: Error)
}| Method | Trigger | Receives |
|---|---|---|
didSucceed(paymentController:response:) | Successful tokenization. Preferred. | PaymentSheetResponse wrapping the token and (when 3DS ran) the 3DS result. |
didSucceed(paymentController:instrument:) | Successful tokenization. Legacy (no 3DS access). | TokenizedResponse |
didCancel(paymentController:) | User dismissed the sheet | (none) |
didFail(paymentController:error:) | Tokenization failed | Error |
Pick the success callback that fits your flow. For plain tokenization, either callback works. When 3D Secure is enabled, use the response: variant so you can read response.threeDSResponse. The token itself does not carry the 3DS result.
After didSucceed, forward the token ID to your backend and call the Finix API to create a Payment Instrument. If 3DS ran, forward response.threeDSResponse?.sessionId alongside the token. See ThreeDSResponse.
When ThreeDSConfiguration is set on Configuration and 3D Secure authentication fails, didFail(paymentController:error:) is called with a FinixError. The token itself may have been created, but the host app should not proceed with the payment. There's no liability shift when 3DS fails.
Inspect (error as? FinixError)?.code to branch on the failure mode.
FinixError.Code (3DS cases)
public struct FinixError: Error {
public let code: FinixError.Code
public let message: String
public let logref: String?
public enum Code {
// ... non-3DS cases omitted ...
// 3D Secure
case ThreeDSSessionCreationFailed
case ThreeDSChallengeFailed
case ThreeDSAuthenticationFailed
case ThreeDSTimeout
case ThreeDSCancelled
case ThreeDSInvalidRedirect
case ThreeDSResultRetrievalFailed
case ThreeDSConfigurationMissing
case ThreeDSInvalidConfiguration
}
}| Code | Meaning |
|---|---|
ThreeDSSessionCreationFailed | The call to /3d_secure_sessions did not return a usable session. Usually a credentials or network issue. |
ThreeDSChallengeFailed | The challenge WKWebView could not complete the issuer's challenge flow (for example, failed to load the challenge URL). |
ThreeDSAuthenticationFailed | The issuer completed authentication and reported a failure. No liability shift. |
ThreeDSTimeout | The 5-minute challenge window elapsed without a terminal state. Commonly caused by a missing CFBundleURLSchemes entry. See URL scheme registration. |
ThreeDSCancelled | The buyer dismissed the challenge sheet. |
ThreeDSInvalidRedirect | The redirect URL received from the challenge page does not match the configured redirectScheme. |
ThreeDSResultRetrievalFailed | Session reached a terminal state but the SDK could not fetch the final authentication result. |
ThreeDSConfigurationMissing | 3DS was triggered without a ThreeDSConfiguration on Configuration. |
ThreeDSInvalidConfiguration | The provided ThreeDSConfiguration is missing required fields (for example, an empty redirectScheme). |
paymentSheet(style:) / bankPaymentSheet() / present(from:paymentSheet:animated:)
Create a payment sheet for the desired collection type, then present it modally.
For card collection, call paymentSheet(style:) with a Form Style:
let sheet = paymentAction.paymentSheet(style: .complete)
paymentAction.present(from: self, paymentSheet: sheet, animated: true)For bank account (ACH) collection, call bankPaymentSheet():
let bankSheet = paymentAction.bankPaymentSheet()
paymentAction.present(from: self, paymentSheet: bankSheet, animated: true)Full example
A complete implementation with credentials, delegate conformance, and optional configuration.
PaymentAction(
credentials: credentials,
delegate: self,
configuration: configuration
)
// Sandbox
let credentials = FinixCredentials(
applicationId: "APc9vhYcPsRuTSpKD9KpMtPe",
environment: .Sandbox
)
// Production (SDK represents this as .Live)
let credentials = FinixCredentials(
applicationId: "APc9vhYcPsRuTSpKD9KpMtPe",
environment: .Live
)
// Sandbox — use a sandbox Application ID
let credentials = FinixCredentials(
applicationId: "APc9vhYcPsRuTSpKD9KpMtPe",
environment: .Sandbox
)
extension CheckoutViewController: PaymentActionDelegate {
// Preferred success callback. PaymentSheetResponse wraps the token and
// (when 3DS ran) the 3DS result.
@objc func didSucceed(paymentController: PaymentInputController, response: PaymentSheetResponse) {
let tokenId = response.tokenizedResponse.id
print("Token: \(tokenId)")
if let threeDS = response.threeDSResponse {
// 3DS ran — forward the session ID too
print("3DS session: \(threeDS.sessionId)")
}
dismiss(animated: true)
}
@objc func didCancel(paymentController: PaymentInputController) {
dismiss(animated: true)
}
@objc func didFail(paymentController: PaymentInputController, error: Error) {
print("Error: \(error.localizedDescription)")
dismiss(animated: true)
}
}
@objc func didFail(paymentController: PaymentInputController, error: Error) {
guard let code = (error as? FinixError)?.code else {
showError(error); return
}
switch code {
case .ThreeDSTimeout:
// Usually a missing CFBundleURLSchemes entry
showError("3DS timed out — check your Info.plist URL scheme")
case .ThreeDSCancelled:
dismiss(animated: true)
case .ThreeDSAuthenticationFailed,
.ThreeDSSessionCreationFailed,
.ThreeDSChallengeLoadFailed,
.ThreeDSInvalidRedirect,
.ThreeDSResultRetrievalFailed,
.ThreeDSConfigurationMissing,
.ThreeDSInvalidConfiguration:
// Token may exist, but no liability shift — do not charge
showError("3DS failed: \(code)")
default:
showError(error)
}
}
class CheckoutViewController: UIViewController {
var paymentAction: PaymentAction!
// Card payment sheet
func showCardSheet() {
let sheet = paymentAction.paymentSheet(style: .complete)
paymentAction.present(from: self, paymentSheet: sheet, animated: true)
}
// Bank account (ACH) payment sheet
func showBankSheet() {
let bankSheet = paymentAction.bankPaymentSheet()
paymentAction.present(from: self, paymentSheet: bankSheet, animated: true)
}
}
class CheckoutViewController: UIViewController {
var paymentAction: PaymentAction!
override func viewDidLoad() {
super.viewDidLoad()
let credentials = FinixCredentials(
applicationId: "APc9vhYcPsRuTSpKD9KpMtPe",
environment: .Live
)
let config = PaymentInputController.Configuration(
title: "Card Entry",
branding: PaymentInputController.Branding(image: UIImage(named: "MyLogo"), title: "My Company"),
buttonTitle: "Pay Now"
)
paymentAction = PaymentAction(
credentials: credentials,
delegate: self,
configuration: config
)
}
func showPaymentSheet() {
let sheet = paymentAction.paymentSheet(style: .complete)
paymentAction.present(from: self, paymentSheet: sheet, animated: true)
}
}
extension CheckoutViewController: PaymentActionDelegate {
@objc func didSucceed(paymentController: PaymentInputController, response: PaymentSheetResponse) {
let tokenId = response.tokenizedResponse.id
print("Token: \(tokenId)")
if let threeDS = response.threeDSResponse {
// 3DS ran — forward the session ID to your backend alongside the token
print("3DS session: \(threeDS.sessionId)")
}
dismiss(animated: true)
}
@objc func didCancel(paymentController: PaymentInputController) {
dismiss(animated: true)
}
@objc func didFail(paymentController: PaymentInputController, error: Error) {
print("Error: \(error.localizedDescription)")
dismiss(animated: true)
}
}