Skip to main content

Installation and initialization

Adding the library to your project

The library is distributed as a Swift Package. Add it to your project using Swift Package Manager.

Xcode

  1. In Xcode, open File → Add Package Dependencies…
  2. Enter the repository URL: https://github.com/comgate-payments/ios-checkout-sdk
  3. Choose a version and the target you want to add the library to.
  4. Once added, import the library in your source files:
import ComgateSDK

Package.swift

If you are using your own Swift Package, add the dependency like this:

dependencies: [
.package(url: "https://github.com/comgate-payments/ios-checkout-sdk", from: "0.1.0")
],
targets: [
.target(
name: "MyApp",
dependencies: [
.product(name: "ComgateSDK", package: "ComgateSDK")
]
)
]
Warning

The library requires iOS 15.0 or later. Verify that your application's configuration meets this requirement (Deployment Target in the target settings).

Project configuration

Apple Pay capability

If you plan to use Apple Pay, you must:

  1. In Xcode, on the Signing & Capabilities tab, add the Apple Pay capability.
  2. Select (or create) all Merchant IDs you will use — typically one for sandbox and one for production.
  3. In the Apple Developer portal (Identifiers → Merchant IDs), register the corresponding merchant identifier with the format merchant.<your-domain>.

The list of allowed merchant identifiers will appear in your entitlements file:

<key>com.apple.developer.in-app-payments</key>
<array>
<string>merchant.cz.example.production</string>
<string>merchant.cz.example.sandbox</string>
</array>

For full Apple Pay configuration details, see Apple Pay.

Third-party keyboards

Third-party keyboards may, in theory, intercept entered characters. For maximum protection of card data, we recommend disabling third-party keyboards in your AppDelegate:

Tip
func application(
_ application: UIApplication,
shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier
) -> Bool {
extensionPointIdentifier != .keyboard
}

Creating session

The ComgateSecureSession class is the main entry point for working with the library. The session handles:

  • internal security initialization,
  • 3D Secure initialization,
  • card and Apple Pay payment processing.

Constructor parameters

ParameterTypeRequiredDescription
checkoutIdStringCheckout SDK connection identifier. Obtain it in the Comgate client portal.
threeDSConfigThreeDSConfig3D Secure configuration (UI, timeout, protocol version). See Card data — 3D Secure.
devModeBoolEnables development/testing mode. Default false.
applePayMerchantIdentifierString?Apple Pay Merchant ID in merchant.* format. Required for Apple Pay. When nil, Apple Pay is disabled.
applePayDisplayNameString?Merchant display name shown in the Apple Pay payment sheet.
translationTranslationTranslations for component texts. Default .forCurrentLocale().
langString?Language code (BCP 47 / ISO 639-1) sent with the payment request (e.g. "cs", "en"). When omitted, the device language is used (if supported).
Information

Network infrastructure and communication are managed internally by the library. With a standard integration, no additional setup is required.

Initialization

The recommended approach is to create the session as a @StateObject in your top-level App or root View and call initialize() asynchronously from the .task modifier:

import SwiftUI
import ComgateSDK

@main
struct MyApp: App {
@StateObject private var session = ComgateSecureSession(
checkoutId: "your-checkout-id",
threeDSConfig: ThreeDSConfig() // default 3DS configuration
)

var body: some Scene {
WindowGroup {
ContentView(session: session)
.task {
do {
try await session.initialize()
} catch {
print("Init failed: \(error)")
}
}
}
}
}
Information

The initialize() method is async throws and runs on the main thread (@MainActor). On failure it throws a ComgateException carrying the specific ComgateError.

Session state (SessionState)

ComgateSecureSession exposes a @Published property state of type SessionState that describes the current lifecycle phase of the session at any point. For simple checks, the isInitialized property is provided.

States

StateWhen it applies
.notInitializedSession has just been created. initialize() has not been called yet.
.initializinginitialize() is in progress — network communication and 3DS SDK initialization are running.
.readyInitialization completed successfully. The session is ready to process payments.
.failed(ComgateError)Initialization failed. The associated value carries the specific cause. The session can be re-initialized by calling initialize() again.

Session properties

PropertyTypeDescription
stateSessionStateCurrent session state (@Published).
isInitializedBoolShortcut: true if and only if state == .ready.
isApplePayConfiguredBooltrue when applePayMerchantIdentifier was supplied and Apple Pay is available.
isProcessingPaymentBooltrue while processPayment(...) or processApplePayPayment(...) is in flight.
translationTranslationTranslations of the current session (read-only).

Use in UI (SwiftUI)

struct ContentView: View {
@ObservedObject var session: ComgateSecureSession

var body: some View {
switch session.state {
case .notInitialized:
Button("Initialize") {
Task { try? await session.initialize() }
}
case .initializing:
ProgressView()
case .ready:
PaymentForm(session: session)
case .failed(let error):
VStack {
Text("Initialization error: \(error.message)")
Button("Retry") {
Task { try? await session.initialize() }
}
}
}
}
}

Initialization errors

The .failed(error) state carries a ComgateError describing the cause. The most common initialization errors:

