# begateway/begateway-ios-sdk architecture

> Architecture diagram of the GitHub repository begateway/begateway-ios-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/begateway/begateway-ios-sdk
- Repository: https://github.com/begateway/begateway-ios-sdk

## Overview

#### 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: [`begateway/Classes/BeGateway/Controllers/template/PaymentBasicViewController.swift`](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/template/PaymentBasicViewController.swift) (Payment controller base), [`begateway/Classes/BeGateway/BeGateway.swift`](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGateway.swift) (BeGateway), [`begateway/Classes/BeGateway/Sources/ServiceApi.swift`](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Sources/ServiceApi.swift) (Service API), [`Example/begateway/ViewController.swift`](https://github.com/begateway/begateway-ios-sdk/blob/master/Example/begateway/ViewController.swift) (Example payment screen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_merchant["Merchant integration"]
  node_example_app["Example host app<br/>iOS host app<br/>[AppDelegate.swift]"]
  node_example_controller["Example payment screen<br/>integration controller"]
end

subgraph group_public["Public SDK contract"]
  node_options["BeGateway options<br/>configuration"]
  node_sdk_facade{{"BeGateway<br/>singleton façade<br/>[BeGateway.swift]"}}
  node_payment_request["Payment request<br/>public request model"]
  node_payment_result["Card and transaction result<br/>public result models"]
end

subgraph group_ui["SDK payment UI"]
  node_payment_controllers["Payment controller base<br/>UI flow base"]
  node_card_entry["Card entry<br/>payment screen"]
  node_saved_cards["Saved-card selection<br/>payment screen"]
  node_token_card["Card-token payment<br/>payment screen"]
  node_redirect_web["Redirect / 3DS web flow<br/>web payment screen"]
  node_sheet_presentation["Sheet presentation<br/>modal presentation"]
end

subgraph group_gateway["Gateway transport"]
  node_service_api["Service API<br/>gateway service<br/>[ServiceApi.swift]"]
  node_source_api["Gateway API client<br/>transport client"]
  node_payment_dto["Payment DTOs<br/>request and response models"]
  node_gateway_endpoint(("beGateway checkout endpoint<br/>external payment gateway"))
end

subgraph group_platform["Security and platform"]
  node_apple_pay["Apple Pay module<br/>wallet bridge"]
  node_encryption{{"Card encryption<br/>security boundary<br/>[BGEncryption.swift]"}}
  node_localization_assets["Localized UI assets<br/>resources<br/>[Localize.swift]"]
end

node_example_app -->|"hosts"| node_example_controller
node_example_controller -->|"configures"| node_options
node_example_controller -->|"invokes"| node_sdk_facade
node_options -->|"configures"| node_sdk_facade
node_payment_request -->|"input"| node_sdk_facade
node_sdk_facade -->|"completion"| node_payment_result
node_sdk_facade -->|"selects flow"| node_payment_controllers
node_payment_controllers -->|"drives"| node_card_entry
node_payment_controllers -->|"drives"| node_saved_cards
node_payment_controllers -->|"drives"| node_token_card
node_payment_controllers -->|"presents redirect"| node_redirect_web
node_payment_controllers -->|"presents modally"| node_sheet_presentation
node_card_entry -->|"encrypts card data"| node_encryption
node_saved_cards -->|"uses stored cards"| node_payment_dto
node_sdk_facade -->|"routes wallet flow"| node_apple_pay
node_apple_pay -->|"submits authorization data"| node_service_api
node_encryption -->|"protects submission"| node_service_api
node_payment_controllers -->|"renders localized UI"| node_localization_assets
node_sdk_facade -->|"token and background flows"| node_service_api
node_service_api -->|"serializes and parses"| node_payment_dto
node_service_api -->|"uses"| node_source_api
node_source_api -->|"HTTPS checkout requests"| node_gateway_endpoint
node_gateway_endpoint -.->|"payment status and result"| node_service_api

