Initialisation

Initialise the iOS SDK at application launch to make sure that it is properly configured at the time of the first payment. In order to do so, you should initialise the integration in your AppDelegate's function application(_:didFinishLaunchingWithOptions:).

Note: An integration needs to be initialised only once in its lifecycle.

The initialisation uses an instance that implements the iZettleSDKAuthorizationProvider protocol. This protocol defines a set of methods for authorizing Zettle users inside your application.

When an integration is initialised, user authentication and authorisation for the integration is also initialised through the same APIs. User authorisation in the SDK is performed through the implementation of OAuth 2.0.

Prerequisite

  • The OAuth redirect URI that is used to create app credentials on the Zettle Developer Portal.
  • The client ID that is part of the created app credentials, see Get started.
  • If you want to use a custom login, make sure that you have set up authorisation code grant with PKCE.

Initialise SDK for default login

The SDK provides a default login interface for your application users. The default login uses a built-in iZettleSDKAuthorization instance that implements the iZettleSDKAuthorizationProvider protocol for user authentication and authorisation.

To use the default login, initialise the SDK for the default login by include the following code when you initialise the integration.

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)

Note: The callbackURL must be the OAuth redirect URI that is used to create app credentials on the Zettle Developer Portal.

Initialise SDK for custom login

Instead of using the default login, you can use a custom login for your application users. However, instead of using the built-in iZettleSDKAuthorization instance, you need to set up a proof key for code exchange (PKCE) flow and implement the iZettleSDKAuthorizationProvider protocol for user authentication and authorisation.

For more information about the PKCE flow, see Set up authorisation code grant with PKCE.

Note: If a custom login is used, there is no logout option for users in the Settings view.

To initialise SDK for a custom login:

  1. Make sure that you have set up a PKCE flow.

  2. Include the following code in AppDelegate. The code implements the iZettleSDKAuthorizationProvider protocol and gets tokens from the PKCE flow.

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
}

For an example of initialising the SDK for custom login, see the custom authorisation in the example iOS SDK.

Initialise SDK for specific user accounts

If you want the SDK integration to be used by specific user accounts, you need to initialise the SDK only for them.

For example, if you want the integration to be used by only one user account, initialise the SDK only for that account. After the initialisation, only that account can log in and use the SDK integration.

The following example shows how to allow the SDK to be used by a specific Zettle account.

Swift

1
var enforcedAccount = { "name@zettle.com" }
2
3
let authenticationProvider = try iZettleSDKAuthorization(
4
clientID: "xxx-xxx-xxx-xxx",
5
callbackURL: URL(string: "app-scheme://url")!,
6
enforcedAccount: enforcedAccount)
7
8
iZettleSDK.shared().start(with: authenticationProvider)

The enforced account will be evaluated for each authenticated operation performed in the SDK.

Next step