ErrorCodeDescription
.deviceRootedDEVICE_ROOTEDDevice appears to be jailbroken or otherwise tampered with. Initialization is blocked to protect card data. The check is skipped in devMode.
.initNetworkErrorINIT_NETWORK_ERRORNetwork error while loading configuration.
.initUnauthorizedINIT_UNAUTHORIZEDServer returned HTTP 401 during initialization — invalid or expired authorization.
.initFailedINIT_FAILEDInitialization failed for another reason (e.g. invalid server response).
.applicationNotAllowedAPPLICATION_NOT_ALLOWEDThe app's Bundle ID is not on the allow-list of applications.
Information

The state property is published via Combine (@Published) and all updates happen on the main thread. The state can be observed via .onReceive(session.$state) or directly within a SwiftUI body.

Translations (localization)

Component texts can be localized via Translation.

  • Translations are passed to ComgateSecureSession through the translation parameter
  • You can use a built-in preset, automatic device-language detection, or a custom Translation instance
  • The following keys are user-overridable:
KeyDescription
panLabelLabel above the card-number (PAN) field.
expiryLabelLabel above the expiry-date field.
cvvLabelLabel above the CVV field.
fullNameLabelLabel above the cardholder-name field.
panHintPlaceholder text in the card-number (PAN) field.
expiryHintPlaceholder text in the expiry-date field (e.g. MM/YY).
cvvHintPlaceholder text in the CVV field.
fullNameHintPlaceholder text in the cardholder-name field.
panInvalidErrorError message displayed under the PAN field when the card number is invalid.
expiryInvalidMonthErrorError message displayed under the expiry field when the month is invalid.
expiryExpiredErrorError message displayed under the expiry field when the card has expired.
fullNameRequiredErrorError message displayed under the name field when the field is empty.
payButtonTextPay-button text in the idle (active) state.
payButtonProcessingTextPay-button text while a payment is being processed.
statusPaidMessage shown in SecurePaymentStatusView for a successful payment.
statusAuthorizedMessage shown in SecurePaymentStatusView for an authorized payment (preauthorization).
statusPendingMessage shown in SecurePaymentStatusView while a payment is awaiting its final status.
loadingProcessingTextText shown in SecureLoadingView while a payment is being processed.
threeDSCancelButtonCancel-button text in the 3D Secure verification dialog.

Currently available translations

TranslationValue
EnglishTranslation.english
BulgarianTranslation.bulgarian
CzechTranslation.czech
DanishTranslation.danish
EstonianTranslation.estonian
FinnishTranslation.finnish
FrenchTranslation.french
CroatianTranslation.croatian
ItalianTranslation.italian
LithuanianTranslation.lithuanian
LatvianTranslation.latvian
HungarianTranslation.hungarian
GermanTranslation.german
DutchTranslation.dutch
NorwegianTranslation.norwegian
PolishTranslation.polish
PortugueseTranslation.portuguese
RomanianTranslation.romanian
RussianTranslation.russian
GreekTranslation.greek
SlovakTranslation.slovak
SlovenianTranslation.slovenian
SpanishTranslation.spanish
SwedishTranslation.swedish
UkrainianTranslation.ukrainian
VietnameseTranslation.vietnamese
let translation = Translation(
panLabel: "Card number",
expiryLabel: "Expiry",
cvvLabel: "CVC/CVV",
fullNameLabel: "Cardholder name",
panHint: "Card number",
expiryHint: "MM/YY",
cvvHint: "CVV",
fullNameHint: "First and last name",
panInvalidError: "Invalid card number",
expiryInvalidMonthError: "Invalid month",
expiryExpiredError: "Card has expired",
fullNameRequiredError: "Cardholder name is required",
payButtonText: "Pay",
payButtonProcessingText: "Processing…",
statusPaid: "Paid",
statusAuthorized: "Authorized",
statusPending: "Pending",
loadingProcessingText: "Processing payment…",
threeDSCancelButton: "Cancel"
)

let session = ComgateSecureSession(
checkoutId: "your-checkout-id",
threeDSConfig: ThreeDSConfig(),
translation: translation
)

Example with a built-in translation:

let session = ComgateSecureSession(
checkoutId: "your-checkout-id",
threeDSConfig: ThreeDSConfig(),
translation: .english
)

Supported language codes

ComgateSecureSession.supportedLanguageCodes returns an alphabetically sorted list of BCP 47 / ISO 639-1 language codes for which the library has built-in translations. This list can be used to populate a language picker in your UI or to check whether the device language is supported.

Currently available codes: bg, cs, da, de, el, en, es, et, fi, fr, hr, hu, it, lt, lv, nl, no, pl, pt, ro, ru, sk, sl, sv, uk, vi

Example — automatic device-language detection with a fallback to English:

let deviceLang = Locale.current.language.languageCode?.identifier ?? "en"
let resolvedLang = ComgateSecureSession.supportedLanguageCodes.contains(deviceLang) ? deviceLang : "en"

let session = ComgateSecureSession(
checkoutId: "your-checkout-id",
threeDSConfig: ThreeDSConfig(),
translation: .forLanguageCode(resolvedLang),
lang: resolvedLang
)

Example — populating a language picker and wiring it to translations:

// Get the list of supported codes
let languageCodes = ComgateSecureSession.supportedLanguageCodes

// After the user picks a language
let selectedCode = "sk"
let translation = Translation.forLanguageCode(selectedCode)