Quick Start
The PayBito iOS Payment SDK is the official high-performance SDK designed for seamless mobile checkout integration. Built on Apple's modern reactive architectures, it helps merchants easily incorporate the PayBito Secure Checkout into their native iOS environments.
Key Features
Dynamic UI Branding
Silently communicates with the PayBito broker API to fetch custom Merchant Colors (Hex) and perfectly brands the iOS Shopping Cart to match the merchant's identity.
Reactive Cart Engine
Built with Apple's Combine framework, the CartManager automatically calculates totals and updates the UI whenever items are added or removed.
Strict Thread Safety
Fully compliant with Swift 6 and strict concurrency rules. All UI updates are securely locked to the @MainActor to prevent race conditions.
Deep-Link Interception
Seamlessly intercepts web-portal success and cancellation callbacks directly back into native Swift delegates.
Graceful Fallbacks
Detailed @ViewBuilder error handling that displays diagnostic UIs for missing credentials instead of crashing the host application.
Installation
Integrating the PayBito iOS Payment SDK is straightforward. Below are the requirements and standard installation procedures.
System Requirements
Minimum OS
iOS 17.0+
Swift Compiler
Swift 5.9+
Swift Package Manager (Recommended)
You can easily integrate the SDK into your project via Swift Package Manager:
Open Package Search
Open your project in Xcode. Go to File > Add Package Dependencies...
Specify Repository URL
Paste the following repository URL into the search bar:
https://github.com/hashcashconsultant/PaybitoSDK.git
Define Dependency Rule
Set the Dependency Rule to "Up to Next Major Version" starting from version 1.0.0 and click Add Package.
SDK Initialization
Initialize the SDK once during your app's startup phase (e.g., in your custom AppDelegate class or the root layout's @main struct in SwiftUI). This prepares the config instance to communicate and cache custom Broker UI branding values.
import PayBitoSDK
let config = PaymentConfiguration(
merchantId: "YOUR_MERCHANT_ID",
publicKey: "pk_your_public_key",
brokerId: "YOUR_BROKER_ID",
origin: "https://portal.paybito.com/payments/merchant/",
enableDebugLogs: true
)
PayBito.initialize(configuration: config)
initialize() function, the SDK automatically connects with the PayBito broker API in the background to fetch and cache your custom broker UI branding.Cart Management
The CartManager provided by the SDK is a globally accessible, thread-safe, and highly reactive component that automatically calculates totals and updates the UI whenever updates happen.
A. Adding Items to the Cart
The CartManager handles concurrency internally. Simply instantiate a product and call the helper from anywhere:
let product = PayBitoProduct(
productId: "P001",
name: "4K Monitor",
price: 399.50,
imageUrl: "https://example.com/monitor.jpg"
)
// Safely add items to the cart from anywhere in your app!
PayBito.addToCart(product)
B. Observing Cart State (Reactive)
Observe the cart state dynamically in SwiftUI to reflect the badge counts or cart details on the fly:
@ObservedObject private var cartManager = PayBito.shared.cartManager
// In the view builder layout...
if cartManager.count > 0 {
Text("\(cartManager.count)")
.font(.caption)
.foregroundColor(.white)
.padding(6)
.background(Color.red)
.clipShape(Circle())
}
C. Updating Quantity
Easily increment or decrement existing quantities inside the shopping cart using the product ID:
// Update quantity (e.g. triggered from plus/minus buttons)
cartManager.updateQuantity(productId: product.productId, newQuantity: newQuantity)
D. Displaying the Checkout Cart
Natively present the user's shopping cart UI by wrapping the SDK's view builder structure inside a standard sheet modifier:
.sheet(isPresented: $isShowingCart) {
PayBito.openCart()
}
Secure Checkout & Backend Token Sync
For strict security reasons, mobile apps should **never** directly generate checkout session tokens using the CLIENT-SECRET-KEY. The Secret Key must remain isolated on your backend infrastructure.
The Token Generation Flow
Launching Checkout Portal
Once you securely retrieve the checkout session token from your server, initiate checkout via the SDK checkout delegate interface:
// Safely launch the Secure Payment Portal
PayBito.checkout(token: "PCN-GENERATED-TOKEN")
Deep-Link Configuration
To support automatic success and cancellation callbacks from the secure checkout portal back into your native app, you must register a custom URL scheme in Xcode.
Xcode Scheme Registration Steps
Open Target Info
Open your project target settings in Xcode and select the Info tab.
Add URL Type
Navigate to the URL Types section at the bottom, and click the + button to add a new scheme mapping.
Configure Scheme
Set the Identifier fields to match your app, and set the URL Schemes field to precisely paybito.
paybito://checkout/success) and handles dismissing the checkout View controller automatically.TechStore Demo App Guide
The TechStore Demo App serves as a reference implementation for integrating the PayBito Payment SDK into an iOS application using SwiftUI. Below are the key views showing its complete implementation.
Core Implementation Flow
SDK Initialization on Main View Appear
In the demo app, the configuration setup is run when the primary SwiftUI view appears:
.onAppear {
let config = PaymentConfiguration(
merchantId: "26660L",
publicKey: "pk_test_...",
brokerId: "ARNA...", // Merchant's Broker ID for custom UI branding
origin: "https://portal.paybito.com/payments/merchant/",
enableDebugLogs: true
)
PayBito.initialize(configuration: config)
}
Checkout Interception via NotificationCenter
When the checkout triggers from the built-in cart sheet, the host app listens for the launch notification to initiate token validation:
let checkoutPublisher = NotificationCenter.default.publisher(for: NSNotification.Name("PayBitoSDK_LaunchCheckout"))
// Listen in the SwiftUI body modifiers:
.onReceive(checkoutPublisher) { _ in
fetchCheckoutToken()
}
Display Checkout View Portal
Bind isShowingCheckout sheet to launch the WebView portal once the checkout token is retrieved:
.sheet(isPresented: $isShowingCheckout) {
PayBito.checkout(token: checkoutToken)
}
Observe Payment Success Notification
The host app handles redirection callback notices to clean cart resources and render the success confirmation panel:
let successPublisher = NotificationCenter.default.publisher(for: NSNotification.Name("PayBitoSDK_PaymentSuccess"))
.onReceive(successPublisher) { _ in
withAnimation {
showSuccessScreen = true
}
}
FAQ & Security Requirements
Review key answers regarding secure token architectures, common setup questions, and developer checklist.
Security Checklist
Keep Secret Keys Off-Device
Never embed or log your CLIENT-SECRET-KEY inside files included in the application bundle. Use secure APIs on your backend to handle token generation requests.
Observe MainActor Constraints
Ensure custom delegates or cart observer bindings execute within the Swift 6 `@MainActor` thread scope to prevent layout rendering warnings or threading exceptions.
Setup Valid Callback Schemes
Configure scheme paybito inside Xcode info URL Types to prevent web portal workflows hanging after successful payment execution.
Frequently Asked Questions
Generating session tokens requires your client secret key. Storing secret keys in mobile source code leaves them vulnerable to extraction via reverse-engineering tools. Performing token generation on a secure server protects your private keys.
When initialized with a broker ID, the SDK calls the PayBito configuration service to download custom branding assets (e.g., custom colors). The native SwiftUI bottom cart UI uses these downloaded variables to customize buttons, totals, and badge elements dynamically.
The checkout WebView handles standard redirects. When it intercepts a URL prefix match matching the registered scheme `paybito://checkout/success`, the web engine triggers a closure callback to close the view controller instance natively and posts a success notification.
Yes. CartManager is designed with Combine publishers that conform to Swift 6 strict concurrency directives. All internal write operations are serialized, and observations are safely locked to the `@MainActor` thread.

