How begateway/begateway-ios-sdk works
Purpose and Entry Points
This is a Swift 5 iOS SDK, distributed through CocoaPods, for accepting in-app beGateway payments. The public façade is the singleton payment module in begateway/Classes/BeGateway/BeGateway.swift, configured by begateway/Classes/BeGateway/BeGatewayOptions.swift. A runnable host integration is provided by Example/begateway/ViewController.swift and Example/begateway/AppDelegate.swift.
Public Payment Contract
Caller input is modeled as payment request, card, customer, and recipient objects:
• begateway/Classes/BeGateway/BeGatewayRequest.swift
• begateway/Classes/BeGateway/BeGatewayRequestCustomer.swift
• begateway/Classes/BeGateway/BeGatewayRequestRecipient.swift
BeGateway exposes flows for obtaining payment tokens, card payments, card-token payments (including background), generic token payments, and Apple Pay. Results return card metadata through begateway/Classes/BeGateway/BeGatewayCard.swift; transaction state is represented in begateway/Classes/BeGateway/TransactionStruct.swift.
Payment Orchestration and UI
The SDK owns payment collection and presentation rather than requiring a merchant-built form. BeGateway selects and drives controller-based flows, including:
• Card entry: begateway/Classes/BeGateway/Controllers/PaymentViewController.swift
• Saved-card selection: begateway/Classes/BeGateway/Controllers/CardsViewController.swift
• Token-card payment: begateway/Classes/BeGateway/Controllers/PayByCardTokenViewController.swift
• Redirect/3DS-style web content: begateway/Classes/BeGateway/Controllers/WebViewController.swift
Reusable payment-controller behavior is centralized under begateway/Classes/BeGateway/Controllers/template/PaymentBasicViewController.swift. UI views are XIB-backed, creating a boundary between merchant invocation API and SDK-managed payment screens.
Network and Gateway Boundary
The service layer sends checkout/payment requests to the configured beGateway endpoint (default documented as https://checkout.begateway.com/ctp/api; replaceable for white-label PSPs). Its boundary is:
• begateway/Classes/BeGateway/Sources/ServiceApi.swift
• begateway/Classes/BeGateway/Sources/BeGatewaySourceApi.swift
• begateway/Classes/BeGateway/Sources/Models/RequestPaymentV2.swift
Request/response DTOs include checkout creation/status and card storage models under begateway/Classes/BeGateway/Sources/Models/. Control flow is: merchant request → SDK UI or wallet/token collection → API request → response/status checking according to configured delay and retry limits → completion or failure callback.
Card Security, Wallets, and Persistence
Card data can be encrypted before gateway submission via begateway/Classes/BeGateway/Encryption/BGEncryption.swift; an additional standalone encryption source exists at Encryption/BGEncyption.swift. Apple Pay is isolated in begateway/Classes/BeGateway/ApplePaymentModule.swift, bridging Apple’s payment authorization data into the same gateway payment flow. Saved cards are represented by begateway/Classes/BeGateway/Sources/Models/StoreCard.swift and surfaced in the cards UI; the public API supports clearing saved cards.
Presentation, Localization, and Runtime
The SDK targets iOS 11+ and uses UIKit, XIBs, asset catalogs, and Apple Pay entitlement support in the example (Example/begateway_Example.entitlements). Modal/sheet presentation is implemented internally under begateway/Classes/BeGateway/Components/Sheet/SheetViewController.swift and begateway/Classes/BeGateway/Components/Sheet/SheetTransition.swift. Payment text is localized through begateway/Classes/Localization/Localize.swift and language-specific Localizable.strings; card-brand assets are bundled in begateway/Assets/bgresources.xcassets.
Main entry points: PaymentBasicViewController.swift Payment controller base · BeGateway.swift BeGateway · ServiceApi.swift Service API · ViewController.swift Example payment screen
Components 19
Merchant integration
- Example host app · Demonstrates SDK configuration and invocation.
Example/begateway/AppDelegate.swift - Example payment screen
Example/begateway/ViewController.swift
Public SDK contract
- BeGateway options · Supplies gateway endpoint, delay, and retry settings.
begateway/Classes/BeGateway/BeGatewayOptions.swift - BeGateway · Public entry point for token, card, token-card, generic-token, and Apple Pay flows.
begateway/Classes/BeGateway/BeGateway.swift - Payment request · Includes customer and recipient payment inputs.
begateway/Classes/BeGateway/BeGatewayRequest.swift - Card and transaction result
begateway/Classes/BeGateway/BeGatewayCard.swift
SDK payment UI
- Payment controller base · Centralizes reusable payment-controller behavior.
begateway/Classes/BeGateway/Controllers/template/PaymentBasicViewController.swift - Card entry
begateway/Classes/BeGateway/Controllers/PaymentViewController.swift - Saved-card selection
begateway/Classes/BeGateway/Controllers/CardsViewController.swift - Card-token payment
begateway/Classes/BeGateway/Controllers/PayByCardTokenViewController.swift - Redirect / 3DS web flow
begateway/Classes/BeGateway/Controllers/WebViewController.swift - Sheet presentation
begateway/Classes/BeGateway/Components/Sheet/SheetViewController.swift
Gateway transport
- Service API · Creates checkout/payment requests and checks status with configured polling.
begateway/Classes/BeGateway/Sources/ServiceApi.swift - Gateway API client
begateway/Classes/BeGateway/Sources/BeGatewaySourceApi.swift - Payment DTOs · Contains payment, checkout/status, and stored-card gateway models.
begateway/Classes/BeGateway/Sources/Models/RequestPaymentV2.swift - beGateway checkout endpoint · Configured endpoint, replaceable for white-label PSPs.
Security and platform
- Apple Pay module · Converts Apple authorization data into the gateway flow.
begateway/Classes/BeGateway/ApplePaymentModule.swift - Card encryption · Encrypts card data before gateway submission.
begateway/Classes/BeGateway/Encryption/BGEncryption.swift - Localized UI assets · Provides payment text and card-brand assets.
begateway/Classes/Localization/Localize.swift
Connections 23
- Example host app → Example payment screen: hosts
- Example payment screen → BeGateway options: configures
- Example payment screen → BeGateway: invokes
- BeGateway options → BeGateway: configures
- Payment request → BeGateway: input
- BeGateway → Card and transaction result: completion
- BeGateway → Payment controller base: selects flow
- Payment controller base → Card entry: drives
- Payment controller base → Saved-card selection: drives
- Payment controller base → Card-token payment: drives
- Payment controller base → Redirect / 3DS web flow: presents redirect
- Payment controller base → Sheet presentation: presents modally
- Card entry → Card encryption: encrypts card data
- Saved-card selection → Payment DTOs: uses stored cards
- BeGateway → Apple Pay module: routes wallet flow
- Apple Pay module → Service API: submits authorization data
- Card encryption → Service API: protects submission
- Payment controller base → Localized UI assets: renders localized UI
- BeGateway → Service API: token and background flows
- Service API → Payment DTOs: serializes and parses
- Service API → Gateway API client: uses
- Gateway API client → beGateway checkout endpoint: HTTPS checkout requests
- beGateway checkout endpoint → Service API: payment status and result