View on GitHub

sensibill-android-documentation

Transaction Matching

What is transaction matching?

Transaction matching is a feature of the Sensibill SDK that allows a list of ExternalAccountTransaction (Sensibill objects that represent bank transactions) to be matched with Sensibill receipts.

How is works?

Transactions are matched to receipts explicitly or implicitly.

Explicit Matching (Transaction Linking)

Explicit matching occurs when a receipt it tagged with an externalTransactionID at the point of capture. The externalTransactionID should be unique and have some relation to a bank transaction (for example hashed bank transaction id). Important: the id that’s passed as an externalAccountTransaction will be used later for matching. Below is an example of how to add an external account transaction id to a receipt upload:

KOTLIN (Android):

val captureIntent = ReceiptCaptureActivityBuilder.getBuilder()
    .withExternalAccountTransactionId("bank_transaction_ID")
    .build(this)
startActivity(captureIntent)

for more capture details Capture Info

Implicit Matching

Implicit matching occurs when a receipt is matched to a ExternalAccountTransaction based on the amount, date and currency.

Date Match

An ExternalAccountTransaction has two potential dates: date & postedDate

  1. Date: The date the transaction occurred and PostedDate: The date the transaction was posted to the bank account

  2. The ExternalAccountTransaction.date takes priority over ExternalAccountTransaction.postedDate.
    • If the date is present, the matcher will use that date. If it’s not present, the postedDate will be used
    • If the posted date is only available, don’t set the date. Only set the postedDate
  3. The matcher will check if the date is within range of the receipt
    • For ExternalAccountTransaction.date, the receipt date must be within 1 day (before/after) of the transaction date
    • For ExternalAccountTransaction.postedDate. The receipt date must be within 3 days before the posted date or one day after
Currency Match

The currency code set on the ExternalAccountTransaction must match the currency code on the receipt

Amount Match

The amount set on the ExternalAccountTransaction must match the amount on the receipt

If these three properties match, the receipt will be linked to matching transaction. The matcher first attempts to match explicitly and then if not, implicitly. Transactions can only be matched to one receipt.

Steps to Match Transactions

  1. Creates a list of transactions that need to be matched against.
    • This is done by taking external transaction (definition can be variable) and converting them into Sensibill ExternalAccountTransaction objects which acts as a bridge between client and SDK.
    • ExternalAccountTransactions has transactionId, postedDate, amount and other metadata that TransactionMatcher will use to match receipts.

2 - Create a TransactionMatcher using TransactionMatcherBuilder which takes Context, Sensibil DefaultEnvironment, and valid access token

TransactionMatcherBuilder transactionMatcherBuilder = new TransactionMatcherBuilder(mContext, DefaultEnvironment.BETA_SANDBOX, access_token);

3 - Build and call .matchTransaction() which takes a list of ExternalAccountTransactions and TransactionMatcherListener()

transactionMatcherBuilder.build()
    .matchTransaction(list, new TransactionMatcher.TransactionMatcherListener() {
        @Override
        public void onMatched(List<MatchedExternalAccountTransaction> list) {
            // Successful Call with matched ExternalAccountTransactions
        }

        @Override
        public void onMatched(Map<ExternalAccountTransaction, MatchedReceiptInfo> map) {}

        @Override
        public void hasFailed(final int errorCode, final String message) {
            // Call Failed
        }
    });

4 - On successful Match, call getReceipt() to get MatchedReceiptInfo which can be used to get the id of the matched receipt. Receipt id can then be used to view Receipt in detail (view how to launch Receipt Detail Activity )