Add Google Pay button to Drop-In View for Android SDK

Firstly you will need to add DropInPaymentView in your activity xml file:

android:padding="20dp" />


The following example code demonstrates how you can add the Google Pay button inside of the payment SDK's pre-built Drop-In view. The onActivityResult (i.e. the Google Pay wallet token) will need to be submitted in a payment authorisation request to Trust Payments for a payment to be completed. Please refer to the Requesting a payment authorisation page when you’re ready to process a payment.

// Need to implement the DropInPaymentView.DropInGooglePayPaymentViewListener
class YourActivity : Activity, DropInPaymentView.DropInGooglePayPaymentViewListener {
private lateinit var tpGooglePayManager : TPGooglePayManager

// Example interface implementation
override fun onGooglePayClicked() {
override fun onCreate(savedInstanceState: Bundle?) {

// creating the Google Pay manager instance
tpGooglePayManager = TPGooglePayManager.Builder(

// Verify that Google Pay is supported by customer device & configuration is valid
tpGooglePayManager.possiblyShowGooglePayButton(object : TPGooglePayManager.ShowGooglePayButtonCallback {
override fun canShowButton(boolean: Boolean) {
dropInPaymentView.apply {
setupForTokenizedPayment(emptySet(), null) // Use with the line bellow to hide card payment form

// Register the interface implementation in the drop-in payment view
dropInGooglePayPaymentViewListener = this@YourActivity
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
val googlePayWalletToken = tpGooglePayManager.onActivityResult(requestCode, resultCode, data)
//Use googlePayWalletToken for processing a payment authorisation
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request