Learn about built-in validation and implement additional scenarios for Google Pay on Android.
The Google Pay component for Android includes comprehensive validation to ensure data integrity and compliance with Google's requirements. All built-in validation is performed before creating payment requests and during the Google Pay flow. If validation fails, the SDK will throw an exception with detailed information.
You can also easily build custom validation, depending on your business needs.
By default, the Google Pay component validates that:
- Fields marked as required are provided.
- Payment request data meets Google Pay API specifications.
- Currency codes, country codes, and amounts are formatted properly.
- Allowed payment methods and networks are properly configured.
- Transaction information is complete and valid.
- Android-specific requirements are met (Google Play Services, API level, permissions).
- Device compatibility requirements are met.
The Google Pay component returns structured error codes for different validation failures:
| Error code | Description | Common causes |
|---|---|---|
REQUIRED_FIELD | A required field is missing. | Missing mandatory configuration. |
INVALID_AMOUNT_FORMAT | The amount format is invalid. | Non-string or negative amount. |
INVALID_CURRENCY_CODE | The currency code is invalid. | Non-ISO 4217 currency format. |
INVALID_COUNTRY_CODE | The country code is invalid. | Non-ISO 3166-1 alpha-2 format. |
INVALID_PAYMENT_METHOD | Payment method configuration invalid. | Unsupported payment method type. |
INVALID_CARD_NETWORKS | Card networks invalid. | Unsupported network values. |
INVALID_AUTH_METHODS | Authentication methods invalid. | Unsupported auth method values. |
INVALID_TRANSACTION_INFO | Transaction info invalid. | Malformed transaction data. |
INVALID_TOTAL_PRICE_STATUS | Total price status invalid. | Invalid status value. |
GOOGLE_PAY_NOT_AVAILABLE | Google Pay not available. | Google Play Services not available. |
ANDROID_VERSION_TOO_LOW | Android version insufficient. | Device running Android < 7.0. |
MISSING_PERMISSIONS | Required permissions missing. | AndroidManifest.xml not configured. |
import android.util.Log
import com.pxp.checkout.components.googlepay.*
// Handle validation errors
val googlePayConfig = GooglePayButtonComponentConfig().apply {
// ... configuration
onError = { error ->
when (error) {
is GooglePayConfigurationValidationFailedException -> {
Log.e("GooglePay", "Configuration validation failed: ${error.message}")
// Handle specific validation errors
val message = error.message ?: ""
when {
message.contains("allowedPaymentMethods") -> {
Log.e("GooglePay", "Invalid payment methods configuration")
showError("Payment configuration error. Please contact support.")
}
message.contains("totalPrice") -> {
Log.e("GooglePay", "Invalid total price format")
showError("Payment amount error. Please refresh and try again.")
}
message.contains("gatewayMerchantId") || message.contains("merchant ID") -> {
Log.e("GooglePay", "Gateway merchant ID missing or invalid")
showError("Payment system configuration error. Please contact support.")
}
else -> {
showError("Payment configuration error.")
}
}
// Log for debugging
Log.e("GooglePay", "Validation error details: ${error.stackTraceToString()}")
}
else -> {
Log.e("GooglePay", "Payment error", error)
}
}
}
}