click node_example_app "https://github.com/begateway/begateway-ios-sdk/blob/master/Example/begateway/AppDelegate.swift"
click node_example_controller "https://github.com/begateway/begateway-ios-sdk/blob/master/Example/begateway/ViewController.swift"
click node_options "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGatewayOptions.swift"
click node_sdk_facade "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGateway.swift"
click node_payment_request "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGatewayRequest.swift"
click node_payment_result "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGatewayCard.swift"
click node_payment_controllers "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/template/PaymentBasicViewController.swift"
click node_card_entry "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/PaymentViewController.swift"
click node_saved_cards "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/CardsViewController.swift"
click node_token_card "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/PayByCardTokenViewController.swift"
click node_redirect_web "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/WebViewController.swift"
click node_sheet_presentation "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Components/Sheet/SheetViewController.swift"
click node_apple_pay "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/ApplePaymentModule.swift"
click node_encryption "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Encryption/BGEncryption.swift"
click node_localization_assets "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/Localization/Localize.swift"
click node_service_api "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Sources/ServiceApi.swift"
click node_source_api "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Sources/BeGatewaySourceApi.swift"
click node_payment_dto "https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Sources/Models/RequestPaymentV2.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_example_app,node_example_controller toneBlue
class node_options,node_sdk_facade,node_payment_request,node_payment_result toneAmber
class node_payment_controllers,node_card_entry,node_saved_cards,node_token_card,node_redirect_web,node_sheet_presentation toneMint
class node_service_api,node_source_api,node_payment_dto,node_gateway_endpoint toneRose
class node_apple_pay,node_encryption,node_localization_assets toneIndigo
```

## Components

### Merchant integration

- [Example host app](https://github.com/begateway/begateway-ios-sdk/blob/master/Example/begateway/AppDelegate.swift): iOS host app · Demonstrates SDK configuration and invocation. · `Example/begateway/AppDelegate.swift`
- [Example payment screen](https://github.com/begateway/begateway-ios-sdk/blob/master/Example/begateway/ViewController.swift): integration controller · `Example/begateway/ViewController.swift`

### Public SDK contract

- [BeGateway options](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGatewayOptions.swift): configuration · Supplies gateway endpoint, delay, and retry settings. · `begateway/Classes/BeGateway/BeGatewayOptions.swift`
- [BeGateway](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGateway.swift): singleton façade · Public entry point for token, card, token-card, generic-token, and Apple Pay flows. · `begateway/Classes/BeGateway/BeGateway.swift`
- [Payment request](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGatewayRequest.swift): public request model · Includes customer and recipient payment inputs. · `begateway/Classes/BeGateway/BeGatewayRequest.swift`
- [Card and transaction result](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/BeGatewayCard.swift): public result models · `begateway/Classes/BeGateway/BeGatewayCard.swift`

### SDK payment UI

- [Payment controller base](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/template/PaymentBasicViewController.swift): UI flow base · Centralizes reusable payment-controller behavior. · `begateway/Classes/BeGateway/Controllers/template/PaymentBasicViewController.swift`
- [Card entry](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/PaymentViewController.swift): payment screen · `begateway/Classes/BeGateway/Controllers/PaymentViewController.swift`
- [Saved-card selection](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/CardsViewController.swift): payment screen · `begateway/Classes/BeGateway/Controllers/CardsViewController.swift`
- [Card-token payment](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/PayByCardTokenViewController.swift): payment screen · `begateway/Classes/BeGateway/Controllers/PayByCardTokenViewController.swift`
- [Redirect / 3DS web flow](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Controllers/WebViewController.swift): web payment screen · `begateway/Classes/BeGateway/Controllers/WebViewController.swift`
- [Sheet presentation](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Components/Sheet/SheetViewController.swift): modal presentation · `begateway/Classes/BeGateway/Components/Sheet/SheetViewController.swift`

### Gateway transport

- [Service API](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Sources/ServiceApi.swift): gateway service · Creates checkout/payment requests and checks status with configured polling. · `begateway/Classes/BeGateway/Sources/ServiceApi.swift`
- [Gateway API client](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Sources/BeGatewaySourceApi.swift): transport client · `begateway/Classes/BeGateway/Sources/BeGatewaySourceApi.swift`
- [Payment DTOs](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Sources/Models/RequestPaymentV2.swift): request and response models · Contains payment, checkout/status, and stored-card gateway models. · `begateway/Classes/BeGateway/Sources/Models/RequestPaymentV2.swift`
- **beGateway checkout endpoint**: external payment gateway · Configured endpoint, replaceable for white-label PSPs.

### Security and platform

- [Apple Pay module](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/ApplePaymentModule.swift): wallet bridge · Converts Apple authorization data into the gateway flow. · `begateway/Classes/BeGateway/ApplePaymentModule.swift`
- [Card encryption](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/BeGateway/Encryption/BGEncryption.swift): security boundary · Encrypts card data before gateway submission. · `begateway/Classes/BeGateway/Encryption/BGEncryption.swift`
- [Localized UI assets](https://github.com/begateway/begateway-ios-sdk/blob/master/begateway/Classes/Localization/Localize.swift): resources · Provides payment text and card-brand assets. · `begateway/Classes/Localization/Localize.swift`

## Connections

- 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
