Skip to main content

BREReceiptManager

The primary interface for managing e-receipt parsing in the BlinkEReceipt SDK. Handles OAuth authentication, IMAP account setup, and e-receipt extraction from email accounts. Inherits from NSObject.

SDK Version: 3.2.0

Declaration

@interface BREReceiptManager : NSObject
class BREReceiptManager : NSObject

Requirements

  • A valid license key set in BRScanManager.licenseKey
  • A valid product intelligence key set in BRScanManager.prodIntelKey
  • For OAuth flows: client IDs configured in googleClientId / outlookClientId
  • For IMAP: account credentials or app passwords

Quick Reference

Class Methods

MethodDescription
+sharedReturns the singleton instance

Properties

PropertyDescription
googleClientIdOAuth Client ID for Gmail authentication
outlookClientIdApplication ID for Outlook OAuth authentication
userHasProviderWhether a stored email provider exists
dayCutoffSearch depth in days
dateCutoffSpecific date boundary for searches
searchUntilDateUpper bound of the search period
senderWhitelistMaps sender addresses to merchant identifiers
countryCodeISO country code for parsing accuracy
aggregateResultsWhether to aggregate related emails
remoteScrapeClientEndpointOverride endpoint for remote scrape result posting
remoteScrapeUserDateCutoffOverride date cutoff for remote scrapes

Methods

MethodDescription
getLinkedAccountsReturns all currently linked email accounts
beginOAuthForProvider:withViewController:andCompletion:Initiates OAuth flow for Gmail or Outlook
setupIMAPForAccount:viewController:withCompletion:Guides IMAP setup for Gmail, Yahoo, or AOL
linkIMAPAccountWithoutSetup:withCompletion:Links an account with a pre-generated App Password
verifyImapAccount:withCompletion:Validates stored IMAP credentials
getEReceiptsWithCompletion:Retrieves e-receipts from all linked accounts
getEReceiptsForAccount:withCompletion:Retrieves e-receipts from a single linked account
startRemoteEReceiptScrapeWithCompletion:Queues a remote scrape job for all accounts
startRemoteEReceiptScrapeForAccount:withCompletion:Queues a remote scrape job for one account
startRemoteEReceiptScrapeForEmail:andProvider:
andEMLFile:withCompletion:
Processes external EML data via remote scrape
parseEReceiptFromSender:rawHTML:completion:Parses raw HTML directly for testing
signOutWithCompletion:Logs out all accounts
signOutFromAccount:withCompletion:Logs out a single account
resetEmailsCheckedClears email check history
openURL:options:provider:App delegate passthrough for OAuth callback handling

Class Methods

+shared

+ (nonnull instancetype)shared;
class func shared() -> Self

Returns the singleton instance of BREReceiptManager.


Properties

googleClientId

@property (nonatomic, copy, nullable) NSString *googleClientId;
var googleClientId: String? { get set }

Required to authenticate Gmail accounts. Enable the Gmail API in your Google API Console and obtain a Client ID for your app's bundle. Set this before beginning the OAuth flow for Gmail.


outlookClientId

@property (nonatomic, copy, nullable) NSString *outlookClientId;
var outlookClientId: String? { get set }

