Using the iOS SDK

This topic provides the information about how to use the iOS SDK.

Installation

In your Xcode project, go to "General" tab -> "Project Overview" page -> "Embedded Binaries" section. Place NetspendSdk.framework file there. This allows NetspendSdk.framework to be available to the application at runtime.

Initialization

Initialize the Netspend SDK on application start in order to allow for external assets to be downloaded and cached without the user perceiving additional delays when micro-apps are launched. As part of initialization, the theme and branding information needs to be set in order to make the micro-apps blend seamlessly within your mobile app.

import NetspendSdk

// Once per app life-cycle, typically in AppDelegate didFinishLaunching:withOptions
NetspendSdk.shared.initialize(
  // The SDK ID for your integration given from Netspend. This is not a secret value.
  sdkID: String, // Use NS-PIT:C-ABCDEF when integrating with the sandbox environment.
  // The theme configuration
  theme: NetspendSdkTheme
  // Branding configuration, see each micro-app for details
  branding: Dictionary<String, Any>
  // Required iovation token for NetspendSDK iovation plugin
  iovationToken: String // FraudForce.blackbox()
)

Customization covers theme and branding in depth.

Establishing a Session

To establish user sessions, create a user session connection object with the user_session_initialization_data that is retrieved from the API when your server creates an access token.

let userSessionConnection = NetspendSdk.shared.createUserSessionConnection(
    // `user_session_initialization_data` from your server
    userSessionInitializationData: user_session_initialization_data
    // iovation token using Fraudforce lib
    iovationToken: FraudForce.blackbox()
)

let device_data = userSessionConnection.deviceData

/// Send device_data to your server to create a user session
/// Then, from the response of creating the user session on the server, use
// the field `encrypted_data` to create the final user session

let session = userSessionConnection.createUserSession(
    // `encrypted_data` from the response of creating a user session
    userSessionEncryptedData: encrypted_data
)

For more information on user_session_initialization_data and creating user sessions, see Netspend API Reference: Sessions.

Using a Session

Once a session is created, it can be used to decrypt data from the Netspend API or encrypt data to be sent from the Netspend API.

Encrypting

Below is a sample code for encrypting data.

let session: NetspendSdkUserSession

do {
    let encryptedData = session.encrypt(value: [
        "some": "dictionary",
        "that_matches": "api documentation"
    ])
} catch NetspendSdkUserSessionError.encryptFailure {
    // Failure!
}

For more information on encrypting data, see Netspend API Reference: Sessions.

Decrypting

Below is a sample code for decrypting data.

do {
    let decryptedDictionary = session.decrypt(value: encryptedData)

    let value = decryptedDictionary["some_key_from_netspend_api_documentation"]
} catch NetspendSdkUserSessionError.decryptFailure {
    // Failure!
}

For more information on decrypting the encrypted data, see Netspend API Reference: Sessions.