BRAccountLinkingManager
Objective-C
@interface BRAccountLinkingManager : NSObject
Swift
class BRAccountLinkingManager : NSObject
Use this interface to manage users’ linked retailer accounts for parsing e-receipts. Here is the basic flow:
- Implement UI to capture the user’s credentials to one or more retailers from the supported list (see
BRAccountLinkingRetailer
enum) - Store these using
-[BRAccountLinkingManager linkAccountWithCredentials:]
- Call
-[BRAccountLinkingManager grabNewOrdersWithCompletion:]
- The callback to this method will return all order details available since the most recent successful invocation
-
Declaration
Objective-C
+ (nonnull instancetype)shared;
Swift
class func shared() -> Self
-
Deprecated
Use BRAccountLinkingConfiguration.dayCutoff instead.
Set this property to control how far back in the user’s history to search for orders
Default: 15
Declaration
Objective-C
@property (nonatomic) NSInteger dayCutoff;
Swift
var dayCutoff: Int { get set }
-
Deprecated
Use BRAccountLinkingConfiguration.dateCutoff instead.
This property is an alternative to
dayCutoff
which allows you to set a specific date/time that serves as the boundary of how far back to search. If set, it will overridedayCutoff
Default: nil
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSDate *dateCutoff;
Swift
var dateCutoff: Date? { get set }
-
Deprecated
Use BRAccountLinkingConfiguration.returnLatestOrdersOnly instead.
When set to YES, the first scrape will attempt to retrieve orders back to the
dayCutoff
ordateCutoff
but all subsequent scrapes will only go as far back as the last scrape date regardless of whether the first scrape completed When set to NO, subsequent scrapes will continue to fetch historical orders untildayCutoff
ordateCutoff
is reached, and after that, scrapes will only go back to the last scrape dateDefault: YES
Declaration
Objective-C
@property (nonatomic) BOOL returnLatestOrdersOnly;
Swift
var returnLatestOrdersOnly: Bool { get set }
-
Deprecated
Use BRAccountLinkingConfiguration.countryCode instead.
Set this to a different country to access the correct version of the retailer’s site, if it exists for that country (currently only supports Amazon UK)
Default: @“US”
Declaration
Objective-C
@property (nonatomic, strong) DEPRECATED_MSG_ATTRIBUTE( "Use BRAccountLinkingConfiguration.countryCode instead.") NSString *countryCode;
Swift
var countryCode: String { get set }
-
Returns current version
Declaration
Objective-C
@property (nonatomic, copy, readonly) NSString *_Nonnull version;
Swift
var version: String { get }
-
A completion handler to receive updates from a background operation when enabled via
enableBackgroundFetchWithIdentifier
BRAccountLinkingRetailer retailer
- the retailer for this orderBRScanResults *results
- the current orderBRAccountLinkingError error
- any error that was encountered while attempting to grab ordersNSString *sessionId
- a unique session GUID that can be reported for debugging purposesDeclaration
Objective-C
@property (nonatomic, copy, nullable) void (^) (BRAccountLinkingRetailer, BRAccountLinkingError, NSString *_Nonnull, BRScanResults *_Nullable) backgroundFetchCompletion;
Swift
var backgroundFetchCompletion: ((BRAccountLinkingRetailer, BRAccountLinkingError, String, BRScanResults?) -> Void)? { get set }
-
Deprecated
Use linkRetailerWithConnection instead
Link a retailer online account
Declaration
Objective-C
- (BRAccountLinkingError)linkAccountWithCredentials: (nonnull BRAccountLinkingCredentials *)credentials;
Swift
func linkAccount(with credentials: BRAccountLinkingCredentials) -> BRAccountLinkingError
Parameters
credentials
The credentials for this account
Return Value
Any
BRAccountLinkingError
error that was encountered while attempting to link this retailer -
Link a retailer connection
Declaration
Objective-C
- (BRAccountLinkingError)linkRetailerWithConnection: (nonnull BRAccountLinkingConnection *)connection;
Swift
func linkRetailer(with connection: BRAccountLinkingConnection) -> BRAccountLinkingError
Parameters
connection
The retailer configuration
Return Value
Any
BRAccountLinkingError
error that was encountered while attempting to link this retailer -
Deprecated
Use verifyRetailerWithConnection instead
Verify account for a given retailer
Declaration
Objective-C
- (void)verifyAccountForRetailer:(BRAccountLinkingRetailer)retailer withCompletion: (nonnull void (^)(BRAccountLinkingError, UIViewController *_Nullable, NSString *_Nonnull))completion;
Swift
func verifyAccount(for retailer: BRAccountLinkingRetailer) async -> (BRAccountLinkingError, UIViewController?, String)
Parameters
retailer
The retailer ID of the account you want to verify
completion
Callback will be executed after verification has been attempted
BRAccountLinkingError error
- any error that was encountered while attempting to verify the accountUIViewController *vc
- for 2FA and other scenarios requiring user interaction, this will contain a reference to a view controller that should be shown or dismissed depending on the particularerror
valueNSString *sessionId
- a unique session GUID that can be reported for debugging purposes
-
Verify connection for a given retailer
Declaration
Objective-C
- (BRAccountLinkingConnectionIdentifier *_Nullable) verifyRetailerWithConnection: (nonnull BRAccountLinkingConnection *)connection withCompletion: (nonnull void (^)(BRAccountLinkingError, UIViewController *_Nullable, NSString *_Nonnull))completion;
Swift
func verifyRetailer(with connection: BRAccountLinkingConnection, withCompletion completion: @escaping (BRAccountLinkingError, UIViewController?, String) -> Void) -> BRAccountLinkingConnectionIdentifier?
Parameters
connection
The account connection you want to verify
completion
Callback will be executed after verification has been attempted
BRAccountLinkingError error
- any error that was encountered while attempting to verify the accountUIViewController *vc
- for 2FA and other scenarios requiring user interaction, this will contain a reference to a view controller that should be shown or dismissed depending on the particularerror
valueNSString *sessionId
- a unique session GUID that can be reported for debugging purposes
Return Value
A BRAccountLinkingConnectionIdentifier that can be used to cancel the task
-
Returns all retailers for which there is a linked account
Declaration
Objective-C
- (nonnull NSArray<NSNumber *> *)getLinkedRetailers;
Swift
func getLinkedRetailers() -> [NSNumber]
Return Value
An array of
NSNumber*
wrapped values from theBRAccountLinkingRetailer
enum -
Returns a linked account configuration
Declaration
Objective-C
- (BRAccountLinkingConnection *_Nullable)getLinkedRetailerConnection: (BRAccountLinkingRetailer)retailer;
Swift
func getLinkedRetailerConnection(_ retailer: BRAccountLinkingRetailer) -> BRAccountLinkingConnection?
Parameters
retailer
The
BRAccountLinkingRetailer
retailer associated with the connectionReturn Value
A
BRAccountLinkingConnection*
objects -
Resets order history for a particular retailer
Declaration
Objective-C
- (void)resetHistoryForRetailer:(BRAccountLinkingRetailer)retailer;
Swift
func resetHistory(for retailer: BRAccountLinkingRetailer)
Parameters
retailer
The
BRAccountLinkingRetailer
retailer for which to reset the order history -
Resets order history for all linked accounts
Declaration
Objective-C
- (void)resetHistory;
Swift
func resetHistory()
-
Unlink a retailer online account
Declaration
Objective-C
- (void)unlinkAccountForRetailer:(BRAccountLinkingRetailer)retailer withCompletion:(nonnull void (^)(void))completion;
Swift
func unlinkAccount(for retailer: BRAccountLinkingRetailer) async
Parameters
retailer
The retailer for which to unlink the account
completion
Unlinking an account involves async operations involving cookies, so this completion indicates when those operations have completed
-
Unlink all accounts
Declaration
Objective-C
- (void)unlinkAllAccountsWithCompletion:(nonnull void (^)(void))completion;
Swift
func unlinkAllAccounts() async
Parameters
completion
Unlinking accounts involves async operations involving cookies, so this completion indicates when those operations have completed
-
Deprecated
Use grabNewOrdersForRetailer instead
Grab new orders across all linked accounts
Note
If there is more than one account linked, they will be searched in parallel, so to determine when the whole process is done, you should wait until you get a callback indicating 0 orders remaining for every linked accountNote
You must have a valid license key set in[BRScanManager sharedManager].licenseKey
as well as a valid prod intel key set in[BRScanManager sharedManager].prodIntelKey
in order to receive any resultsDeclaration
Objective-C
- (void)grabNewOrdersWithCompletion: (nonnull void (^)(BRAccountLinkingRetailer, BRScanResults *_Nullable, NSInteger, UIViewController *_Nullable, BRAccountLinkingError, NSString *_Nonnull))completion;
Swift
func grabNewOrders() async -> (BRAccountLinkingRetailer, BRScanResults?, Int, UIViewController?, BRAccountLinkingError, String)
Parameters
completion
Callback will be executed as soon as each order is ready to be returned
BRAccountLinkingRetailer retailer
- the retailer for this orderBRScanResults *results
- the current orderNSInteger ordersRemainingInAccount
- the number of orders remaining in the current accountUIViewController *verificationViewController
- UIViewController for additional user input like 2FA when requiredBRAccountLinkingError error
- any error that was encountered while attempting to grab ordersNSString *sessionId
- a unique session GUID that can be reported for debugging purposes
-
Same as above except allows you to grab orders only for a single retailer
Declaration
Objective-C
- (BRAccountLinkingConnectionIdentifier *_Nullable) grabNewOrdersForRetailer:(BRAccountLinkingRetailer)retailer withCompletion:(nonnull void (^)(BRAccountLinkingRetailer, BRScanResults *_Nullable, NSInteger, UIViewController *_Nullable, BRAccountLinkingError, NSString *_Nonnull))completion;
Swift
func grabNewOrders(for retailer: BRAccountLinkingRetailer, withCompletion completion: @escaping (BRAccountLinkingRetailer, BRScanResults?, Int, UIViewController?, BRAccountLinkingError, String) -> Void) -> BRAccountLinkingConnectionIdentifier?
Return Value
A
BRAccountLinkingConnectionIdentifier*
object -
It cancels any connection that matches provided identifier
Declaration
Objective-C
- (void)cancelConnection: (nonnull BRAccountLinkingConnectionIdentifier *)identifier;
Swift
func cancelConnection(_ identifier: BRAccountLinkingConnectionIdentifier)
Parameters
identifier
A BRAccountLinkingConnectionIdentifier object
-
Updates linked connection with latest configuration
Declaration
Objective-C
- (void)updateConnection:(BRAccountLinkingConnection *_Nonnull)connection;
Swift
func update(_ connection: BRAccountLinkingConnection)
Parameters
connection
A BRAccountLinkingConnection object
-
It enables the SDK to check for new orders of all linked retailers periodically in backgorund, If background fetch is enabled by the host app
Note
The task is set to run every 1h but limittations apply. For more info, checkhttps://developer.apple.com/documentation/backgroundtasks/bgapprefreshtask?language=objc
Note
More info about how to generate the identifier string can be found here: https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app?language=objcNote
You must enable background fetch inside your application delegate’s didFinishLaunchingWithOptions: method. Attempting to enable it after launch or enabling it multiple times will cause a crashDeclaration
Objective-C
- (BRAccountLinkingError)enableBackgroundFetchWithIdentifier: (NSString *_Nonnull)identifier;
Swift
func enableBackgroundFetch(withIdentifier identifier: String) -> BRAccountLinkingError
Parameters
identifier
A string containing the identifier of the task.
Return Value
Any
BRAccountLinkingError
error that was encountered while attempting to enable background fetch