iOS SDK using a Mobile Reader
Initialize the Stax iOS SDK in your app so you can prepare to accept mobile-reader payments.
This developer guide covers SDK installation and initialization for iOS apps.
Prerequisites
Create an ephemeral token (a temporary authentication credential) on your backend to initialize the Omni object. Keep your long-term API key on your server, not in your mobile app. Follow Ephemeral Authentication Tokens to request a token.
Find your server-side API key in Stax Pay > Apps > API Keys. For this example, ask your Account Manager for development credentials compatible with Environment.DEV; do not assume a Dashboard sandbox key uses the DEV environment.
Then, you’ll create a TransactionRequest that holds all the necessary data to take a payment.
Finally, you’ll ask Omni to take the payment by calling the takeMobileReaderPayment() method, passing in the TransactionRequest and a block to run once the payment is complete.
Requirements
- Target iOS 13 or later.
- Obtain an ephemeral token from your backend for the environment you will initialize.
Setting up your Mobile Reader
Installation
Use CocoaPods to install the Fattmerchant iOS SDK.
- Install CocoaPods.
- Add
pod 'Fattmerchant'to your existingPodfileinside your app's target. - Run
pod installfrom the directory containing yourPodfile, then open the generated.xcworkspacein Xcode. A successful installation makesimport Fattmerchantavailable in your app target.
- Add these entries inside the existing root
<dict>in your app'sInfo.plistto support payments with a physical card reader:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Bluetooth access lets this app connect to your card reader to accept payments.</string>
<key>UISupportedExternalAccessoryProtocols</key>
<array>
<string>com.idtechproducts.neo</string>
</array>Note: UISupportedExternalAccessoryProtocols:com.idtechproducts.neo is required for VP3550 mobile readers. You can omit this line if you are not using the IDTech VP3550 mobile reader.
Initialize
-
Add the following initialization function to a Swift file in your app target. It creates
Omni.InitParamsand passes the parameters toOmni.initialize(...), with completion and error callbacks.Use
Environment.DEVfor development with matching credentials. Switch toEnvironment.LIVEonly when you intentionally prepare for live processing with the corresponding credentials.
import Foundation
import Fattmerchant
func initializeStax(appId: String, ephemeralToken: String) -> Omni? {
guard !appId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
print("Initialization not started: provide a nonempty app ID.")
return nil
}
guard !ephemeralToken.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
print("Initialization not started: obtain an ephemeral token from your backend.")
return nil
}
// appId identifies your application, not a merchant or transaction.
// The SDK's official example uses "com.example.app"; confirm your value with Stax.
// Obtain ephemeralToken from your backend, not from the Dashboard.
// Keep the backend's API key in Stax Pay > Apps > API Keys out of this app.
let initParams = Omni.InitParams(
appId: appId,
apiKey: ephemeralToken,
environment: Environment.DEV
)
let omni = Omni()
print("Attempting initialization...")
omni.initialize(params: initParams, completion: {
print("Stax SDK initialized successfully.")
}) { _ in
// Avoid logging credentials or sensitive SDK error details.
print("Stax SDK initialization failed. Check token validity, environment, and connectivity before retrying.")
}
return omni
}-
Call
initializeStax(appId:ephemeralToken:)after your backend supplies a valid development token, passing your application's identifier and that token. Retain the returnedOmniinstance in your app and wait for the completion callback before using it for reader operations. Returning an instance does not mean asynchronous initialization has succeeded.The
appIdargument is an application identifier, not a Stax resource ID such as a merchant or transaction ID. The official SDK example usescom.example.app; confirm the accepted identifier for your integration with your Account Manager rather than substituting a merchant ID. Do not use example strings as authentication credentials.
Successful initialization prints:
Attempting initialization...
Stax SDK initialized successfully.If either argument is empty, the function prints an explanation, returns nil, and does not initialize the SDK. If asynchronous initialization fails, the error callback prints Stax SDK initialization failed. Check token validity, environment, and connectivity before retrying. Obtain a fresh token from your backend, verify that it matches Environment.DEV, and check your connection before retrying. Do not start reader operations after a failure.
RequiredApple requires information about the software/hardware of systems using their payment system. Please contact your Account Manager so we can add your device and software to acceptable applications. Please provide:
- Version & Build Number
- Bundle ID
- Name of the app on the store
- Short description of your application
Updated 4 days ago
