Initialisation

Before you execute an operation with the Zettle SDK, it must be initialised, and the user must be authorised. Initialisation and authorisation are done through the same APIs, using an object that conforms to the iZettleSDKAuthorizationProvider protocol.

This protocol defines a set of methods for authorizing Zettle users inside your application. The Zettle SDK implements this protocol out-of-the-box through an iZettleSDKAuthorization object.

User authorisation in the SDK is performed through the implementation of OAuth 2.0. A Client ID and a callback URL from your integrating application is required for this.

To get a Client ID, go to the Zettle Developer Portal and create an account. Then create an iOS SDK developer application. Once you complete that process, you'll be given a Client ID which can be used to initialise the SDK.

1
let authenticationProvider = try iZettleSDKAuthorization(
2
clientID: "xxx-xxx-xxx-xxx",
3
callbackURL: URL(string: "app-scheme://url"))
4
5
iZettleSDK.shared().start(with: authenticationProvider)

Initialise the SDK using token-based authorisation

User authorisation is most often done through the provided user interface. However, if you have an access token and a refresh token, you will be able to authorise the users through the token-based authorisation process. You can use the proof key for code exchange (PKCE) flow to get the required tokens. See OAuth PKCE method.

Note: There will be no log out option for merchants in the Settings view when using the token-based authorization.

The following example shows how to add support for token-based authorisation.

1
/// Step 1. Create a class that implements the iZettleSDKAuthorizationProvider protocol.
2
3
class YourCustomAuthClass: iZettleSDKAuthorizationProvider {
4
5
///Step 2. Provide implementation of the `authorizeAccountWithCompletion` method.
6
func authorizeAccount(completion: @escaping iZettleAuthorizationCompletion) {
7
let token =...
8
completion(token, nil)
9
}
10
11
///Step 3. Provide implementation of the `verifyAccountWithUuid` method. This is used when triggering refunds.
12
func verifyAccount(uuid: UUID, completion: @escaping iZettleAuthorizationCompletion) {
13
let token =...
14
completion(token, nil)
15
}
16
}

See also this custom authorisation provider example.