Callbacks & Results¶
In this guide
The two callback interfaces the SDK uses, and the fields on the result and error objects they hand back.
The SDK uses callbacks so the host app receives results on the main thread.
You are already on the main thread
Callbacks are delivered on the main thread, so you can update UI directly without posting back to a handler.
PaymentCallback¶
Used by checkout() and payWithCard().
interface PaymentCallback {
fun onSuccess(result: PaymentResult)
fun onFailure(error: PaymentError)
fun onCancelled()
}
Exactly one method is called for each payment attempt.
OperationCallback¶
Used by status, capture, void, refund, merchant transactions, recurring transactions, and recurring charges.
Transport success is not payment success
onSuccess means the request completed at the transport layer. Always inspect
the business fields such as status, result, or paymentStatus to know the
real outcome.
Shared Helper¶
You can create a small helper to avoid repeating error handling.
private fun <T> operationCallback(onSuccess: (T) -> Unit) =
object : OperationCallback<T> {
override fun onSuccess(result: T) = onSuccess(result)
override fun onFailure(error: PaymentError) {
// Log error.code and show error.message when appropriate.
}
}
PaymentResult¶
sessionId- Checkout session or payment id. Use it as
paymentIdfor later operations. transactionId- Gateway transaction id, for reconciliation and records.
orderId- Merchant order id.
amount- Paid amount.
currency- Payment currency.
status- Gateway status.
PaymentError¶
code- Stable
ErrorCodeenum for programmatic handling — see Error Handling. message- User or support-facing message.
details- Optional additional gateway or diagnostic detail.
Handle by code, display message
Branch your logic on code (stable), and show message to users. Log
details for diagnostics — but never log full card data.