Skip to main content

AccountLinkingClient

The primary interface for linking retailer accounts and fetching order history. Implements Closeable — call close() when done to release resources.

Package: com.microblink.linking

Declaration

class AccountLinkingClient(context: Context) : Closeable

Quick Reference

Properties

PropertyDescription
dayCutoffHow many days back to search for orders
dateCutoffSpecific date boundary, overrides dayCutoff
latestOrdersOnlyWhether to only fetch orders newer than the last fetch
countryCodeISO country code for the retailer's regional site
webProxyOptional web proxy configuration

Methods

MethodDescription
link(account)Links one or more retailer accounts
verify(retailerId, success, failure, preview)Verifies stored credentials for a retailer
orders(retailerId, success, failure, preview)Fetches new orders for the specified retailer
accounts()Returns all currently linked accounts
unlink()Unlinks all accounts or a specific account
resetHistory()Resets order fetch history
close()Releases resources

Configuration Properties

dayCutoff

var dayCutoff: Int

How many days back to search for orders on each fetch.


dateCutoff

var dateCutoff: Date?

Alternative to dayCutoff. When set, overrides dayCutoff and uses this specific date as the search boundary.


latestOrdersOnly

var latestOrdersOnly: Boolean

When true, subsequent fetches only retrieve orders newer than the last fetch. When false, continues fetching history back to the cutoff on each call.

Default: true


countryCode

var countryCode: String

ISO country code for the retailer's regional site (currently used for Amazon UK).

Default: "US"


webProxy

var webProxy: WebProxy?

Optional web proxy configuration for network requests.


Methods

fun link(account: Account): Task<Boolean>
fun link(vararg accounts: Account): Task<Boolean>

Links one or more retailer accounts. Returns a Task<Boolean> that resolves true on success. See Account and Credentials.


verify(retailerId, success, failure, preview)

fun verify(
retailerId: Int,
success: (verified: Boolean, uuid: String) -> Unit,
failure: (throwable: AccountLinkingException) -> Unit,
preview: (view: View?) -> Unit? = { }
)

Verifies that stored credentials for the given retailer are still valid.

Parameters:

ParameterDescription
retailerIdRetailer constant from com.microblink.linking (e.g., RETAILER_AMAZON)
successCalled with true if credentials are valid, plus a session UUID
failureCalled with an AccountLinkingException on error
previewOptional callback receiving a View for in-progress web interaction

orders(retailerId, success, failure, preview)

fun orders(
retailerId: Int,
success: (retailerId: Int, results: ScanResults?, remaining: Int, uuid: String) -> Unit,
failure: (retailerId: Int, throwable: AccountLinkingException) -> Unit = { _, _ -> },
preview: (view: View?) -> Unit? = { }
)

Fetches new orders for the specified retailer since the last successful fetch.

Parameters:

ParameterDescription
retailerIdRetailer constant
successCalled for each order with the retailer ID, parsed ScanResults (nullable), remaining order count, and session UUID
failureCalled with the retailer ID and exception on error; has a default no-op implementation
previewOptional callback receiving a View for in-progress web interaction

accounts()

fun accounts(): Task<List<Account>?>

Returns all currently linked accounts stored on the device.


fun unlink(): Task<Boolean>
fun unlink(account: Account): Task<Boolean>

Unlinks all accounts, or a specific account. Returns a Task<Boolean> that resolves true on success.


resetHistory()

fun resetHistory(): Task<Boolean>
fun resetHistory(retailerId: Int): Task<Boolean>

Resets order fetch history for all linked accounts or a specific retailer, causing the next orders() call to re-fetch from the cutoff.


close()

override fun close()

Releases resources. Should be called when the client is no longer needed.