Required to authenticate Outlook accounts. Register your app at the Azure Portal (https://portal.azure.com/) and add an App Registration to obtain an Application (client) ID. Set this before beginning the OAuth flow for Outlook.


userHasProvider (read-only)

@property (nonatomic, readonly) BOOL userHasProvider;
var userHasProvider: Bool { get }

Indicates whether a stored email provider exists.


dayCutoff

@property (nonatomic) NSInteger dayCutoff;
var dayCutoff: Int { get set }

How far back (in days) to search the user's inbox for e-receipts. Default: 14


dateCutoff

@property (nonatomic, strong, nullable) NSDate *dateCutoff;
var dateCutoff: Date? { get set }

Alternative to dayCutoff; sets a specific date/time boundary for the search. Overrides dayCutoff when set. Default: nil


searchUntilDate

@property (nonatomic, strong, nullable) NSDate *searchUntilDate;
var searchUntilDate: Date? { get set }

Works with dateCutoff to set the later boundary (i.e., until when) for the search period. Default: nil


senderWhitelist

@property (nonatomic, copy, nullable) NSDictionary *senderWhitelist;
var senderWhitelist: [AnyHashable: Any]? { get set }

If populated, the keys in this dictionary are used as the senders to search the user's inbox for, and the corresponding values are used as the merchant sender address for parsing. Default: nil


countryCode

@property (nonatomic, copy, nullable) NSString *countryCode;
var countryCode: String? { get set }

If the e-receipts being scraped are known to be from a specific country, set this to the ISO 2-character country code to improve parsing. Default: nil


aggregateResults

@property (nonatomic) BOOL aggregateResults;
var aggregateResults: Bool { get set }

Controls whether to aggregate all emails relating to a given e-receipt order (such as shipping status updates) in the results structure. Default: NO


remoteScrapeClientEndpoint

@property (nonatomic, copy, nullable) NSString *remoteScrapeClientEndpoint;
var remoteScrapeClientEndpoint: String? { get set }

If set, overrides the client endpoint configured server-side to which results will be POSTed following a remote scrape. Default: nil


remoteScrapeUserDateCutoff

@property (nonatomic, strong, nullable) NSDate *remoteScrapeUserDateCutoff;
var remoteScrapeUserDateCutoff: Date? { get set }

If set, overrides the default date cutoff for the current user in remote scrapes. Default: nil


Methods

getLinkedAccounts

- (NSArray<BREmailAccount *> *_Nonnull)getLinkedAccounts;
func getLinkedAccounts() -> [BREmailAccount]

Returns an array of all currently linked BREmailAccount objects.


beginOAuthForProvider:withViewController:andCompletion:

- (void)beginOAuthForProvider:(BREReceiptProvider)provider
withViewController:(UIViewController *_Nonnull)viewController
andCompletion:(nonnull void (^)(BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func beginOAuth(for provider: BREReceiptProvider,
with viewController: UIViewController,
andCompletion completion: @escaping (BREmailAccount?, Error?) -> Void)

Initiates the OAuth flow for Gmail or Outlook. See BREReceiptProvider.


setupIMAPForAccount:viewController:withCompletion:

- (void)setupIMAPForAccount:(BRIMAPAccount *_Nonnull)account
viewController:(UIViewController *_Nonnull)viewController
withCompletion:(nonnull void (^)(BRSetupIMAPResult,
BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func setupIMAP(for account: BRIMAPAccount,
viewController: UIViewController,
withCompletion completion: @escaping (BRSetupIMAPResult,
BREmailAccount?, Error?) -> Void)

Guides IMAP setup for Gmail, Yahoo, or AOL accounts. Returns a BRSetupIMAPResult.


linkIMAPAccountWithoutSetup:withCompletion:

- (void)linkIMAPAccountWithoutSetup:(BRIMAPAccount *_Nonnull)account
withCompletion:(nonnull void (^)(BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func linkIMAPAccountWithoutSetup(_ account: BRIMAPAccount,
withCompletion completion: @escaping (BREmailAccount?, Error?) -> Void)

Links an account when an App Password has already been generated.


verifyImapAccount:withCompletion:

- (void)verifyImapAccount:(BRIMAPAccount *_Nonnull)account
withCompletion:(nonnull void (^)(BOOL, NSError *_Nullable))completion;
func verifyImapAccount(_ account: BRIMAPAccount,
withCompletion completion: @escaping (Bool, Error?) -> Void)

Validates stored IMAP credentials.


getEReceiptsWithCompletion:

- (void)getEReceiptsWithCompletion:(nonnull void (^)(NSArray<BRScanResults *> *_Nullable,
BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func getEReceipts(withCompletion completion: @escaping ([BRScanResults]?,
BREmailAccount?, Error?) -> Void)

Retrieves e-receipts from all linked accounts.

Expected result fields:

  • Order level: total, receiptDate, ereceiptOrderNumber
  • Products: productNumber, productDescription, unitPrice, totalPrice, quantity, shippingStatus
  • With product intelligence: productName, brand, category, size, upc, imgUrl

getEReceiptsForAccount:withCompletion:

- (void)getEReceiptsForAccount:(BREmailAccount *_Nonnull)account
withCompletion:(nonnull void (^)(NSArray<BRScanResults *> *_Nullable,
BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func getEReceipts(for account: BREmailAccount,
withCompletion completion: @escaping ([BRScanResults]?,
BREmailAccount?, Error?) -> Void)

Retrieves e-receipts from a single linked account.


startRemoteEReceiptScrapeWithCompletion:

- (void)startRemoteEReceiptScrapeWithCompletion:(nonnull void (^)(NSInteger,
BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func startRemoteEReceiptScrape(withCompletion completion: @escaping (Int,
BREmailAccount?, Error?) -> Void)

Queues a remote scrape job for all linked accounts. Completion receives a job ID, the email account, and any error.


startRemoteEReceiptScrapeForAccount:withCompletion:

- (void)startRemoteEReceiptScrapeForAccount:(BREmailAccount *_Nonnull)account
withCompletion:(nonnull void (^)(NSInteger,
BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func startRemoteEReceiptScrape(for account: BREmailAccount,
withCompletion completion: @escaping (Int, BREmailAccount?, Error?) -> Void)

Queues a remote scrape job for a single account.


startRemoteEReceiptScrapeForEmail:andProvider:andEMLFile:withCompletion:

- (void)startRemoteEReceiptScrapeForEmail:(NSString *_Nonnull)email
andProvider:(BREReceiptProvider)provider
andEMLFile:(NSData *_Nonnull)emlFile
withCompletion:(nonnull void (^)(NSInteger,
BREmailAccount *_Nullable,
NSError *_Nullable))completion;
func startRemoteEReceiptScrape(forEmail email: String,
andProvider provider: BREReceiptProvider,
andEMLFile emlFile: Data,
withCompletion completion: @escaping (Int, BREmailAccount?, Error?) -> Void)

Processes external EML data via remote scrape.


parseEReceiptFromSender:rawHTML:completion:

- (void)parseEReceiptFromSender:(NSString *_Nonnull)sender
rawHTML:(NSString *_Nonnull)html
completion:(nonnull void (^)(BRScanResults *_Nullable,
NSError *_Nullable))completion;
func parseEReceipt(fromSender sender: String, rawHTML html: String,
completion: @escaping (BRScanResults?, Error?) -> Void)

Directly parses raw HTML for testing purposes.


signOutWithCompletion:

- (void)signOutWithCompletion:(nonnull void (^)(NSError *_Nullable))completion;
func signOut(withCompletion completion: @escaping (Error?) -> Void)

Logs out all accounts; invalidates OAuth tokens and removes IMAP credentials.


signOutFromAccount:withCompletion:

- (void)signOutFromAccount:(BREmailAccount *_Nonnull)account
withCompletion:(nonnull void (^)(NSError *_Nullable))completion;
func signOut(from account: BREmailAccount,
withCompletion completion: @escaping (Error?) -> Void)

Logs out a single account.


resetEmailsChecked

- (void)resetEmailsChecked;
func resetEmailsChecked()

Clears email check history for testing without re-authentication.


openURL:options:provider:

- (BOOL)openURL:(NSURL *_Nonnull)url
options:(NSDictionary *_Nonnull)options
provider:(BREReceiptProvider)provider;
func open(_ url: URL, options: [UIApplication.OpenURLOptionsKey: Any],
provider: BREReceiptProvider) -> Bool

App delegate passthrough for OAuth callback handling. Call this from application(_:open:options:).