Add Google Pay button to custom view in your Android app

‚Äč  Last updated: 


Once you have configured the Google Pay manager, you can choose to add the Google Pay button in a custom view by adding the following code to your activity/fragment xml file:

//Add google pay custom view button to layout 
android:layout_height="wrap_content" />


For further customisation of the Google Pay button you can set the following options.

The first value shown is the default value (e.g. the buttonColor would default to black).



Verify that Google Pay is supported by customer device & configuration is valid

Please ensure that you call the following method to verify that Google Pay is correctly configured and that the Google Pay button should be made visible to the customer:

tpGooglePayManager.possiblyShowGooglePayButton(object : TPGooglePayManager.ShowGooglePayButtonCallback {
override fun canShowButton(boolean: Boolean) {
googlePayButton.visibility = View.VISIBLE
} else{
googlePayButton.visibility = View.GONE


Request a Google Wallet Token

Set up the Google Pay button to correctly display the Google Pay window:

googlePayButton.setOnClickListener {


Get a Google Pay wallet token. The token is needed in the subsequent steps when performing a payment authorisation request.

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == tpGooglePayManager.requestCode){
val googlePayWalletToken = tpGooglePayManager.onActivityResult(requestCode, resultCode, data)
//Use googlePayWalletToken for processing a payment authorisation


  Please proceed to the Requesting a payment authorisation page that details the approaches you can take to process the payment.

Was this article helpful?
0 out of 0 found this helpful