# Transaction Matching Guidance
source: https://developer.mastercard.com/ethoca-consumer-clarity-for-merchants/documentation/tutorials-and-guides/transaction-matching-guidance/index.md

Because issuers often send incomplete request data, we strongly recommend that merchants perform fuzzy matching of transactions when receiving Ethoca Consumer Clarity requests or First-Party Trust requests, to enhance matching accuracy and efficiency.

The following flowchart (with decision pseudocodes further below) shows a visual recommendation of how your fuzzy matching logic will ideally be constructed:

![Flowchart for matching guidance](https://static.developer.mastercard.com/content/ethoca-consumer-clarity-for-merchants/documentation/img/matching-guidance-flowchart2.png)

Though not required, the decision pseudocodes below provide our recommendation as to how you can implement matching logic in your environment:
Note:
* The search object contains all input parameters: ARN, Date, Auth_code, Amount, Currency, TID, BIN, L4.
* Each transaction in the database has fields: ARN, Date, Auth_code, Amount, Currency, TID, BIN, L4.
* A convert_currency(amount, from_currency, to_currency) function is available for currency conversion.
* The is_date_match function checks if two dates are within a ±2-day range, implementing the fuzzy date rule.
* The is_amount_equal function ensures an exact match of amount and currency for conditions requiring precision.
* The is_amount_fuzzy_match function allows for a 5% variance after converting the search amount to the transaction's currency if they differ, or directly compares them if the currencies are the same.

    def find_matching_transaction(search, database): 

    # Condition 1: ARN + Date
    matches = [tx for tx in database if tx.ARN == search.ARN and is_date_match(tx.Date, search.Date)] if len(matches) == 1: return matches[0]

    # Condition 2: Date + Auth_code + Amount
    matches = [tx for tx in database if is_date_match(tx.Date, search.Date) and 
        tx.Auth_code == search.Auth_code and 
        is_amount_equal(tx.Amount, tx.Currency, search.Amount, search.Currency)]
    if len(matches) == 1:
        return matches[0]

    # Condition 3: Date + TID + Amount_fuzzy
    matches = [tx for tx in database if is_date_match(tx.Date, search.Date) and 
               tx.TID == search.TID and 
               is_amount_fuzzy_match(search.Amount, search.Currency, tx.Amount, tx.Currency)]
    if len(matches) == 1:
        return matches[0]

    # Condition 4: Date + Amount_fuzzy + BIN + L4 + Auth_code
    matches = [tx for tx in database if is_date_match(tx.Date, search.Date) and 
               is_amount_fuzzy_match(search.Amount, search.Currency, tx.Amount, tx.Currency) and 
               tx.BIN == search.BIN and 
               tx.L4 == search.L4 and 
               tx.Auth_code == search.Auth_code]
    if len(matches) == 1:
        return matches[0]

    # Condition 5: Date + Amount + BIN + L4
    matches = [tx for tx in database if is_date_match(tx.Date, search.Date) and 
               is_amount_equal(tx.Amount, tx.Currency, search.Amount, search.Currency) and 
               tx.BIN == search.BIN and 
               tx.L4 == search.L4]
    if len(matches) == 1:
        return matches[0]

    # No single match found
    return None

## Transaction Fields For Matching {#transaction-fields-for-matching}

This table shows the fields associated with the matching guidance provided above:

|               Field Name                |                                                       Description                                                        |
|-----------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| Acquirer Reference Number (ARN)         | Acquirer Reference Number of the transaction                                                                             |
| Transaction Date and Time               | Date, time, and time zone information of when the transaction was authorized in UTC format                               |
| Auth Code                               | Issuer authorization code for the transaction                                                                            |
| Transaction Currency and Amount         | Total amount value associated with the transaction at the time of the authorization and the currency associated with it. |
| Transaction ID/Banknet Reference Number | Transaction identifier value associated with the type specified in transactionIdentifierType                             |
| Card BIN                                | The first 6 numbers of of the card used                                                                                  |
| Card L4                                 | The last 4 numbers of the card used                                                                                      |

## Merchant Matching Tips {#merchant-matching-tips}

* **It is essential for merchants to avoid using card numbers (PAN or BIN \& L4) as their primary filter for matching.**

  * Doing so can lead to a low match rate for receipts and alerts, as merchants typically only have access to tokenized card numbers, while Ethoca transmits the real card number (known as FPAN or Funding Primary Account Number).
  * Instead, merchants should prioritize using the transaction date as their initial filter (Condition 1 in the pseudocodes above), following by matching combinations, such as the authorization code and transaction amount. The PAN and BIN \& L4 should only be applied as filters at a later stage of the logic.
* **It is advisable for merchants to implement comprehensive fuzzy matching regardless of the availability of data fields.**

  * For instance, merchants with limited access to ARN should still incorporate ARN into their matching criteria.
  * This approach guarantees that the merchant's matching logic remains standardized, consistent, and future-proof, as acquirers may evolve and new acquirers may offer fields that weren't originally available.
* **The auth code is among the most readily available data fields for issuers and merchants alike.**

  * Comprising just 6 alphanumeric digits, the auth code is not deterministic for matching single transactions.
  * However, its effectiveness is greatly amplified when used alongside other data points, such as transaction date, amount, and BIN \& L4. This strategic combination can significantly improve the merchant match rate.
