Getting Started on iOS
Introduction
The Software Development Kit for iOS is a dynamic framework with a simple set of tools that allow you to easily communicate with the Paysafe Wallet API. The SDK is written in Swift.
Requirements
- iOS 14.3
- Swift 5.7
Installation
Manually
PaysafeWallet SDK can be integrated into your project manually.
- Contact Paysafe for latest artifacts.
- Extract downloaded zip files and copy PaysafeWallet.xcframework, TMXProfiling.xcframework and TMXProfilingConnections.xcframework to your project directory.
- Open your Xcode project and drag copied xcframeworks inside.
- Select your application project in the Project Navigator (blue project icon), then select your app's target under Targets section.
- Open General panel, scroll to Frameworks, Libraries & Embedded Content and expand it.
- Make sure all three frameworks are added there, if not add them with the
+
button and selectEmbed & Sign
in Embed column.
Usage
All wallet operations are provided via the Wallet
singleton:
import PaysafeWallet
let wallet = Wallet.instance
Configure SDK
In order to use the SDK, you need to configure it, configuration will be stored as long as you application is
not terminated. This is done by calling the configure
method of the Wallet
instance with a configuration token. Mind
that configure
is async operation and needs to be waited to complete.
// issue a <config-token> from your backend server
let configuration = Wallet.Configuration(configToken: "<config-token>", /* the config token you have received from your backend server */
apiEnvironment: .production) /* set to .production or .test to direct API calls to the appropriate environment */
let configurationResult = try await wallet.configure(with: configuration)
// Request user token using configurationResult.digitalFingerprint
// or using completion block
wallet.configure(with: configuration, completion: { result in
switch result {
case .success(let configurationResult):
// Request user token using configurationResult.digitalFingerprint
case .failure(let error):
// Handle error
}
})
The configuration token is issued from your backend server. The steps to generate it are explained in SDK Configuration.
Authenticate User
To ensure secure access to customer data by the SDK, it is necessary to provide a customer token. Customer tokens
exclusively permit access to resources linked to the specific customer for whom the token was generated. Call the
authenticate
method of the Wallet
instance to set the customer token:
// issue a <customer-token> from your backend server, passing configureResult.digitalFingerprint
let authConfiguration = Wallet.AuthenticationConfiguration(accessToken: "<customer-token>")
wallet.authenticate(with: authConfiguration)
The customer token is issued from your backend server passing the digitalFingerprint
value from the configuration result.
More details on getting the customer token are available in SDK User Authentication.
Wallet Operations
Once Configure and Authenticate are performed, you can start using the SDK for wallet operations.
let customerInfo = try await wallet.profileService.getProfile(include: [])
// or using completion block
wallet.profileService.getProfile(include: [], completion: { result in
switch result {
case .success(let customerInfo):
// Display customer information
case .failure(let error):
// Handle error
}
})
UI Appearance configuration
Appearance for the UI elements provided by the SDK can be customized completely or partially by creating Appearance
object,
modifying its properties and applying it to Wallet.instance
.
var appearance = Appearance.defaultAppearance
appearance.cornerRadius = Appearance.CornerRadius(small: 1, medium: 4, large: 8)
appearance.fonts = Appearance.Fonts(text1: UIFont.italicSystemFont(ofSize: 14),
text2: UIFont.boldSystemFont(ofSize: 14))
appearance.colors.background.base = .lightGray
Wallet.instance.setAppearance(appearance)
Appearance should be configured once before using any UI provided by the SDK.
Objective-C support
Objective-C is not supported and SDK functionality can not be accessed using Objective-C.
Swift concurrency
All SDK operations have async variants that can be used when async context is available.