Introduction

Link is Lean’s official SDK that leverages the capabilities of modern browsers and mobile clients, such as asynchronous communication, encryption at REST, transit and much more, while giving you an optimised, customizable, conversion-optimized user journey for your users to connect their accounts.

Link SDK

Lean's iOS SDK is available through Swift Package Manager. To integrate Lean’s Link SDK in XCode go to File > Swift Packages > Add Package Dependency and use the URL below:

https://www.github.com/leantechnologies/link-sdk-ios-distribution

Manual installation can also be achieved by adding the .xcframework available here to your project in XCode.

You can then import the SDK into your swift files.

swift

import LeanSDK

Usage with Swift UI

1. Initalizing

You will need to initalize the LeanSDK within your Swift UI application by calling Lean.manager.setup(appToken, sandbox), version this sets the application token and environment during runtime of your application.

2. Create the View state

You can present a Lean.manager.view anywhere in your application, however for best performance we recommend that it be placed inside a .fullScreenCover and set ignoresSafeArea() so that the view displays in full screen.

3. Call a method

You can now write and attach functions to any UI element using Lean.manager.[method] see Methods section below

4. Handle success and error closures

You can write your own completion blocks upon success and failure of the LinkSDK.

Errors will pass back a LeanStatus dictionary with the following:

{
status: "ERROR",
method: "LINK",
message: "Some message"
}

Swift

// YourApp.Swift
import SwiftUI
import LeanSDK
@main
class LeanTestAppApp: App {
required init() {
Lean.manager.setup(
appToken: "YOUR_APP_TOKEN",
sandbox: true,
version: "1.3.2"
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Swift

// ContentView.swift
import SwiftUI
import LeanSDK
struct ContentView: View {
@State private var isPresented = false
var linkPermissions = [LeanPermission.Identity, LeanPermission.Accounts,
LeanPermission.Transactions, LeanPermission.Balance]
var body: some View {
VStack {
Button("Link", action: { handleLink() })
}
}
.fullScreenCover(isPresented: $isPresented, content: {
Lean.manager.view.ignoresSafeArea()
})
func handleLink() {
Lean.manager
.link(customerId: "CUSTOMER_ID", permissions: linkPermissions, success: {
print("Entity Linked")
isPresented = false
}, error: { (status) in
print(status.status)
print(status.message)
print(status.method)
isPresented = false
})
isPresented = true
}
}

Usage with View Controllers

1. Initalizing

Call Lean.manager.setup(appToken, sandbox, version) during ViewDidLoad - or before attempting to make a call to the SDK.

2. Call a method

You can now write and attach functions to any UI element using Lean.manager.[method] see Methods section below.

Ensure that you set the presentingViewController, to the View Controller that you want the SDK to present within.

3. Handle success and error closures

You can write your own completion blocks upon success and failure of the LinkSDK.

Errors will pass back a LeanStatus dictionary with the following:

{
status: "ERROR",
method: "LINK",
message: "Some message"
}

Swift

// ViewController.swift
import UIKit
import LeanSDK
class ViewController: UIViewController {
var linkPermissions = [LeanPermission.Identity, LeanPermission.Accounts,
LeanPermission.Transactions, LeanPermission.Balance]
override func ViewDidLoad() {
super.viewDidLoad()
Lean.manager.setup(appToken: "YOUR_APP_TOKEN", sandbox: true, version: "1.3.2")
}
}
@IBAction func handleLink(_sender: Any) {
Lean.manager.link(presentingViewController: self, customerId: "CUSTOMER_ID", permissions: linkPermissions) {
print("Entity Linked")
} error: { (status) in
print(status.status)
print(status.message)
}
}

Choosing a version

When calling Lean.manager.setup a version is required.

Version takes a String and can point to either a specific SDK version i.e. "1.3.2" or an alias i.e. "latest".

We recommend passing in a specific version to ensure stability in the case that a change to the SDK breaks your application.

Available Versions

Specific Version semver

The current stable build is 1.3.2


latest alias

latest is an alias for the current release. It is subject to change at relatively short notice - but does allow for any bug fixes to be shipped over the air - meaning fixes can be applied without the need to resubmit your application to the app store.


next-release alias

next-release is a QA version of the SDK allowing you to test the next version that will become latest before we roll out the changes, this should only be used for development and QA purposes as it is subject to breakage without any warning.


Was this section helpful? 

Lean.manager.setup(
appToken: "YOUR_APP_TOKEN",
sandbox: true,
version: "1.3.2"
)

Available Methods

.link()

The .link method is used to connect accounts with the Data API.

[see reference]


.reconnect()

The .reconnect method is used to reauthenticate a customer account with the Data API.

[see reference]


.createPaymentSource()

The .createPaymentSource method is used to connect a bank account as a payment method to your application in the Payments API.

[see reference]


.pay()

The .pay method is used to make a bank to bank transfer from your customer's account to your account in the Payments API.

[see reference]

Was this section helpful? 

swift

Lean.manager.link(
customerId: String,
permissions: ArrayOf<LeanPermission>,
bankId: String?,
success: () -> (),
error: (status) -> ()
)

swift

Lean.manager.reconnect(
reconnectId: String,
success: () -> (),
error: (status) -> ()
)

swift

Lean.manager.createPaymentSource(
customerId: String,
bankId: String?
success: () -> (),
error: (status) -> ()
)

swift

Lean.manager.createPaymentSource(
paymentIntentId: String,
accountId: String?
success: () -> (),
error: (status) -> ()
)

Webhook URL

Results from the Link SDK will be sent to your server via a POST request from Lean made to the Webhook URL in the application settings.

Response

type String

The type of the webhook being received in the format of: [Object type].[action]. When triggered by the Lean.link() call, the type will be entity.created.


message String

Description of the event that has triggered the webhook.


payload Object

The resource which has triggered the webhook.

Upon entity creation, this will be the entity object:

View child attributes

id String

The identifier you will use to reference your customer's bank entity when making API calls.


app_user_id String

For your convenience, we’ll also pass the id your application uses to reference your customer.


permissions Array

The permissions your customer granted you.


bank_details Object

Attributes related to the bank that the entity originates from.

View child attributes

name String

The name of the bank where your user's entity and accounts exist.


bank_identifier String

For use with the /bank endpoint, allows you to query data on the bank related to the entity.


logo_url String

A URL pointing to an image of the bank's logo.


main_color String

The HEX value of the primary color the bank uses for display purposes.


background_color String

The HEX value of the secondary color the bank uses for display purposes.


timestamp DateTime

The time at which the webhook was triggered.

json

// Success Example
{
"type": "entity.created",
"message": "An entity object has been created.",
"payload": {
"id": "f08fb010-878f-407a-9ac2-a7840fb56185",
"app_user_id": "00001",
"permissions": ["transactions", "balance", "identity", "accounts"],
"bank_details": {
"name": "Lean Mockbank",
"identifier": "LEANMB1_SAU",
"logo": "https://cdn.leantech.me/img/banks/white-lean.png",
"main_color": "#1beb75",
"background_color": "#001E26"
}
},
"timestamp": "2020-10-10T17:19:00.059933Z"
}

Next Steps

With the Link SDK installed in your application, you can now get entity_ids for the Data API and create payment sources and charges with the Payment API.

Data API Reference

Payments API Reference