Skip to content

comgate-payments/ios-checkout-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ComgateSDK for iOS

Native iOS SDK for accepting card and Apple Pay payments through the Comgate payment gateway, with built-in 3-D Secure 2.x support.

Requirements

  • iOS 15.0+
  • Xcode 15.0+
  • Swift 5.9+

Installation

Swift Package Manager

In Xcode, choose File → Add Package Dependencies… and enter the repository URL:

https://github.com/comgate-payments/ios-checkout-sdk.git

Or add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/comgate-payments/ios-checkout-sdk.git", from: "0.1.0")
]

The product ComgateSDK re-exports the bundled binary dependencies; you do not need to declare them separately.

Quickstart

import SwiftUI
import ComgateSDK

@main
struct DemoApp: App {
    @StateObject private var session = ComgateSecureSession(
        checkoutId: "<YOUR_CHECKOUT_ID>",
        applePayMerchantIdentifier: "merchant.<your.identifier>",
        applePayDisplayName: "<Your Store>",
        threeDSConfig: ThreeDSConfig(
            uiCustomization: ThreeDSUiCustomization(
                toolbarStyle: ThreeDSToolbarStyle(headerText: "<Your Store>")
            ),
            challengeTimeoutMinutes: 5
        ),
        translation: .forCurrentLocale()
    )

    var body: some Scene {
        WindowGroup {
            PaymentScreen(session: session)
                .task {
                    if case .notInitialized = session.state {
                        try? await session.initialize()
                    }
                }
        }
    }
}

@MainActor
final class CollectorHolder: ObservableObject {
    let collector: SecureCardDataCollector
    init(pan: SecurePanFieldState, expiry: SecureExpiryFieldState, cvv: SecureCvvFieldState) {
        self.collector = secureCardDataCollector(pan: pan, expiry: expiry, cvv: cvv)
    }
}

struct PaymentScreen: View {
    @ObservedObject var session: ComgateSecureSession

    @StateObject private var panState: SecurePanFieldState
    @StateObject private var expiryState: SecureExpiryFieldState
    @StateObject private var cvvState: SecureCvvFieldState
    @StateObject private var nameState: SecureFullNameFieldState
    @StateObject private var statusState = PaymentStatusState()
    @StateObject private var holder: CollectorHolder

    init(session: ComgateSecureSession) {
        self._session = ObservedObject(wrappedValue: session)
        let pan = SecurePanFieldState()
        let expiry = SecureExpiryFieldState()
        let cvv = SecureCvvFieldState()
        let name = SecureFullNameFieldState()
        _panState = StateObject(wrappedValue: pan)
        _expiryState = StateObject(wrappedValue: expiry)
        _cvvState = StateObject(wrappedValue: cvv)
        _nameState = StateObject(wrappedValue: name)
        _holder = StateObject(wrappedValue: CollectorHolder(pan: pan, expiry: expiry, cvv: cvv))
    }

    private var collector: SecureCardDataCollector { holder.collector }

    private func params() -> PaymentParams {
        try! PaymentParams(
            email: "buyer@example.com",
            price: 100,
            curr: "CZK",
            country: "CZ",
            label: "Order #1",
            refId: "order-1"
        )
    }

    private func handle(_ result: PaymentResult) {
        statusState.translation = session.translation
        statusState.show(result: result)
    }

    var body: some View {
        ScrollView {
            VStack(spacing: 12) {
                SecureFullNameField(state: nameState)
                SecurePanField(state: panState)
                SecureExpiryField(state: expiryState)
                SecureCvvField(state: cvvState)

                SecurePayButton(
                    session: session,
                    collector: collector,
                    paymentParams: params,
                    onResult: handle
                )

                SecureApplePayButton(
                    session: session,
                    paymentParams: params,
                    onResult: handle
                )

                SecurePaymentStatusView(state: statusState)
            }
            .padding(.horizontal, 20)
            .padding(.top, 60)
        }
        .onAppear {
            panState.translation = session.translation
            expiryState.translation = session.translation
            cvvState.translation = session.translation
            nameState.translation = session.translation
            nameState.attachTo(session)
        }
        .onDisappear { nameState.detachFrom(session) }
        .secureLoadingOverlay(session: session)
    }
}

SwiftUI components used above

  • SecurePanField, SecureExpiryField, SecureCvvField, SecureFullNameField — card data input fields.
  • SecurePayButton — submits the card payment.
  • SecureApplePayButton — submits the Apple Pay payment.
  • SecurePaymentStatusView — payment outcome display.
  • .secureLoadingOverlay(session:) — progress indicator.

Host app configuration

Disable third-party keyboards in your UIApplicationDelegate to ensure card fields cannot be intercepted:

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

For Apple Pay, add the com.apple.developer.in-app-payments entitlement with your merchant identifier.

Localization

The SDK includes localized strings for the following languages:

Bulgarian, Croatian, Czech, Danish, Dutch, English, Estonian, Finnish, French, German, Greek, Hungarian, Italian, Latvian, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian, Slovak, Slovenian, Spanish, Swedish, Ukrainian, Vietnamese.

Bundled third-party components

Component License
ThreeDSSDK Redistributed with permission of the vendor.
CryptoSwift MIT — Copyright © 2014 Marcin Krzyżanowski.

License

See LICENSE.

Security

To report a security issue, see SECURITY.md. Do not open public issues for security reports.

Changelog

See CHANGELOG.md.

Contact

podpora@comgate.cz

About

Native iOS SDK for accepting card and Apple Pay payments through the Comgate payment gateway, with built-in 3-D Secure 2.x support. Distributed via Swift Package Manager.

https://comgate.cz

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages