Transaction History
This guide explains how to search for past transactions using the TransactionRepository. This functionality allows you to retrieve detailed lists of operations based on date ranges and specific criteria like card brand, amount, or result status.
Before searching, ensure the TPV is initialized.
Basic Search by Date
To retrieve transactions, use the getTransactions method. You must provide a start date and an end date.
The range between initDate and endDate cannot exceed 15 days.
suspend fun searchTransactions(start: Date, end: Date) {
val result = transactionRepository.getTransactions(
initDate = start,
endDate = end
)
handleTransactionResult(result)
}Advanced Filtering
You can refine your search using the TransactionFilter object. All properties in this filter are optional, you only need to set the criteria you want to apply.
Filter Properties
operationNumber: Search for a specific transaction ID (Int).type: A list of OperationType (e.g., PAYMENT, REFUND).result: The OperationResult status (e.g., AUTHORIZED, DENIED).lastCardDigits: The last 4 digits of the card (Int).rangeAmountMinMax: A Pair of Money objects defining the minimum and maximum amount.cardBrand: The CardBrand (e.g., VISA, MASTERCARD).
Example: Filtering by Card Brand and Amount
suspend fun searchVisaHighValue(start: Date, end: Date) {
// Define the filter
val myFilter = TransactionFilter(
cardBrand = CardBrand.VISA,
rangeAmountMinMax = Pair(
Money(BigDecimal("50.00"), Currency.getInstance("EUR")),
Money(BigDecimal("500.00"), Currency.getInstance("EUR"))
),
result = OperationResult.AUTHORIZED
)
// Execute search
val result = transactionRepository.getTransactions(
initDate = start,
endDate = end,
filter = myFilter
)
handleTransactionResult(result)
}Pagination and Limits
To manage large datasets, use the TransactionResultsFilter.
maxOperations: Limits the number of transactions returned.offset: Skips the specified number of transactions (useful for paging).
val pagingFilter = TransactionResultsFilter(
maxOperations = 20,
offset = 0
)
val result = transactionRepository.getTransactions(
initDate = start,
endDate = end,
resultsFilter = pagingFilter
)Interpreting the Result
The repository returns a RepositoryResult<GetTransactionsResult>.
The GetTransactionsResult data class contains:
transactionList: AList<Transaction>containing the found operations.hasMoreTransactions: ABooleanindicating if there are more transactions available matching your criteria (useful for pagination).
Handling Logic
fun handleTransactionResult(result: RepositoryResult<GetTransactionsResult>) {
when (result) {
is RepositoryResult.Success -> {
val searchData = result.data
val transactions = searchData.transactionList
if (transactions.isEmpty()) {
println("No transactions found.")
} else {
println("Found ${transactions.size} transactions.")
transactions.forEach { txn ->
println("ID: ${txn.operationInfo.number} - Amount: ${txn.amount}")
}
}
if (searchData.hasMoreTransactions) {
println("⚠️ There are more transactions available. Load next page.")
}
}
is RepositoryResult.ConnectionError -> println("❌ Connection Error")
is RepositoryResult.ProtocolError -> println("❌ Error: ${result.type}")
else -> {}
}
}Next Steps
- Issue Digital Receipts: Learn how to retrieve digital copies of receipts for these transactions.
- Control the Device Printer: Control the printer to reprint tickets.