Search…
Manage Funding Sources
Provides the essentials for a user to link their real payment methods with a virtual card
Funding sources supply the means for a user to link a real funding source with a virtual card. A user can supply their credit or debit card as a method to fund a transaction performed on the virtual card.

Creating a Funding Source

A funding source is registered by calling the create funding source API.
Before creating a funding source, the identity of your user must first be verified via Secure Id Verification.
Currently only credit and debit cards are supported as funding sources
iOS
Android
The FundingSourceAuthorizationDelegate is a protocol that facilitates any payment provider authorizations that require user input. For example, if a payment provider requires 3D-Secure authorization, a view controller with inputs will be provided by the SDK. This protocol ensures that you have the ability to control how this information is presented on your application.
An example implementation on your view controller AddFundingSourceViewController for delegate conformance may look like this:
AddFundingSourceViewController.swift
1
import SudoVirtualCards
2
​
3
class AddFundingSourceViewController: UIViewController, FundingSourceAuthorizationDelegate {
4
​
5
// ... Other view controller details
6
​
7
let returnURL: String? = "yourapp://fundingsource/authorization"
8
​
9
func fundingSourceAuthorizationPresentingViewController() -> UIViewController {
10
return self
11
}
12
}
Copied!
You may now call to create a funding source with code similar to this example:
AddFundingSourceViewController.swift
1
import SudoVirtualCards
2
​
3
class AddFundingSourceViewController: UIViewController, FundingSourceAuthorizationDelegate {
4
​
5
// .. Implementation Details go here
6
​
7
// Ensure you have a reference somehow to a `DefaultSudoVirtualCardsClient` instance.
8
let virtualCardsClient: SudoVirtualCardsClient
9
​
10
func addFundingSource() {
11
// Collect the input details on your form however makes sense for your use case.
12
let inputDetails = CreditCardFundingSourceInput(
13
cardNumber: input.cardNumber,
14
expirationMonth: input.expirationMonth,
15
expirationYear: input.expirationYear,
16
securityCode: input.securityCode,
17
address: input.address,
18
unitNumber: input.unitNumber,
19
city: input.city,
20
state: input.state,
21
postalCode: input.postalCode,
22
country: input.country)
23
self.virtualCardsClient.createFundingSource(
24
withCreditCardInput: inputDetails,
25
authorizationDelegate: self
26
) { result in
27
switch result {
28
case let .failure(cause):
29
// Handle/notify user of error
30
case let .success(fundingSource):
31
// Funding source has been added - return object is record of this operation.
32
}
33
​
34
}
35
}
Copied!
If a call to createFundingSource returns a success result from the completion handler, a user will now be able to provision a Virtual Card. If a failure is returned instead, the cause.localizedDescription can be presented to the user to notify them as to what caused the error.
A call to the createFundingSource method performs a synchronous network request to the funding source provider. Therefore, this method needs to be called with a Dispatchers.IO coroutine dispatcher to confine the coroutine execution to the I/O thread.
Calling this method on the Dispatchers.Main thread may cause a NetworkOnMainThreadException
An example implementation of creating a funding source is:
1
val inputDetails = CreditCardFundingSourceInput(
2
cardNumber = "4242424242424242",
3
expirationMonth = 10,
4
expirationYear = 2022,
5
securityCode = "123",
6
addressLine1 = "222333 Peachtree Place",
7
addressLine2 = null,
8
city = "Atlanta",
9
state = "GA",
10
postalCode = "30318",
11
country = "US"
12
)
13
launch {
14
try {
15
val fundingSource = withContext(Dispatchers.IO) {
16
virtualCardsClient.createFundingSource(
17
inputDetails
18
)
19
}
20
// The returned [fundingSource] has been created.
21
} catch (e: FundingSourceException) {
22
// Handle/notify user of exception
23
}
24
}
Copied!
The call to createFundingSource will return the funding source that has been created. A user will now be able to provision a Virtual Card. If an exception occurs, the e.localizedMessage can be presented to the user to notify them as to what caused the exception.

Cancelling a Funding Source

If a user decides they want to remove a funding source from their account, the ability to provide them with the means to do so is applied with the cancel funding source API.
When a funding source is cancelled, any associated active virtual cards will no longer be able to process transactions. Any such transactions will be declined.
This API call is idempotent, so any subsequent calls to this method with the same id will always yield the same result.
When a funding source is cancelled, the record of the funding source will not be deleted, but instead its state will be set to INACTIVE. This is because refunds are always returned to the same original funding source and so clients will need to be able to retain details about cancelled funding in case any such future refunds refer to them.
iOS
Android
To cancel a funding source, the id of the existing funding source must be passed into the cancelFundingSourceWithId method. An example implementation of cancelling a funding source on your CancelFundingSourceViewController may looked like this:
CancelFundingSourceViewController.swift
1
import SudoVirtualCards
2
​
3
class CancelFundingSourceViewController: UIViewController {
4
​
5
// .. Implementation details go here
6
​
7
// Ensure you have a reference somehow to a `DefaultSudoVirtualCardsClient` instance.
8
let virtualCardsClient: SudoVirtualCardsClient
9
​
10
func cancelFundingSource() {
11
// Collect the id on your form however makes sense for your use case.
12
self.virtualCardsClient.cancelFundingSourceWithId(id) { result in
13
switch result {
14
case let .failure(cause):
15
// Handle/notify user of error
16
case let .success(fundingSource):
17
// The returned funding source is now cancelled.
18
}
19
}
20
}
21
}
Copied!
If a call to cancelFundingSourceWithId returns a success result from the completion handler, the funding source with the associated id will now be in an INACTIVE state and no longer usable for provisioning Virtual Cards. If a failure is returned instead, the cause.localizedDescription can be presented to the user to notify them as to what caused the error.
To cancel a funding source, the id of the existing funding source must be passed into the cancelFundingSource method. An example implementation of cancelling a funding source is:
1
// Collect the id on your form however makes sense for your use case.
2
launch {
3
try {
4
val fundingSource = withContext(Dispatchers.IO) {
5
virtualCardsClient.cancelFundingSource(id)
6
}
7
// The returned [fundingSource] is now cancelled.
8
} catch (e: FundingSourceException) {
9
// Handle/notify user of exception
10
}
11
}
Copied!
The call to cancelFundingSource will return the funding source with the associated id in an INACTIVE state and will no longer be usable for provisioning Virtual Cards. If an exception occurs, the e.localizedMessage can be presented to the user to notify them as to what caused the exception.

Accessing Funding Sources

To provide the ability for a user to access previously added (or cancelled) funding sources, the get and list funding source APIs are used.
The former is used to access a specific funding source by its id, whereas the latter is used to access a list of funding sources. Both of these APIs support the use of data Caching through the use of the cachePolicy property.

Accessing a Single Funding Source

iOS
Android
To access a single funding source, getFundingSourceWithId can be used. If the input id property does not match an existing funding source, a nil response will be returned.
An example use case for accessing a funding source may exist in a view controller named AccessFundingSourcesViewController:
AccessFundingSourcesViewController.swift
1
class AccessFundingSourcesViewController: UIViewController {
2
​
3
// .. Implementation details go here
4
​
5
// Ensure you have a reference somehow to a `DefaultSudoVirtualCardsClient` instance.
6
let virtualCardsClient: SudoVirtualCardsClient
7
​
8
func accessFundingSourceWithId(_ id: String) {
9
virtualCardsClient.getFundingSourceWithId(
10
id,
11
cachePolicy: .useOnline
12
) { result in
13
switch result {
14
case let .failure(cause):
15
// Handle/notify user of error
16
case let .success(fundingSource):
17
// If the id matches a funding source, `fundingSource` will be returned, else nil
18
}
19
}
20
}
Copied!
The getFundingSource method is used to retrieve details of a funding source given its id. If the input id property does not match an existing funding source, a null response will be returned.
An example implementation of accessing a funding source is:
1
launch {
2
try {
3
val fundingSource = withContext(Dispatchers.IO) {
4
virtualCardsClient.getFundingSource(
5
id,
6
cachePolicy = CachePolicy.REMOTE_ONLY
7
)
8
}
9
// If the [id] matches a funding source, [fundingSource] will be returned, else [null]
10
} catch (e: FundingSourceException) {
11
// Handle/notify user of exception
12
}
13
}
Copied!

Accessing Multiple Funding Sources

iOS
Android
A user can have multiple funding sources, and some may be active whilst others are inactive. To access multiple records at once, getFundingSourcesWithLimit may be used. If no results matching the input are found, an empty ListOutput will be returned.
Multiple access does support Pagination. For more details, see here.
An example use case for accessing multiple funding sources may exist in the same view controller above named AccessFundingSourcesViewController:
AccessFundingSourcesViewController.swift
1
class AccessFundingSourcesViewController: UIViewController {
2
​
3
// .. Implementation details go here
4
​
5
// Ensure you have a reference somehow to a `DefaultSudoVirtualCardsClient` instance.
6
let virtualCardsClient: SudoVirtualCardsClient
7
​
8
func accessFundingSources() {
9
virtualCardsClient.getFundingSourcesWithLimit(
10
20,
11
nextToken: nextToken,
12
cachePolicy: .useOnline
13
) { result in
14
switch result {
15
case let .failure(cause):
16
// Handle/notify user of error
17
case let .success(fundingSources):
18
// `fundingSources` contains the funding sources that match the input.
19
}
20
}
21
}
Copied!
A user can have multiple funding sources, and some may be active whilst others are inactive. To access multiple funding sources at once, listFundingSources is used. If no results matching the input are found, an empty ListOutput will be returned.
Multiple access does support Pagination. For more details, see here.
An example implementation of accessing multiple funding sources is:
1
launch {
2
try {
3
val fundingSources = withContext(Dispatchers.IO) {
4
virtualCardsClient.listFundingSources(
5
limit = 20,
6
nextToken = nextToken,
7
cachePolicy = CachePolicy.REMOTE_ONLY
8
)
9
}
10
// [fundingSources] contains the funding sources that match the input.
11
} catch (e: FundingSourceException) {
12
// Handle/notify user of exception
13
}
14
}
Copied!
Last modified 1yr ago