Requirements
- iOS 16 or higher
- Swift 5.9+
- SwiftUI
Installation
Add the Benny SDK as a Swift Package Manager dependency in Xcode:- Go to File > Add Package Dependencies.
- Enter the repository URL:
https://github.com/Benny-API/benny-mobile-sdk - Select the
BennySDKlibrary product.
Package.swift
import BennySDK gives you access to all SDK types—no additional imports required.
Initialize the SDK
CallBennySDK.initialize() once at app startup, before rendering any SDK components. Your App.init() is the recommended place.
Your Benny organization ID.
.sandbox for testing, .production for live transactions.Card Tokenization
TheCardNumberInput view renders a secure card number field. Card data never touches your servers—it’s tokenized directly by the SDK.
How it works
- Create a
CardNumberInputControlleras a@StateObject, passing the session token from your backend. - Place
CardNumberInputin your view. It renders a secure text field for the card number. - Call
controller.tokenize()when the user is ready to submit. - On success,
onSuccessreceives a PAN token ID (string) that you can send to your backend.
Callbacks
| Callback | Type | Description |
|---|---|---|
onLoadingChange | (Bool) -> Void | Called with true when a request starts and false when it completes. |
onError | (String?) -> Void | Called with an error message on failure, or nil to clear a previous error. |
onSuccess | (String) -> Void | Called with the PAN token ID on successful tokenization. |
PIN entry and EBT operations
ThePinInput view renders a secure PIN field for EBT balance checks and payments.
How it works
- Create a
PinInputControlleras a@StateObject, passing the session token. - Place
PinInputin your view. It renders a secure numeric field for the PIN. - Call
controller.submit()with the PAN token ID (from card tokenization) and anEbtOperation. - On success,
onSuccessreceives anEbtResultwith the account balances.
EBT operations
| Operation | Usage |
|---|---|
EbtOperation.BalanceCheck() | Check the cardholder’s EBT balance. |
EbtOperation.Payment(paymentIntentId:) | Execute an EBT payment against a payment intent created on your backend. |
EBT result
UseonEnum(of:) to pattern-match on the result:
The SDK returns balance amounts as integers in cents. Divide by 100 to display dollar amounts.
The
onEnum(of:) helper enables exhaustive switch statements on Kotlin sealed classes in Swift.Styling
BothCardNumberInput and PinInput are standard SwiftUI views, so you can apply any SwiftUI view modifiers to control their appearance.
Common styling patterns
| Modifier | Description |
|---|---|
.frame(height:) | Set a fixed height. |
.padding(...) | Add internal padding around the input. |
.background(...) | Set the background color. |
.cornerRadius(...) | Round the container corners. |
.overlay(...) | Add a border using a RoundedRectangle stroke. |
The secure input field inside the component has its own internal text styling. View modifiers control the container around the input.