Getnet DocsGetnet Docs

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: The Date object 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, default true): If true, the result will include a breakdown of totals by card brand (Visa, Mastercard, etc.).

Interpreting CloseSessionResult

The operation returns a CloseSessionResult sealed interface:

  1. Successful (CloseSessionResult.Successful): The session closed correctly. The data property contains a TotalsCommonModel with the summary of the closed session (amounts, transaction counts, etc.).
  2. 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