SDKs
Link Money's SDKs can be used to link your customers' bank accounts to Link Money services. Follow the setup steps of retrieving a session key for authentication before importing the appropriate SDK for your platform. Each platform has a corresponding example to help you begin linking accounts.
Note that every time a customer wants to link a bank account, regardless of platform, you need to retrieve a new session key.
JavaScript SDK
There are two methods to integrate the JavaScript SDK, via a build tool such as Webpack or by importing the SDK directly in your HTML source.
We have made two separate sample applications for each integration. You can reference either the direct integration sample or the build tool integration sample depending on your specific needs.
Direct
<html>
<body>
<button id="link-btn">Pay by Bank</button>
<script type="module">
import Link from 'https://static.link.money/linkmoney-web/v1/latest/linkmoney-web.min.js';
document.addEventListener(
'DOMContentLoaded',
() => {
document
.getElementById('link-btn')
.addEventListener('click', async function () {
const config = {
sessionKey: '{SESSION_KEY}',
redirect: '{REDIRECT_URL}',
environment: 'production' | 'sandbox'
};
const link = Link LinkInstance(config);
link.action();
});
},
false
);
</script>
</body>
</html>
Build Tool
Use your preferred package manager to retrieve the latest version of the SDK.
npm install @link.money/linkmoney-web
yarn add @link.money/linkmoney-web
Then in your rendered component, import the SDK.
import Link from '@link.money/linkmoney-web'
const showAlert = (sessionKey, redirect, environment) => {
const config = {
sessionKey,
redirect,
environment
}
const link = Link.LinkInstance(config);
link.action();
}
export const renderHTML = () => {
return (
<div>
<button onClick={showAlert('{SESSION_KEY}', '{REDIRECT_URL}' 'production' | 'sandbox' )} />
</div>
)
};
Usage
You can now use the following classes and interfaces to set up bank account linking. Link Money's Javascript SDK is Typescript-enabled. Please note that before you start your production integration you will need to let Link Money know what URL you are redirecting your users to so as to avoid malicious exploitations.
Start by using the static factory in the Link
class by calling Link.LinkInstance(Config)
. The Config
interface specifies the session key and the URL to which your customer will be redirected to after linking their bank account. Environment should be either production
or sandbox
depending whether you are in testing or production. The LinkInstance
function returns a LinkAction
, which has an action
method that redirects your customer to Link Money's bank account-linking flow.
Link
The Link static class is the entry point to linking bank accounts. To
begin initiating bank account linking, you can call Link.LinkInstance(Config)
.
Methods
getLinkInstances
() => LinkAction[]
Retrieves all LinkInstances within the static factory
Returns a new LinkInstance
Config
Information to pass when creating a LinkInstance.
Properties
redirect
string
URL customer will be redirected to after success or failure - must be pre-approved by Link Money
sessionKey
string
Your session key
environment
string
production
orsandbox
LinkAction
Interface for LinkInstances. Since properties are private, they will only be available for LinkInstances instantiated by your code.
Methods
action
() => void
Redirects customer to Link Money’s bank account-linking flow
getToken
() => string
Retrieves the authorization token of the instance
isInitiated
() => boolean
Retrieves initiation status of the instance
Properties
initiated
boolean
Indicates the status of a link or pay action
redirect
string
URL customer will be redirected to after success or failure
sessionKey
string
Your session key
action() Method
Calling link.action()
will redirect your customer to Link
Money's account-linking flow. After either success or failure, Link
Money will redirect your customer back to your redirect URL provided in
the Config
with the following parameters.
status
number
Status code
customerId
string
Newly generated customer ID. You must retain this value to use for payments
{REDIRECT_URL}/?status=200&customerId={CUSTOMER_ID}
Status codes
200
Payments can be made
Successfully linked bank account
204
Payments can NOT be made
Customer exited voluntarily
500
Payments can NOT be made
Error occurred
Get Customer By ID
Calling the Link.getCustomer
method allows you to access
attributes of a customer. Simply pass a valid auth token and the
customerId
returned by Link Money after the account linking process.
1let customerDetails = await Link.getCustomer(
2 {AUTH_TOKEN},
3 {CUSTOMER_ID}
4);
5
6console.log(customerDetails);
Response Body
id
string
Your customer ID
firstName
string
Customer’s first name
lastName
string
Customer’s last name
email
string
Customer’s email
status
enum
CREATED
orACTIVE
orINACTIVE
1{
2 "id": "string",
3 "firstName": "string",
4 "lastName": "string",
5 "email": "string",
6 "status": "string",
7 "creationDate": "2022-05-27T19:46:24.548Z"
8}
Get Account Details By Customer ID
Calling the Link.getAccounts
method allows you to access details of the bank account(s) a customer has linked. Simply pass a valid auth token and the customerId
returned by Link Money after the account linking process.
1let customerAccounts = await Link.getAccounts(
2 {AUTH_TOKEN},
3 {CUSTOMER_ID}
4);
5
6console.log(customerAccounts);
Response Body
accountDetails
array
Array of account details objects
accountId
string
Account ID
financialInstitutionId
string
Financial Institution ID
financialInstitutionName
string
Financial Institution name
iconUrl
URL *OPTIONAL
URL for a financial institution’s icon, when available
logoUrl
URL *OPTIONAL
URL for a financial institution’s logo, when available
lastFour
string
Last four digits of a bank account number
type
enum
CHECKING
orSAVINGS
status
enum
ACTIVE
orINACTIVE
orABANDON
orCREATED
creationDate
Date
Account creation date
1{
2 "accountDetails":
3 [{ "accountId": "string",
4 "financialInstitutionId": "string",
5 "financialInstitutionName": "string",
6 "logoUrl": "string",
7 "iconUrl": "string",
8 "lastFour": "string",
9 "type": "enum",
10 "status": "enum",
11 "preferred": "boolean",
12 "creationDate": "2022-05-27T18:36:47.630Z" }]
13}
iOS SDK
The iOS SDK can be added either via Cocoapods or downloaded and added manually as an .xcframework
.
In addition to the example shown below, we have also made available a sample application demonstrating how to integrate the SDK.
pod 'LinkAccount', '~> 1'
Example
1import LinkAccount
2
3let view = LinkAccountView(sessionKey: sessionKey, environment: .production)
4 view.display { result in
5 self.isPresenting.toggle()
6 switch result {
7 case .success(let value):
8 print("Customer ID is \(value)")
9 case .failure(let error):
10 print(error)
11 }
12}
Module
The LinkAccount
module contains everything necessary to
kick off the linking flow and debug issues resulting from failed linking
attempts.
Members
LinkAccountView
Kicks off account linking flow
LinkService
Retrieves customer and account info
LinkCustomer
Struct representing a Link customer
LinkError
Encapsulates errors returned from account linking
LinkEnvironment
Link environment
LinkAccountView
This class is the entry point to linking bank accounts. To begin initiating bank account linking, you can call LinkAccountView
instance and then call the display
method.
sessionKey
string
Your session key
environment
Link environment
Methods
display
Kicks off the linking flow
LinkError
code
string
Error Code
message
string
Error message
errorDescription
string
Description of error
LinkEnvironment
production
enum
Enum type pointing to production
sandbox
enum
Enum type pointing to sandbox
LinkAccountComplete
LinkAccountComplete
is a closure returning a Swift Result
type with either .success
or .failure
set.
success
string
String value representing the customer ID
failure
Encapsulates errors returned from account linking
LinkService
This class provides methods to retrieve customer info and lists of authorized accounts.
accessToken
string
Your access token
environment
Link environment
Example
Create an instance of the LinkService
class passing along the accessToken
and environment
arguments. Each method takes a customerId
and a completion handler which returns a Swift Result
type.
1import LinkAccount
2
3let service = LinkService(accesstoken, .production)
4service.getCustomer(customerId) {
5 switch result {
6 case .success(let value):
7 print("Customer: \(value.firstName) \(value.lastName)")
8 case .failure(let error):
9 print("Failed to retrieve customer: \(error)")
10 }
11}
Methods
Retrieves customer info
Retrieves an array of authorized accounts
LinkCustomer
id
string
Customer ID
firstName
string
Customer’s first name
lastName
string
Customer’s last name
email
string
Customer’s email
status
enum
ACTIVE
orCREATED
creationDate
Date
Account creation date
LinkAuthorizedAccount
accountId
int
Account ID
financialInstitutionId
int
Financial institution ID
financialInstitutionName
string
Financial Institution name
logoUrl
URL *OPTIONAL
URL for a financial institution’s logo, when available
lastFour
string
Last four digits of a bank account number
type
enum
CHECKING
orSAVINGS
status
enum
ACTIVE
orINACTIVE
orABANDON
orCREATED
creationDate
Date
Account creation date
Android SDK
The Android SDK can be added either via Maven package management or downloaded directly and added manually as an AAR bundle.
implementation 'money.link:linkaccount:1.+'
Example
Create an instance of the LinkAccountDialog
class using the LinkAccountDialog.create
method passing along the sessionKey
and environment
arguments. The SDK provides two environments, LinkEnvironment.SANDBOX
and LinkEnvironment.PRODUCTION
(default).
To display the created LinkAccountDialog
instance the display
method needs to be called passing along a supportFragmentManager
.
1import money.link.linkaccount.*
2
3val dialog = LinkAccountDialog(sessionKey, LinkEnvironment.PRODUCTION)
4dialog.display(supportFragmentManager)
After the LinkAccountDialog has finished, the result can be received using Android-recommended fragment communication options, a shared ViewModel or the Fragment Result API.
For both options, the returned result will be of type LinkAccountResult
, a type alias of a Kotlin Result type. On success, the value is a customer id of type LinkCustomerId
. On failure, the value is an error of type LinkError
.
To receive the result using a shared ViewModel, a global instance of the LinkAccountResultViewModel
has to be initialized using Android’s viewModels lazy delegate and observe the linkAccountResult before displaying the LinkAccountDialog
.
Notice: The results of the LinkAccountDialog
will be emitted only once and to only one observer.
1import androidx.appcompat.app.AppCompatActivity
2import androidx activity.viewModels
3import money.link.linkaccount.*
4
5class MainActivity : AppCompatActivity() {
6
7 val viewModel: LinkAccountResultViewModel by viewModels()
8
9 override fun onCreate(savedInstanceState: Bundle?) {
10 super.onCreate(savedInstanceState)
11 viewModel.linkAccountResult.observe(this){ result ->
12 result.onSuccess { customerId ->
13 print("Customer ID is $customerId")
14 }
15
16 result.onFailure { error ->
17 print(error)
18 }
19 }
20 }
21}
To receive the result using the Fragment Result API a result listener needs to be set in the Activity or Fragment that receives the result. To set the result listener the setFragmentResultListener()
has to be called from the receiver’s supportFragmentManager using the LINK_ACCOUNT_REQUEST_KEY
. The result returned in the response bundle can be retrieved with the LINK_ACCOUNT_RESULT_KEY
.
1import androidx.appcompat.app.AppCompatActivity
2import androidx.fragment.app.FragmentResultListener
3import money.link.linkaccount.*
4
5class MainActivity : AppCompatActivity() {
6 override fun onCreate(savedInstanceState: Bundle?) {
7 super.onCreate(savedInstanceState)
8 supportFragmentManager.setFragmentResultListener(
9 LinkAccountDialog.LINK_ACCOUNT_REQUEST_KEY,
10 this,
11 FragmentResultListener { _, bundle ->
12 val serializedResult = bundle.getSerializable(LinkAccountDialog.LINK_ACCOUNT_RESULT_KEY)
13 (serializedResult as? LinkAccountResult)?.let { result ->
14 result.onSuccess { customerId ->
15 print("Customer ID is $customerId")
16 }
17
18 result.onFailure { error ->
19 print(error)
20 }
21 }
22 }
23 )
24 }
25}
Package
The money.link.linkaccount
package contains everything
necessary to kick off the linking flow and debug issues resulting from
failed linking attempts.
Members
LinkAccountDialog
Encapsulates the account linking flow
LinkService
Retrieves customer and account info
LinkCustomer
Represents a Link Money customer
LinkAccountResultViewModel
ViewModel implementation to share the result
LinkError
Encapsulates errors returned from account linking
LinkEnvironment
Link environment
LinkAccountDialog
This class is the entry point to linking bank accounts. To begin initiating bank account linking, you create a LinkAccountDialog
instance and then call the display
function.
sessionKey
string
Your session key
environment
LinkEnvironment
Link environment
Methods
create
(SessionKey, LinkEnvironment)
Creates a new Link Account Dialog instance
display
Kicks off the linking flow
LinkError
statusCode
int *OPTIONAL
Error code
message
string
Error message
LinkEnvironment
production
enum
Enum type pointing to production
sandbox
enum
Enum type pointing to sandbox
LinkAccountResultViewModel
linkAccountResult
LiveData<LinkAccountResult>
Live data object that can be observed for results
LinkAccountResult
onSuccess
string
String value representing the customer ID
onFailure
Encapsulates errors returned from account linking
LinkService
This class provides methods to retrieve customer info and lists of authorized accounts.
accessToken
string
Your access token
environment
Link environment
Example
Create an instance of the LinkService
class passing along the accessToken
and environment
arguments. Each method takes a customerId
and a completion handler which returns a Kotlin Result
type.
1import money.link.linkaccount.LinkService
2
3val service = LinkService(accesstoken, LinkEnvironment.PRODUCTION)
4service.getCustomer(customerId) {
5 it.onSuccess {
6 print("Customer: ${it.firstName} ${it.lastName}")
7 }
8}
Methods
Retrieves customer info
Retrieves a list of authorized accounts
LinkCustomer
id
string
Customer ID
firstName
string
Customer’s first name
lastName
string
Customer’s last name
email
string
Customer’s email
status
enum
ACTIVE
orCREATED
creationDate
Date
Account creation date
LinkAccount
accountId
int
Account ID
financialInstitutionId
int
Financial institution ID
financialInstitutionName
string
Financial Institution name
logoUrl
URL *OPTIONAL
URL for a financial institution’s logo, when available
lastFour
string
Last four digits of a bank account number
type
enum
CHECKING
orSAVINGS
status
enum
ACTIVE
orINACTIVE
orABANDON
orCREATED
creationDate
Date
Account creation date
React Native SDK
Use one of the following methods to import the React Native SDK to your project.
npm install @link.money/linkpay-reactnative@1
yarn add @link.money/linkpay-reactnative@1
Example
The React Native SDK presents as a full screen takeover so you’ll want to include it at the root of your navigation stack.
1import {
2 LinkPayContextProvider,
3 LinkPayView,
4} from '@link.money/linkpay-reactnative';
5
6<NavigationContainer>
7 <LinkPayContextProvider>
8 <Stack.Navigator>
9 <Stack.Group>
10 <Stack.Screen
11 name="Home"
12 component={Home}
13 options={{ title: 'Your app’s root view' }}
14 />
15 </Stack.Group>
16 <Stack.Group screenOptions={{ presentation: 'modal' }}>
17 <Stack.Screen name="LinkPayView" component={LinkPayView} />
18 </Stack.Group>
19 </Stack.Navigator>
20 </LinkPayContextProvider>
21<NavigationContainer>
Additionally, you’ll need to reference it from your checkout UI.
1import {
2 LinkService,
3 LinkHost,
4 LinkCustomerAccount,
5 useLinkPayContext,
6 LinkPayEnvironment,
7} from '@link.money/linkpay-reactnative';
8
9// Checkout
10export default function Checkout({ navigation }: { navigation: any }) {
11 const linkPayContext = useLinkPayContext();
12 const [customerId, setCustomerId] = useState('');
13
14 // Called when the customer has successfully linked their account
15 useEffect(() => {
16 if (linkPayContext.customerId.length > 0) {
17 setCustomerId(linkPayContext.customerId);
18 }
19 }, [linkPayContext.customerId]);
20
21 // Called if customer attempted but failed to link their account
22 useEffect(() => {
23 if (linkPayContext.failure) {
24 let message = linkPayContext.failure.message;
25
26 if (linkPayContext.failure.code) {
27 message = message.concat(' (code: ', linkPayContext.failure.code, ')');
28 }
29
30 return Alert.alert('Error', message);
31 }
32 }, [linkPayContext.failure]);
33
34 // Call this method when customer clicks/taps the link account action
35 const linkCustomerAccount = () => {
36 // Retrieved from LinkPay API using client id + secret
37 linkPayContext.setSessionKey(sessionKey);
38
39 // Choices are sandbox and production with sandbox being default
40 linkPayContext.setEnvironment(LinkPayEnvironment.sandbox);
41
42 // Present the modal
43 navigation.navigate('LinkPayView');
44 };
45}
Package
The React Native SDK contains everything necessary to kick off the linking flow and debug issues resulting from failed linking attempts.
Members
LinkPayContextProvider
React context that passes values from the account linking to the calling React component
LinkService
Retrieves customer and account info
LinkPayEnvironment
LinkPay environment
LinkError
Contains information about any linking errors
LinkPayContextProvider
Add this React context to your navigation stack so that linked account information can be passed back to the calling React component.
Properties
sessionKey
string
Your session key
environment
Preferred Link environment, sandbox or production
customerId
string
Initially blank, it will contain the generated unique customer id after an account has been successfully linked
failure
Initially null, it encapsulates any errors returned from the linking process
LinkError
message
string
Error message
code
number *OPTIONAL
Error code
LinkPayEnvironment
Enum with a value of either sandbox
or production
.
LinkService
This class provides methods to retrieve customer info and lists of authorized accounts.
Example
Create an instance of the LinkService
class passing along the accessToken
and environment
arguments. You can use either a Promise-style callback or an await
inside of an async
method.
1const [customerId, setCustomerId] = useState('');
2const [accounts, setAccounts] = useState<LinkCustomerAccount[]>([]);
3
4useEffect(() => {
5 if (customerId.length > 0 && accessToken) {
6 const service = new LinkService(accessToken, LinkPayEnvironment.sandbox);
7 service
8 .getAccounts(customerId)
9 .then((result: LinkCustomerAccount[]) => {
10 setAccounts(result);
11 })
12 .catch((error: any) => {
13 Alert.alert('Error', error.message);
14 });
15 }
16}, [customerId]);
Methods
getCustomer
(customerId: string) -> LinkCustomerDetails
Retrieves customer info
getAccounts
(customerId: string) -> LinkCustomerAccount[]
Retrieves a list of authorized accounts
LinkCustomerDetails
id
string
Customer ID
firstName
string
Customer’s first name
lastName
string
Customer’s last name
email
string
Customer’s email
status
enum
ACTIVE
orCREATED
creationDate
Date
Account creation date
LinkCustomerAccount
accountId
int
Account ID
financialInstitutionId
int
Financial institution ID
financialInstitutionName
string
Financial Institution name
logoUrl
URL *OPTIONAL
URL for a financial institution’s logo, when available
lastFour
string
Last four digits of a bank account number
type
enum
CHECKING
orSAVINGS
status
enum
ACTIVE
orINACTIVE
orABANDON
orCREATED
creationDate
Date
Account creation date