Create a Single-Step Payment
The core function of the TPV is to process card payments. The PaymentRepository manages this operation, handling communication with the card reader and the Get Smart SDK Payment Service.
Before processing any payment, ensure you have initialized the TPV.
Performing a Standard Payment
To process a simple card payment, use the makePayment function. The only mandatory parameter is the amount (as a Money object).
suspend fun pay(amount: BigDecimal, currency: Currency) {
// 1. Create the Money object
val money = Money(amount, currency)
// 2. Call makePayment
val result = paymentRepository.makePayment(
amount = money
)
// 3. Handle the result
when (result) {
is RepositoryResult.Success -> handlePaymentResult(result.data)
is RepositoryResult.ConnectionError -> showError("Connection failed")
is RepositoryResult.Cancelled -> showInfo("User cancelled: ${result.message}")
is RepositoryResult.ProtocolError -> showError("Error: ${result.type}")
}
}Advanced Payment Parameters
The makePayment function supports several optional parameters to enrich the transaction data:
tip: AMoneyobject representing the tip amount.shiftInfo: AShiftInfoobject to associate the payment with a specific work shift (Number and Date).financialConditions: Specific financial conditions if applicable.proprietaryExtraData: An object to attach third-party data to the transaction.language: AnLanguageIso6391enum to force the service UI to a specific language for this operation.
Example with optional parameters:
val result = paymentRepository.makePayment(
amount = Money(BigDecimal("50.00"), Currency.getInstance("EUR")),
tip = Money(BigDecimal("5.00"), Currency.getInstance("EUR")),
language = LanguageIso6391.ES
)Interpreting the PaymentResult
When the repository call is successful (RepositoryResult.Success), it returns a PaymentResult object. You must check this object to determine if the financial operation was actually approved or denied by the bank.
The PaymentResult is a sealed interface with three possible states:
1. Accepted (PaymentResult.Accepted)
The payment was authorized by the host.
- Data: Contains a
Transactionobject with full details (card used, authorization code, receipt data). - Action: Print the receipt and complete the sale in your app.
2. Denied (PaymentResult.Denied)
The payment was rejected by the host or bank.
- Data: Contains a
Transactionobject (often with a rejection reason). - Action: Inform the user the card was declined.
3. Card Not Found (PaymentResult.CardNotFound)
Specific error for manual entry flows where the entered card number does not exist.
Example Handling Logic
fun handlePaymentResult(paymentResult: PaymentResult) {
when (paymentResult) {
is PaymentResult.Accepted -> {
val transaction = paymentResult.data
val authCode = transaction.operationInfo.authorizationNumber
println("✅ Payment Approved! Auth Code: $authCode")
// Proceed to print ticket...
}
is PaymentResult.Denied -> {
val transaction = paymentResult.data
val reason = transaction.operationInfo.failedReasonInfo?.desc ?: "Unknown"
println("❌ Payment Denied. Reason: $reason")
}
is PaymentResult.CardNotFound -> {
println("❌ Error: Card not found.")
}
}
}Next Steps
- Create a Pre-Authorized Payment: Learn about reserving funds on a card.
- Refund a Payment: How to return funds if a payment was made in error.