IOS SDK
The Accrue Savings IOS SDK is available as a package for your company to integrate the Accrue Wallet.
It simplifies the integration by combining the Wallet lifecycle and deep linking into a single package.
Installation
Your package is available as a Swift Package Manager package.
The repository URL is https://github.com/accrue-savings/ios-sdk
Swift Package Manager
To add the Accrue Savings SDK to your Xcode project, select File
> Swift Packages
> Add Package Dependency
and enter the repository URL.
Usage
Here is an example of how to embed the widget in a IOS (swift) application:
import SwiftUI
import AccrueIosSDK
import WebKit
struct ContentView: View {
@StateObject private var contextData = AccrueContextData(
userData: AccrueUserData(
// A unique reference id for the user
referenceId: "yourReferenceId",
// User email
email: "email@example.com",
// User US phone number
phoneNumber: "+12125559999"
),
// Optional settings data
settingsData: AccrueSettingsData(
// Should the widget inherit the authentication from the parent app
shouldInheritAuthentication: true
)
)
var body: some View {
AccrueWallet(
// Merchant Id provided by Accrue
merchantId: "yourMerchantId",
// Redirection token for deep linking
redirectionToken: "yourRedirectionToken",
// Sandbox mode
isSandbox: true,
// Context data to be attached to the user profile stored with Accrue
contextData: contextData,
// Callback with actions triggered by the user
onAction: handleOnAction
)
}
// Callback function to handle user actions
func handleOnAction(action: String) {
print("action with data: \(action)")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Props
The following props are available for the AccrueWallet
component:
merchantId | |
Required | Yes |
Type | String |
Description | Merchant ID (received from Accrue) |
Default | N/A |
Example | 724a57f2-1670-42de-b1f0-a94425fb60cf |
redirectionToken | |
Required | No |
Type | String |
Description | Redirection token for the deep linking. This token will be used to redirect the user to a specific screen within the Accrue Savings Widget |
Default | nil |
Example | 61a77652-14ae-4ed4-9bb3-cdb31312869e |
isSandbox | |
Required | No |
Type | Bool |
Description | Flag to enable the sandbox mode. If set to true, the widget will use the sandbox environment |
Default | true |
Example | true |
contextData | |
Required | yes |
Type | ContextData(userData: AccrueUserData, settingsData: AccrueSettingsData) |
Description | Your own user data to be attached to the user profile stored with Accrue |
Default | nil |
Example | ContextData(userData: AccrueUserData(), settingsData: AccrueSettingsData()) |
onAction | |
Required | No |
Type | ((String) -> Void)? |
Description | Callback with actions triggered by the user |
Default | nil |
Example | { print("action with data: (action)") } |
ContextData
The ContextData
struct is used to pass the user data and settings data to the widget.
AccrueUserData
The AccrueUserData
struct is used to pass the user data to the widget. The following fields are available:
referenceId | |
Required | Yes |
Type | String |
Description | A unique reference id for the user |
Default | N/A |
Example | 123e4567-e89b-12d3-a456-426614174000 |
email | |
Required | No |
Type | String |
Description | User email |
Default | N/A |
Example | email@example.com |
phoneNumber | |
Required | Yes |
Type | String |
Description | User US phone number |
Default | N/A |
Example | +12125559999 |
AccrueSettingsData
The AccrueSettingsData
struct is used to pass the settings data to the widget. The following fields are available:
shouldInheritAuthentication | |
Required | No |
Type | Bool |
Description | Should the widget inherit the authentication from the parent app |
Default | true |
Example | true |
⚠️ Important: Keep in mind that the
shouldInheritAuthentication
will change the behavior of the widget.
The following UX changes will occur:
- We will use the
phoneNumber
passed as props to auto-send the OTP to the user if not already authenticated on the widget. - We will use the
referenceId
passed as the authentication state (on merchant side). If present, we will consider the user as authenticated. Otherwise, we will consider the user as unauthenticated. - Once user confirms the OTP, we will consider the user as authenticated on the widget.
- If
referenceId
changes, the user will be logged out from the widget.
Considerations:
- The user would not be able to change the phone number in the widget.
- The user would not be able to logout from the widget (unless the
referenceId
changes). - The user would not be able to change the email in the widget.
- All
phoneNumber/email
changes should be handled on the merchant side.
Actions
Actions are emitted from the webview in the form of a string. The onAction
callback will be triggered with the action string as a parameter.
The following actions are available:
AccrueWallet::SignInButtonClicked
: The user clicked the sign-in buttonAccrueWallet::RegisterButtonClicked
: The user clicked the register button
The string will contain the action key and any additional data in the following format:
{
"action": "AccrueWallet::SignInButtonClicked",
"data": {}
}