Create a Single-Step Payment
Single-step payments, or direct sales, authorize and capture the transaction amount in a single operation. This is the standard flow for point-of-sale transactions where the cardholder is present and the product or service is provided immediately.
Requirements
Before you can process a payment, the following lifecycle steps must be completed:
- Global Configuration: Library environment and license must be set.
- Authentication: A successful login to obtain
RedCLSTerminalData. - PIN pad Initialization: The physical device must be connected and initialized (
inicializarPinpadreturned status 0).
Step 1: Prepare the Transaction Data
The SDK uses the RedCLSOperativeWithCardData class to define the transaction parameters. Unlike other systems, the amount is passed as a String with two decimal places (e.g., "10.00").
import redcls.itpvpc.data.RedCLSOperativeWithCardData
// Define the transaction amount and reference
val amount = "25.00"
val saleData = RedCLSOperativeWithCardData(amount).apply {
this.invoice = "INV-123456" // Optional reference number
}Ensure the amount string uses a dot . as the decimal separator and contains exactly two decimal positions.
Step 2: Execute the Payment
The transaction is performed via the operativaConTarjeta method of your RedCLSPinPadManager instance. This operation is synchronous and handles the entire flow: card detection, PIN entry (if applicable), and online authorization.
// This must be run on a background thread
Thread {
try {
val response = pinpadManager.operativaConTarjeta(saleData)
if (response.status == 0) {
val tx = response.transactionData
if (tx.result == "Autorizada") {
Log.i("GetMini", "Approved! Auth: ${tx.autorizationNumber}")
} else {
Log.w("GetMini", "Denied. Code: ${tx.responseCode}")
}
} else {
Log.e("GetMini", "SDK Error: ${response.status} - ${response.msgKO}")
}
} catch (e: Exception) {
Log.e("GetMini", "Payment Exception: ${e.message}")
}
}.start()Step 3: Handle the Transaction Result
The RedCLSTransactionData object contains all the necessary information for your records and receipt printing.
| Field | Description |
|---|---|
result | The authorization outcome (e.g., "Autorizada", "Denegada"). |
autorizationNumber | The unique code provided by the issuer (if approved). |
responseCode | The 4-digit status code (e.g., "0000" for OK, "0190" for denial). |
identifierRTS | A 24-character SDK reference ID for the transaction. |
order | The internal sequence number assigned by the SDK. |
isPinAuthenticated | Indicates if the cardholder was verified via PIN. |
fun handleSuccess(tx: RedCLSTransactionData) {
when (tx.result) {
"Autorizada" -> {
Log.i("GetMini", "Approved! Auth: ${tx.autorizationNumber}")
// Proceed to print/display receipt
}
"Denegada" -> {
Log.w("GetMini", "Transaction Denied. Code: ${tx.responseCode}")
}
}
}Troubleshooting Common Payment Issues
- Timeout: The PIN pad may time out if the user takes too long to present the card or enter the PIN. Ensure the device is reachable and the battery is sufficient.
- Card Denied: If the
resultis “Denegada”, the cardholder should contact their bank. You can find the specific reason code intx.responseCode. - PIN pad Lost: If the connection drops during payment, the method will return an error status. You must re-initialize the connection before retrying.
Always store the identifierRTS and autorizationNumber. You will need these if you need to process a Refund (Devolución) later.
Next Steps
After mastering single-step payments, you can explore advanced transaction types:
- Create a Pre-authorized Payment - Reserve funds for later capture.
- Refund a Payment - Return funds to customers.
- Security and Device Binding - Optimize your integration’s security.