Overview

Set the PrimerHeadlessUniversalCheckoutListener 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.

onAvailablePaymentMethodsLoaded

This method will return the payment methods that should be displayed based on the current client session data.

123
fun onAvailablePaymentMethodsLoaded(  paymentMethods: List<PrimerHeadlessUniversalCheckoutPaymentMethod>)
kotlin
copy

Parameters

paymentMethods
List<PrimerHeadlessUniversalCheckoutPaymentMethod>Required
Properties
paymentMethodType
StringRequired
A unique string identifier for the payment method.
supportedPrimerSessionIntents
List<PrimerSessionIntent>Required
A list of PrimerSessionIntent which defines what intents can be used with this payment method.
PrimerSessionIntent
paymentMethodManagerCategories
PrimerPaymentMethodManagerCategoryRequired
A list which defines the payment method managers that can be used with this payment method.
PrimerPaymentMethodManagerCategory

Indicates that the supported payment method manager for the payment method is PrimerHeadlessUniversalCheckoutNativeUiManager.

Indicates that the supported payment method manager for the payment method is PrimerHeadlessUniversalCheckoutRawDataManager.

requiredInputDataClass
KClass<out PrimerRawData>?

Indicates the subclass of the PrimerRawData that must be set using the PrimerHeadlessUniversalCheckoutRawManager.

onCheckoutCompleted

This method will be called when the payment has been completed, returning the payment' data.

⚠️

This method won't be called when you are using PrimerPaymentHandling.MANUAL flow, or the PrimerSessionIntent.VAULT session intent.

1
fun onCheckoutCompleted(checkoutData: PrimerCheckoutData)
kotlin
copy

Parameters

checkoutData
PrimerCheckoutDataRequired
payment
PaymentRequired
Properties
id
StringRequired
ID of created payment.
orderId
StringRequired
Order ID of created payment.
additionalInfo
PrimerCheckoutAdditionalInfo?
direct subclasses
Properties
expiresAt
StringRequired
couponCode
StringRequired
retailerName
StringRequired
Properties
expiresAt
StringRequired
qrCodeUrl
String?
qrCodeBase64
StringRequired
Properties
expiresAt
StringRequired
entity
StringRequired
reference
StringRequired

onBeforePaymentCreated

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.AUTO flow. Please note, that if you override this method, you must call one of the decisionHandler's methods.

1234
fun onBeforePaymentCreated(  paymentMethodData: PrimerPaymentMethodData,  decisionHandler: PrimerPaymentCreationDecisionHandler)
kotlin
copy

Parameters

paymentMethodType
StringRequired

A unique string identifier for the payment method. (e.g. PAYPAL, GOOGLE_PAY)

decisionHandler
PrimerPaymentCreationDecisionHandlerRequired
Methods

Call continuePaymentCreation() when you want to continue with the payment creation.

Call abortPaymentCreation(errorMessage) when you want to abort the payment. Optionally you can provide an error message to get presented on the error screen.

Example

