Manage Shifts and Sessions
This guide explains how to manage operational shifts and sessions using the ShiftRepository and SessionRepository. These operations allow you to segment transaction periods and settle batches with the host.
Opening a Shift
Shifts are local operational periods that allow you to group transactions (e.g., by employee or time of day). To start a new shift, use openShift.
Repository: ShiftRepository
Function: openShift
Parameters:
number: An integer representing the shift number.date: TheDateobject indicating when the shift opens.
Example:
suspend fun startShift(shiftNumber: Int) {
val result = shiftRepository.openShift(
number = shiftNumber,
date = Date() // Current time
)
when (result) {
is RepositoryResult.Success -> {
val isSuccess = result.data
if (isSuccess) {
println("✅ Shift $shiftNumber opened successfully")
} else {
println("❌ Failed to open shift")
}
}
is RepositoryResult.ConnectionError -> println("❌ Connection Error")
is RepositoryResult.ProtocolError -> println("❌ Error: ${result.type}")
else -> {}
}
}Closing a Session
Closing a session (often called “End of Day” or “Batch Close”) finalizes the current period and settles transactions with the Getnet host. This is a critical operation to ensure payments are processed and funds are deposited.
Repository: SessionRepository
Function: closeSession
Parameters:
wantBrandDetails(Optional, defaulttrue): Iftrue, the result will include a breakdown of totals by card brand (Visa, Mastercard, etc.).
Interpreting CloseSessionResult
The operation returns a CloseSessionResult sealed interface:
- Successful (
CloseSessionResult.Successful): The session closed correctly. Thedataproperty contains aTotalsCommonModelwith the summary of the closed session (amounts, transaction counts, etc.). - Rejected (
CloseSessionResult.Rejected): The host rejected the closure request.
Example:
suspend fun closeDailySession() {
val result = sessionRepository.closeSession(wantBrandDetails = true)
when (result) {
is RepositoryResult.Success -> {
when (val sessionOutcome = result.data) {
is CloseSessionResult.Successful -> {
val totals = sessionOutcome.data
println("✅ Session Closed. Total: ${totals.totalAmount}")
}
is CloseSessionResult.Rejected -> {
println("❌ Session Close Rejected by Host")
}
}
}
is RepositoryResult.ConnectionError -> println("❌ Connection Error")
is RepositoryResult.ProtocolError -> println("❌ Error: ${result.type}")
else -> {}
}
}Next Steps
- View Totals and Reports: Querying accumulated totals for specific sessions or shifts.