Set the PrimerCheckoutListener in order to receive different callbacks from Primer SDK.
Callbacks can be used for managing the customer journey and trigger actions after specific events
throughout the payment journey. See below for a breakdown of all callbacks supported within the Primer SDK.
This method will be called just before the payment gets created, and lets you decide whether you want to proceed
with the payment creation.
This method will be called only when using the PrimerPaymentHandling.AUTOflow. Please note,
that if you override this method, you must call one of the
decisionHandler’s methods.
KOTLIN
Copy
Ask AI
fun onBeforePaymentCreated( paymentMethodData: PrimerPaymentMethodData, decisionHandler: PrimerPaymentCreationDecisionHandler)
Call abortPaymentCreation(errorMessage) when you want to abort the payment. Optionally you can provide an error message to get presented on the error screen.
This method will be called with the when the payment method has been is tokenized,
returning the payment method’s tokenization data. Use the token to create a payment on your backend.
Make sure that you call the decisionHandler once your operation has been completed.
This method will be called when you are using
PrimerPaymentHandling.MANUALflow, or the
PrimerSessionIntent.VAULTsession
intent.
KOTLIN
Copy
Ask AI
fun onTokenizeSuccess( paymentMethodTokenData: PrimerPaymentMethodTokenData, decisionHandler: PrimerResumeDecisionHandler)
class CheckoutActivity : AppCompatActivity() { // 👇 Add this private val listener = object : PrimerCheckoutListener { // 👇 Add this override fun onTokenizeSuccess( paymentMethodTokenData: PrimerPaymentMethodTokenData, decisionHandler: PrimerResumeDecisionHandler ) { // Create your payment val paymentResponse = //... if (paymentResponse.isSuccessful()) { // 👇 Call the decisionHandler to show the success screen decisionHandler.handleSuccess() } else if (paymentResponse.isPending()) { // 👇 Call the decisionHandler with the new client token to continue the flow decisionHandler.continueWithNewClientToken(paymentResponse.requiredAction.clientToken) } else { // 👇 Call the decisionHandler to show the error screen with your custom error message decisionHandler.handleFailure("Your error message.") } } }}
class CheckoutActivity : AppCompatActivity() { // 👇 Add this private val listener = object : PrimerCheckoutListener { // 👇 Add this override fun onResumeSuccess( resumeToken: String, decisionHandler: PrimerResumeDecisionHandler ) { // Resume your payment val paymentResponse = //... if (paymentResponse.isSuccessful()) { // 👇 Call the decisionHandler to show the success screen decisionHandler.handleSuccess() } else if (paymentResponse.isPending()) { // 👇 Call the decisionHandler with the new client token to continue the flow decisionHandler.continueWithNewClientToken(paymentResponse.requiredAction.clientToken) } else { // 👇 Call the decisionHandler to show the error screen with your custom error message decisionHandler.handleFailure("Your error message.") } } }}
This method will be called to notify you that the client session will be updated, e.g.
a surcharge needs to be applied when a payment method has been chosen.
This method will be called to notify you that the client session has been updated, e.g.
surcharge has been applied when a payment method has been chosen.
KOTLIN
Copy
Ask AI
fun onClientSessionUpdated(clientSession: PrimerClientSession)