Skip to content

airwallex/airwallex-risk-ios

Repository files navigation

Airwallex Risk iOS SDK

Bitrise Platforms Swift SPM

The Airwallex Risk SDK is required for Airwallex scale customer apps.

Table of contents

Requirements

  • iOS 13+, macOS 13+, watchOS 7+, tvOS 14+
  • Swift 5.8+

Installation

Swift Package Manager

  • File > Add Packages…
  • Enter package URL https://github.com/airwallex/airwallex-risk-ios
  • Select "Up to Next Major Version"

These instructions may vary slightly for different Xcode versions. If you encounter any problem or have a question about adding the package to an Xcode project, we suggest reading the adding package dependencies to your app guide from Apple.

Usage

Quick start

The SDK must be started as early as possible in your application lifecycle. We recommend adding the start(accountID:with:) method in the application delegate:

import AirwallexRisk

class AppDelegate {

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    Risk.start(
      accountID: "YOUR_ACCOUNT_ID", // Required
      with: AirwallexRiskConfiguration(isProduction: true)
    )
  }
}

Notes:

  • accountID is required in all Airwallex scale customer apps. This will be your Airwallex account ID.
  • the optional AirwallexRiskConfiguration may also be used if needed. For test/debug builds you can set isProduction: false or environment: .staging/.demo. You can also customise the frequency of sending logs by bufferTimeInterval: 5.

Update user

After the app user signs in to their Airwallex account, the app must send the users ID through to the SDK as follows. This will be persisted in the SDK until the next time this method is called. Set to nil on sign out.

⚠️ Important: The user ID here is the signed in user's individual Airwallex account ID, not your own system user ID.

import AirwallexRisk

Risk.set(userID: "USER_ID")

Events

Some app events must be logged to the SDK. These events include:

  • User logs in: When a user logs in, send the event "login". Make sure you set the user ID (above) before sending this event.
  • Create a payout transaction: When a user submits a payment transaction, send the event "payout".

Use the following snippet to send event name and current screen name.

import AirwallexRisk

Risk.log(
  event: "EVENT_NAME",
  screen: "SCREEN_NAME"
)

Request header

When your app sends a request to Airwallex, you must add the provided header into your request before sending. An example implementation follows:

import AirwallexRisk

guard let header = Risk.header else {
  return
}
var request = URLRequest(url: URL(string: "https://www.airwallex.com/...")!)
request.setValue(header.value, forHTTPHeaderField: header.field)

Alternatively, the SDK provides a convenience URLRequest extension method that can be used to directly add the header to any Airwallex request:

import AirwallexRisk

var request = URLRequest(url: URL(string: "https://www.airwallex.com/...")!)
request.setAirwallexHeader()

The header consists of

  • the field, which will always be "x-risk-device-id", and
  • the value, which will be an internally generated device identifier.

Session ID

You can get the unique ID per app running session and provide it into Airwallex requests if needed (optional).

import AirwallexRisk

let sessionID = Risk.SessionID