The PayMaya Android SDK returns payment results through the standard Android Activity result mechanism. Each payment type has its own result class with Success, Cancel, and Failure states.
The Checkout payment returns one of three result types:
PayMayaCheckoutResult.kt
sealed class PayMayaCheckoutResult(open val checkoutId: String?) { /** * Success result of the Checkout payment. */ class Success internal constructor( override val checkoutId: String ) : PayMayaCheckoutResult(checkoutId) /** * Canceled result of the Checkout payment. */ class Cancel internal constructor( override val checkoutId: String? = null ) : PayMayaCheckoutResult(checkoutId) /** * Failed result of the Checkout payment. */ class Failure internal constructor( override val checkoutId: String? = null, val exception: Exception ) : PayMayaCheckoutResult(checkoutId)}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { payMayaCheckoutClient.onActivityResult(requestCode, resultCode, data)?.let { processCheckoutResult(it) }}private fun processCheckoutResult(result: PayMayaCheckoutResult) { when (result) { is PayMayaCheckoutResult.Success -> { val message = "Success, checkoutId: ${result.checkoutId}" Toast.makeText(this, message, Toast.LENGTH_LONG).show() } is PayMayaCheckoutResult.Cancel -> { val message = "Canceled, checkoutId: ${result.checkoutId}" Toast.makeText(this, message, Toast.LENGTH_LONG).show() } is PayMayaCheckoutResult.Failure -> { val message = "Failure, checkoutId: ${result.checkoutId}, exception: ${result.exception}" if (result.exception is BadRequestException) { Log.d(TAG, (result.exception as BadRequestException).error.toString()) } Toast.makeText(this, message, Toast.LENGTH_LONG).show() } }}
The checkoutId is always available in Success results, but may be null in Cancel or Failure results if the payment didn’t progress far enough to receive an ID.
sealed class SinglePaymentResult : PayWithPayMayaResult() { /** * Success result of the Single Payment. */ class Success internal constructor( val paymentId: String ) : SinglePaymentResult() /** * Canceled result of the Single Payment. */ class Cancel internal constructor( val paymentId: String? = null ) : SinglePaymentResult() /** * Failed result of the Single Payment. */ class Failure internal constructor( val paymentId: String? = null, val exception: Exception ) : SinglePaymentResult()}
sealed class CreateWalletLinkResult : PayWithPayMayaResult() { /** * Success result of the creation of the wallet link. */ class Success internal constructor( val linkId: String ) : CreateWalletLinkResult() /** * Canceled result of the creation of the wallet link. */ class Cancel internal constructor( val linkId: String? = null ) : CreateWalletLinkResult() /** * Failed result of the creation of the wallet link. */ class Failure internal constructor( val linkId: String? = null, val exception: Exception ) : CreateWalletLinkResult()}
sealed class PayMayaVaultResult { /** * Success result of the card tokenization process. */ class Success internal constructor( val paymentTokenId: String, val state: String, val createdAt: String, val updatedAt: String, val issuer: String ) : PayMayaVaultResult() /** * Canceled result of the card tokenization process. */ object Cancel : PayMayaVaultResult()}
Vault does not return a Failure result. Card validation errors are shown in the vault UI.
When users close a payment activity (e.g., by pressing Back), the SDK automatically checks the payment status if a transaction ID was already received.