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
BRAccountLinkingRetailerenum) - 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
-
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
enableBackgroundFetchWithIdentifierBRAccountLinkingRetailer 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 *_Nullable, BRScanResults *_Nullable) backgroundFetchCompletion;Swift
var backgroundFetchCompletion: ((BRAccountLinkingRetailer, BRAccountLinkingError, String?, BRScanResults?) -> Void)? { get set }
-
Link an account for a given retailer
Declaration
Objective-C
- (BRAccountLinkingConnectionIdentifier *_Nullable) linkAccountWithConnection:(BRAccountLinkingConnection *_Nonnull)connection withCompletion:(nonnull void (^)(BRAccountLinkingError, UIViewController *_Nullable, NSString *_Nullable))completion;Swift
func linkAccount(with connection: BRAccountLinkingConnection, withCompletion completion: @escaping (BRAccountLinkingError, UIViewController?, String?) -> Void) -> BRAccountLinkingConnectionIdentifier?Parameters
connectionA retailer’s configuration
completionCallback will be executed, if additional user input is needed or linking has completed
BRAccountLinkingError– any error that was encountered while attempting to link the account. You should check if the error equalsBRAccountLinkingErrorNonebefore proceeding with SDK methods like fetching orders or triggering new flows.UIViewController *userInputViewController- 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 particularerrorvalueNSString *sessionId- a unique session GUID that can be reported for debugging purposes
Return Value
A BRAccountLinkingConnectionIdentifier that can be used to cancel the task
-
Performs a login for the provided retailer
Declaration
Objective-C
- (BRAccountLinkingConnectionIdentifier *_Nullable) loginUserForLinkedRetailer:(BRAccountLinkingRetailer)retailer withCompletion: (nonnull void (^)(BRAccountLinkingError, UIViewController *_Nullable, NSString *_Nullable))completion;Swift
func loginUser(forLinkedRetailer retailer: BRAccountLinkingRetailer, withCompletion completion: @escaping (BRAccountLinkingError, UIViewController?, String?) -> Void) -> BRAccountLinkingConnectionIdentifier?Parameters
retailerAn ID of a linked retailer
completionCallback will be executed, if additional user input is needed or linking has completed
BRAccountLinkingError– any error that was encountered while attempting to login. You should check if the error equalsBRAccountLinkingErrorNonebefore proceeding with SDK methods like fetching orders or triggering new flows.UIViewController *userInputViewController- 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 particularerrorvalueNSString *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 a list with connections matching all linked accounts on device
Declaration
Objective-C
- (NSArray<BRAccountLinkingConnection *> *_Nonnull)getLinkedConnections;Swift
func getLinkedConnections() -> [BRAccountLinkingConnection]Return Value
An array of
BRAccountLinkingConnectionobjects -
Resets order history for a particular account connection
Declaration
Objective-C
- (void)resetHistoryForConnection: (BRAccountLinkingConnection *_Nonnull)connection;Swift
func resetHistory(for connection: BRAccountLinkingConnection)Parameters
connectionThe
BRAccountLinkingConnectionfor which to reset the order history -
Unlink a retailer online account
Declaration
Objective-C
- (void)unlinkAccountForRetailer:(BRAccountLinkingRetailer)retailer withCompletion:(nonnull void (^)(void))completion;Swift
func unlinkAccount(for retailer: BRAccountLinkingRetailer) asyncParameters
retailerThe retailer for which to unlink the account
completionUnlinking an account involves async operations involving cookies, so this completion indicates when those operations have completed
-
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
identifierA BRAccountLinkingConnectionIdentifier object
-
Updates linked connection with latest configuration
Declaration
Objective-C
- (void)updateConnection:(BRAccountLinkingConnection *_Nonnull)connection;Swift
func update(_ connection: BRAccountLinkingConnection)Parameters
connectionA 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=objcNote
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) -> BRAccountLinkingErrorParameters
identifierA string containing the identifier of the task.
Return Value
Any
BRAccountLinkingErrorerror that was encountered while attempting to enable background fetch
View on GitHub