PayBito Payments
iOS SDK Guide

Integrate seamless crypto & fiat payments into your iOS app using our professional-grade SDK built with Combine and SwiftUI.

v1.0.0 — Stable Release

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:

1
Open Package Search

Open your project in Xcode. Go to File > Add Package Dependencies...

2
Specify Repository URL

Paste the following repository URL into the search bar:

SPM URL
https://github.com/hashcashconsultant/PaybitoSDK.git
3
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.

Swift
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)
Dynamic Branding: Upon calling the 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:

Swift
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:

SwiftUI
@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:

Swift
// 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:

SwiftUI
.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:

Swift
// Safely launch the Secure Payment Portal
PayBito.checkout(token: "PCN-GENERATED-TOKEN")
Warning: Always verify that token requests occur over secure HTTPS connections with server verification enabled on your backend requests.

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

1
Open Target Info

Open your project target settings in Xcode and select the Info tab.

2
Add URL Type

Navigate to the URL Types section at the bottom, and click the + button to add a new scheme mapping.

3
Configure Scheme

Set the Identifier fields to match your app, and set the URL Schemes field to precisely paybito.

Auto-Dismissal: The SDK automatically intercepts completion redirects (such as 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.

TechStore Products Grid
Products Grid
TechStore Cart Sheet
Branded Cart Sheet
Secure Checkout portal
Secure Checkout Portal
Payment Success Screen
Payment Success Screen

Core Implementation Flow

1
SDK Initialization on Main View Appear

In the demo app, the configuration setup is run when the primary SwiftUI view appears:

SwiftUI
.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)
}
2
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:

SwiftUI
let checkoutPublisher = NotificationCenter.default.publisher(for: NSNotification.Name("PayBitoSDK_LaunchCheckout"))

// Listen in the SwiftUI body modifiers:
.onReceive(checkoutPublisher) { _ in
    fetchCheckoutToken()
}
3
Display Checkout View Portal

Bind isShowingCheckout sheet to launch the WebView portal once the checkout token is retrieved:

SwiftUI
.sheet(isPresented: $isShowingCheckout) {
    PayBito.checkout(token: checkoutToken)
}
4
Observe Payment Success Notification

The host app handles redirection callback notices to clean cart resources and render the success confirmation panel:

SwiftUI
let successPublisher = NotificationCenter.default.publisher(for: NSNotification.Name("PayBitoSDK_PaymentSuccess"))

.onReceive(successPublisher) { _ in
    withAnimation {
        showSuccessScreen = true
    }
}
Simulator Fallback: If the local simulation backend returns errors (due to invalid API configurations), the demo app gracefully falls back to a hardcoded testing token to allow frontend validation without crashing.

FAQ & Security Requirements

Review key answers regarding secure token architectures, common setup questions, and developer checklist.

Security Checklist
1
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.

2
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.

3
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

Why does the SDK require a backend server for token generation?

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.

What does "Dynamic UI Branding" do under the hood?

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.

How does the deep link auto-dismiss the WebView?

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.

Is CartManager thread-safe?

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.

Contents

paybito logo

Download the Mobile Apps

Contact Us

  (Max 120 Character)
  (Max 500 Character)
By checking this box, you agree to receive SMS messages from PayBitoPro. Reply STOP to opt out at any time. Reply HELP for customer care contact information. Message and data rates may apply. Message frequency may vary. Phone numbers collected for SMS consent will not be shared with third parties or affiliates for marketing purposes under any circumstance. Check out our Privacy Policy to learn more.

BitcoinBTC/USD

Ether CoinETH/USD

HCX CoinHCX/USD

BCH CoinBCH/USD

LitecoinLTC/USD

EOS CoinEOS/USD

ADA CoinADA/USD

Link CoinLINK/USD

BAT CoinBAT/USD

HBAR CoinHBAR/USD

+
Chat Now
Welcome to Paybito Support