Transactions
Last updated: 2026-05-14
Transaction Flow
PAaS 2 transactions use Android Intents:
- Your app creates a transaction request.
CarbonTerminal.createIntentForTransactionconverts it to anIntent.- Your app launches the Payment Application with
ActivityResultLauncher. - The Payment Application performs the secure payment flow.
- Your app receives the result and calls
createTransactionResponseFromIntent. - Your app handles approval, decline, receipts, and local order state.
Register the Result Launcher
kotlinprivate lateinit var transactionLauncher: ActivityResultLauncher<Intent> transactionLauncher = registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> if (result.resultCode == Activity.RESULT_OK) { val app = requireActivity().application as PaasApplication val response = app.terminal.createTransactionResponseFromIntent(result.data) handleTransactionResponse(response) } else { showError("Transaction cancelled") } }
Purchase Request
kotlinval request = PurchaseRequest( currencyId = Constants.CURRENCY_ID_NUMBER_DEFAULT, totalAmount = 10000, saleId = "sale-1001", loyaltyApplications = emptyArray(), paymentMethod = "", cashBackAmount = 0, tipAmount = 0, maximumTipAmount = 0, maximumTipPercent = 100, allowSkipTip = SkipTipOptions.NO ) request.setDisabledFeatures(arrayOf<PaymentFeatures>()) val intent = terminal.createIntentForTransaction(request) if (intent != null) { transactionLauncher.launch(intent) }
Refund Request
Use a refund request when returning funds to the cardholder or supported payment method. Include the original transaction reference when your flow requires it.
kotlinval request = RefundRequest( currencyId = Constants.CURRENCY_ID_NUMBER_DEFAULT, totalAmount = 4500, saleId = "refund-1001", loyaltyApplications = emptyArray(), paymentMethod = "", transactionReference = originalTransactionReference ) val intent = terminal.createIntentForTransaction(request) if (intent != null) { transactionLauncher.launch(intent) }
Transaction Response
The returned TransactionResponse contains outcome, transaction identity, receipts, payment details, and error/denial details.
kotlinprivate fun handleTransactionResponse(response: TransactionResponse) { when (response.getError()) { TransactionError.NONE -> { completeSale( transactionId = response.getTransactionId(), terminalId = response.getTerminalId(), amount = response.getTotalAmount() ) printReceipts(response) } else -> { showError("Payment failed: ${response.getError()}") } } }
Receipt Handling
The exact receipt content depends on transaction type and payment method. At minimum, card-payment receipts should include:
- Reference number
- Verification and authorisation method
- Card name
- Whether the card was contactless or chip
- Denial reason when declined
- EMV data such as AID, TVR, and TSI
Alternative payment method receipts should include:
- Reference number
- Payment method
Print Text Receipt
kotlinprivate fun printReceipts(response: TransactionResponse) { val printJob = terminal.startPrintJob(requireContext()) printJob.printTextLine("Westpay", null, null, monospace = false, bold = true) printJob.printTextLine("Transaction", null, response.getTransactionId(), monospace = true, bold = false) printJob.printTextLine("Amount", null, response.getTotalAmount().toString(), monospace = true, bold = false) val status = printJob.finish() Log.i("PAaS", "Receipt print status: $status") }
Print Bitmap Receipt
kotlinfun printReceiptImage(context: Activity, image: Bitmap) { lifecycleScope.launch { val success = withContext(Dispatchers.Default) { val printJob = terminal.startPrintJob(context) val printed = printJob.printImage(image) val status = printJob.finish() printed && status == PrinterStatus.OK } if (!success) { showError("Unable to print receipt") } } }
Last Transaction Result
Use getLastTransactionResult when your app needs to recover the final transaction outcome after interruption or uncertainty.
kotlinterminal.getLastTransactionResult( object : TransactionResponseHandler { override fun onTransactionCompleted(result: TransactionResponse) { handleTransactionResponse(result) } } )