A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/google-pay/compose-pay-button below:

google-pay/compose-pay-button: An Android library that provides a Jetpack Compose wrapper on top of the Google Pay Button API.

Google Pay button for Jetpack Compose

An Android library that provides a Jetpack Compose wrapper on top of the Google Pay Button API.

The library is hosted on Maven central and can be used by ensuring the following lines exist in each gradle file:

build.gradle:

repositories {
    mavenCentral()
}

app/build.gradle:

dependencies {
    implementation "com.google.pay.button:compose-pay-button:<version>"
}
// other imports omitted for brevity
// see full example in the "app" directory

import com.google.pay.button.ButtonTheme
import com.google.pay.button.ButtonType
import com.google.pay.button.PayButton

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val onClick = { println("Button clicked") }

        // as per https://developers.google.com/pay/api/android/reference/request-objects#PaymentMethod
        val allowedPaymentMethods = """
            [
              {
                "type": "CARD",
                "parameters": {
                  "allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
                  "allowedCardNetworks": ["AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"]
                },
                "tokenizationSpecification": {
                  "type": "PAYMENT_GATEWAY",
                  "parameters": {
                    "gateway": "example",
                    "gatewayMerchantId": "exampleGatewayMerchantId"
                  }
                }
              }
            ]
        """.trimIndent()

        setContent {
            // Default
            PayButton(onClick = onClick, allowedPaymentMethods = allowedPaymentMethods)

            // Customized look
            PayButton(
                onClick = onClick,
                allowedPaymentMethods = allowedPaymentMethods,
                radius = 1.dp,
                modifier = Modifier.width(200.dp),
                theme = ButtonTheme.Light
            )

            // Customized labels
            PayButton(onClick = onClick, allowedPaymentMethods = allowedPaymentMethods, type = ButtonType.Book)
            PayButton(onClick = onClick, allowedPaymentMethods = allowedPaymentMethods, type = ButtonType.Subscribe)
            PayButton(onClick = onClick, allowedPaymentMethods = allowedPaymentMethods, type = ButtonType.Donate)
        }
    }
}
Error handling and Fallback UI

The PayButton composable wraps the underlying PayButton Android View, which may encounter errors during initialization. To handle these situations, the PayButton composable provides:

This mechanism ensures that your app can gracefully handle potential issues with the PayButton and provide a fallback experience to the user.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4