Run Administrative Commands
This guide shows you how to run administrative operations such as generating reports, performing terminal logon, or opening the Paynt app.
Set Up Admin Models
data class StartAdminRequest(
val type: StartAdminType = StartAdminType.Unknown
)
data class StartAdminResponse(
val type: StartAdminType = StartAdminType.Unknown,
val detailedList: List<StartAdminReportTotals>? = null, // Brand-specific totals
val total: StartAdminReportTotals? = null, // Overall totals
val response: String? = null // Response code (acquirer specific)
)
data class StartAdminReportTotals(
val saleCount: Int = 0, // Number of sales
val refundCount: Int = 0, // Number of refunds
val saleAmount: Int = 0, // Total sales amount in cents
val refundAmount: Int = 0, // Total refunds amount in cents
val brand: String = "All" // Card brand or "All"
)
enum class StartAdminType {
XReport, // X Report (current totals)
ZReport, // Z Report (end of day with totals reset)
Logon, // Terminal logon
OpenApp, // Just open the app
Unknown
}
Set Up the Admin Launcher
private val adminLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
handleAdminResult(result)
}
fun startAdminOperation(type: StartAdminType) {
val request = StartAdminRequest(type = type)
val payload = Gson().toJson(request)
val intent = createIntent(
PayntIntentConstants.ADMIN_URI,
PayntIntentConstants.ACTION_START_ADMIN,
PayntIntentConstants.EXTRA_START_ADMIN_REQUEST,
payload
)
if (intent != null) {
try {
adminLauncher.launch(intent)
} catch (e: ActivityNotFoundException) {
Log.e("PaymentIntegration", "Failed to launch admin intent", e)
handlePayntNotInstalled()
}
} else {
handlePayntNotInstalled()
}
}
private fun handleAdminResult(result: ActivityResult) {
if (result.resultCode == RESULT_OK) {
val responseJson = result.data?.getStringExtra(
PayntIntentConstants.EXTRA_START_ADMIN_RESPONSE
)
responseJson?.let {
val response = Gson().fromJson(it, StartAdminResponse::class.java)
processAdminResponse(response)
}
}
}
private fun processAdminResponse(response: StartAdminResponse) {
when (response.type) {
StartAdminType.XReport, StartAdminType.ZReport -> {
val totalSales = response.total?.saleAmount ?: 0
val totalRefunds = response.total?.refundAmount ?: 0
val salesCount = response.total?.saleCount ?: 0
val refundCount = response.total?.refundCount ?: 0
response.detailedList?.forEach { brandTotals ->
val brand = brandTotals.brand
val brandSales = brandTotals.saleAmount
}
}
StartAdminType.Logon -> {
val responseCode = response.response
}
StartAdminType.OpenApp -> {
// App opened successfully
}
else -> {
// Handle unknown response
}
}
}
Run Administrative Commands
// Generate X Report (current totals)
startAdminOperation(StartAdminType.XReport)
// Generate Z Report (end of day with totals reset)
startAdminOperation(StartAdminType.ZReport)
// Perform terminal logon
startAdminOperation(StartAdminType.Logon)
// Just open the payment app
startAdminOperation(StartAdminType.OpenApp)