Skip to content

Data validation

Learn about built-in validation and implement additional scenarios for Google Pay on Android.

Overview

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.

Built-in validation

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.

Error codes

The Google Pay component returns structured error codes for different validation failures:

Error codeDescriptionCommon causes
REQUIRED_FIELDA required field is missing.Missing mandatory configuration.
INVALID_AMOUNT_FORMATThe amount format is invalid.Non-string or negative amount.
INVALID_CURRENCY_CODEThe currency code is invalid.Non-ISO 4217 currency format.
INVALID_COUNTRY_CODEThe country code is invalid.Non-ISO 3166-1 alpha-2 format.
INVALID_PAYMENT_METHODPayment method configuration invalid.Unsupported payment method type.
INVALID_CARD_NETWORKSCard networks invalid.Unsupported network values.
INVALID_AUTH_METHODSAuthentication methods invalid.Unsupported auth method values.
INVALID_TRANSACTION_INFOTransaction info invalid.Malformed transaction data.
INVALID_TOTAL_PRICE_STATUSTotal price status invalid.Invalid status value.
GOOGLE_PAY_NOT_AVAILABLEGoogle Pay not available.Google Play Services not available.
ANDROID_VERSION_TOO_LOWAndroid version insufficient.Device running Android < 7.0.
MISSING_PERMISSIONSRequired permissions missing.AndroidManifest.xml not configured.

Validation example

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)
            }
        }
    }
}