Cards & Wallets · Mobile SDK · UI Components

Google Pay Button

The GooglePayButton component
The GooglePayButton component
Android only.

The GooglePayButton is a Composable function used to render a button that initiates a Google Pay payment. It is optional — you can control your own button UI instead.

Parameters

ParameterDescription
modifierThe modifier to apply to this layout.
radiusThe corner radius of the button.
buttonTypeThe type of button to display.
billingAddressThe billing address to use for the payment.

Example usage

Compose Multiplatform

Kotlin
GooglePayButton(
  modifier = Modifier,
  radius = 16.dp,
  buttonType = GooglePayButtonType.Pay,
  billingAddress = billingAddress
)

Android View

XML
<com.accesspaysuite.mobilesdk.ui.googlepay.GooglePayButtonView
  android:id="@+id/googlePayButton"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />
Kotlin
val googlePayButton = findViewById<GooglePayButtonView>(R.id.googlePayButton)
googlePayButton.billingAddress = myBillingAddress
googlePayButton.radius = 24.dp
googlePayButton.buttonType = GooglePayButtonType.Pay

Using your own button

You are not limited to our Google Pay button — you can use any button or UI you like. You will, however, need to launch a specific function to do so.

Requirements

  • The PaymentResultCallback must be set before starting a Google Pay payment
  • The PaymentProcessor must be initiated before starting a Google Pay payment
  • Google Pay must be an accepted payment method

Compose

Use the following composable-scoped function in your UI screen. It is available at com.accesspaysuite.mobilesdk.modules.InitiateGooglePay.

Kotlin
InitiateGooglePay()

Android Activity

Use the following function in your Activity root class. The same function is available for ComponentActivity-inherited activities and fragments.

Kotlin
...
import com.accesspaysuite.mobilesdk.modules.initiateGooglePay

class MainActivity : ComponentActivity() {
  ...
  @Suppress("unused")
  private val _initiateGooglePay = initiateGooglePay()

  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      ...
  }
}

Android Fragment

Kotlin
...
import com.accesspaysuite.mobilesdk.modules.initiateGooglePay

class FragmentGooglePay: Fragment() {

  @Suppress("unused")
  private val _initiateGooglePay = initiateGooglePay()

  override fun onCreateView(
      inflater: LayoutInflater,
      container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View? {
      return ...
  }
}

Starting the payment

Using the payment processor class, run the following method:

Kotlin
processor.processGooglePayPayment(billingAddress)