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.
- 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.
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.
1let authenticationProvider = try iZettleSDKAuthorization(2clientID: "xxx-xxx-xxx-xxx",3callbackURL: URL(string: "app-scheme://url")!45iZettleSDK.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.
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:
Make sure that you have set up a PKCE flow.
Include the following code in
AppDelegate
. The code implements theiZettleSDKAuthorizationProvider
protocol and gets tokens from the PKCE flow.
1/// Step 1. Create a class that implements the iZettleSDKAuthorizationProvider protocol.23class YourCustomAuthClass: iZettleSDKAuthorizationProvider {45///Step 2. Provide implementation of the `authorizeAccountWithCompletion` method.6func authorizeAccount(completion: @escaping iZettleAuthorizationCompletion) {7let token =...8completion(token, nil)9}1011///Step 3. Provide implementation of the `verifyAccountWithUuid` method. This is used when triggering refunds.12func verifyAccount(uuid: UUID, completion: @escaping iZettleAuthorizationCompletion) {13let token =...14completion(token, nil)15}16}
For an example of initialising the SDK for custom login, see the custom authorisation in the example iOS SDK.
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
1var enforcedAccount = { "name@zettle.com" }23let authenticationProvider = try iZettleSDKAuthorization(4clientID: "xxx-xxx-xxx-xxx",5callbackURL: URL(string: "app-scheme://url")!,6enforcedAccount: enforcedAccount)78iZettleSDK.shared().start(with: authenticationProvider)
The enforced account will be evaluated for each authenticated operation performed in the SDK.