123456789101112
class CheckoutActivity : AppCompatActivity() {    // 👇 Add this    private val listener = object : PrimerHeadlessUniversalCheckoutListener {      // 👇 Add this      override fun onBeforePaymentCreated(        paymentMethodData: PrimerPaymentMethodData,        decisionHandler: PrimerPaymentCreationDecisionHandler      ) {        decisionHandler.continuePaymentCreation()      }    }  }
kotlin
copy

onCheckoutAdditionalInfoReceived

This callback is trigger when the payment is not authorized as it’s an asynchronous alternative payment method, such as a voucher payment method.

⚠️

This method will be called only when using the PrimerPaymentHandling.AUTO flow.

1
fun onCheckoutAdditionalInfoReceived(additionalInfo: PrimerCheckoutAdditionalInfo)
kotlin
copy
additionalInfo
PrimerCheckoutAdditionalInfoRequired
direct subclasses
Properties
expiresAt
StringRequired
couponCode
StringRequired
retailerName
StringRequired
Properties
expiresAt
StringRequired
qrCodeUrl
String?
qrCodeBase64
StringRequired
Properties
expiresAt
StringRequired
entity
StringRequired
reference
StringRequired

onTokenizeSuccess

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.MANUAL flow, or the PrimerSessionIntent.VAULT session intent.

1234
fun onTokenizeSuccess(  paymentMethodTokenData: PrimerPaymentMethodTokenData,  decisionHandler: PrimerHeadlessUniversalCheckoutResumeDecisionHandler)
kotlin
copy

Parameters

paymentMethodTokenData
PrimerPaymentMethodTokenDataRequired
Properties
token
StringRequired
tokenType
TokenTypeRequired
Cases
analyticsId
StringRequired
paymentInstrumentType
StringRequired
paymentInstrumentData
PaymentInstrumentData?
Properties

A unique string identifier for the payment method. (e.g. PAYPAL, GOOGLE_PAY)

sessionInfo
SessionInfo?
The first 6 digits of the card number.
The last 4 digits of the card number.
The expiration month of the card, in 2-digit format.
The expiration year of the card, in 4-digit format.
The name of the cardholder.
network
String?
The human readable representation of card network (e.g., Visa, Mastercard).
binData
BinData?
Additional BIN data.
Properties
network
String?
The card network (e.g., VISA, MASTERCARD, AMEX).
externalPayerInfo
ExternalPayerInfo?
External information about the payer associated with the transaction.
Properties
email
String
The payer's email address.
The payer's unique ID.
firstName
String?
The payer's given name.
lastName
String
The payer's given surname.
sessionData
SessionData?
vaultData
VaultData?
threeDSecureAuthentication
AuthenticationDetails?
decisionHandler
PrimerHeadlessUniversalCheckoutResumeDecisionHandlerRequired
Methods

Call continueWithNewClientToken when the payment has entered in a PENDING state and a required action client token has been provided.

Example

12345678910111213141516171819202122
class CheckoutActivity : AppCompatActivity() {  // 👇 Add this  private val listener = object : PrimerHeadlessUniversalCheckoutListener {    // 👇 Add this    override fun onTokenizeSuccess(      paymentMethodTokenData: PrimerPaymentMethodTokenData,      decisionHandler: PrimerResumeDecisionHandler    ) {        // Create your payment        val paymentResponse =  //...        val paymentResponse =  //...          if (paymentResponse.isSuccessful()) {            // 👇 Show the success screen, fulfill the order etc..          } else if (paymentResponse.isPending()) {            // 👇 Call the decisionHandler with the new client token to continue the flow            decisionHandler.continueWithNewClientToken(paymentResponse.requiredAction.clientToken)          } else {            // 👇 Show the error screen, retry payment...          }    }  }}
kotlin
copy

onCheckoutResume

This method will be called providing a resumeToken so you can resume the payment.

⚠️

This method will be called when you are using PrimerPaymentHandling.MANUAL flow and when the payment is in a PENDING state.

1
fun onCheckoutResume(resumeToken: String, decisionHandler: PrimerHeadlessUniversalCheckoutResumeDecisionHandler)
kotlin
copy

Parameters

parameters
resumeToken
StringRequired
decisionHandler
PrimerHeadlessUniversalCheckoutResumeDecisionHandlerRequired
Methods

Call continueWithNewClientToken when the payment has entered in a PENDING state and a required action client token has been provided.

Example

123456789101112131415161718192021
class CheckoutActivity : AppCompatActivity() {  // 👇 Add this  private val listener = object : PrimerHeadlessUniversalCheckoutListener {    // 👇 Add this    override fun onResumeSuccess(      resumeToken: String,      decisionHandler: PrimerResumeDecisionHandler    ) {        // Resume your payment        val paymentResponse =  //...        if (paymentResponse.isSuccessful()) {          // 👇 Show the success screen, fulfill the order etc..        } else if (paymentResponse.isPending()) {          // 👇 Call the decisionHandler with the new client token to continue the flow          decisionHandler.continueWithNewClientToken(paymentResponse.requiredAction.clientToken)        } else {          // 👇 Show the error screen, retry payment...        }    }  }}
kotlin
copy

onResumePending

This callback is trigger when the payment is not authorized as it’s an asynchronous alternative payment method, such as a voucher payment method.

⚠️

This method will be called only when using the PrimerPaymentHandling.MANUAL flow.

1
fun onResumePending(additionalInfo: PrimerCheckoutAdditionalInfo)
kotlin
copy

Parameters

additionalInfo
PrimerCheckoutAdditionalInfoRequired
direct subclasses
Properties
expiresAt
StringRequired
couponCode
StringRequired
retailerName
StringRequired
Properties
expiresAt
StringRequired
qrCodeUrl
String?
qrCodeBase64
StringRequired
Properties
expiresAt
StringRequired
entity
StringRequired
reference
StringRequired

onBeforeClientSessionUpdated

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.

1
fun onBeforeClientSessionUpdated()
kotlin
copy

onClientSessionUpdated

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.

1
fun onClientSessionUpdated(clientSession: PrimerClientSession)
kotlin
copy

Parameters

clientSession
PrimerClientSessionRequired

onFailed

This method will be called when an error occurs. It may return PrimerCheckoutData if the error occurs after the payment creation.

1
fun onFailed(error: PrimerError, checkoutData: PrimerCheckoutData?)
kotlin
copy

Parameters

error
PrimerErrorRequired
Properties
errorId
StringRequired
A unique error identifier.
errorCode
String?
A unique error code.
description
StringRequired
A error description.
A recovery suggestion for the given error. In case it's present, use it to try to recover from error.
diagnosticsId
StringRequired
A unique diagnostics id for the given error.
checkoutData
PrimerCheckoutData?
Properties
payment
PaymentRequired
Properties
id
StringRequired
ID of created payment.
orderId
StringRequired
Order ID of created payment.
additionalInfo
PrimerCheckoutAdditionalInfo?
direct subclasses
Properties
expiresAt
StringRequired
couponCode
StringRequired
retailerName
StringRequired
Properties
expiresAt
StringRequired
qrCodeUrl
String?
qrCodeBase64
StringRequired
Properties
expiresAt
StringRequired
entity
StringRequired
reference
StringRequired