Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GoogleWalletImplementation(
try {
// Inicializar TapAndPayClient diretamente (sem reflexão!)
tapAndPayClient = TapAndPay.getClient(reactContext)

// Inicializar WalletOpener
walletOpener = WalletOpener(reactContext)

Expand Down Expand Up @@ -74,7 +74,7 @@ class GoogleWalletImplementation(
} else {
WalletLogger.d(TAG, "🔍 [GOOGLE] Intent data é null")
}

WalletLogger.i(TAG, "Push tokenize OK - Retornando resolve vazio")
resolve(null)
}
Expand All @@ -89,7 +89,7 @@ class GoogleWalletImplementation(
val errorCodeName = ErrorCode.getErrorCodeName(resultCode)
val message = ErrorCode.getErrorMessage(resultCode)
val errorMessage = "$message ($errorCodeName) - result_code:$resultCode"

WalletLogger.w(TAG, "PUSH_TOKENIZE_ERROR: $errorMessage")
reject("PUSH_TOKENIZE_ERROR", errorMessage)
}
Expand All @@ -109,7 +109,7 @@ class GoogleWalletImplementation(
val errorCodeName = ErrorCode.getErrorCodeName(resultCode)
val message = ErrorCode.getErrorMessage(resultCode)
val errorMessage = "$message ($errorCodeName) - result_code:$resultCode"

WalletLogger.w(TAG, "CREATE_WALLET_ERROR: $errorMessage")
reject("CREATE_WALLET_ERROR", errorMessage)
}
Expand All @@ -135,13 +135,13 @@ class GoogleWalletImplementation(
WalletLogger.w(TAG, "❌ [GOOGLE] Android ${Build.VERSION.SDK_INT} não suportado. Versão mínima requerida: Android 9.0 (API ${MIN_ANDROID_VERSION})")
return false
}

// Verificar se o cliente TapAndPay está inicializado
if (tapAndPayClient == null) {
WalletLogger.w(TAG, "❌ [GOOGLE] Cliente TapAndPay não foi inicializado")
return false
}

WalletLogger.d(TAG, "✅ [GOOGLE] Android ${Build.VERSION.SDK_INT} suportado e SDK disponível")
return true
}
Expand Down Expand Up @@ -547,10 +547,10 @@ class GoogleWalletImplementation(
try {
intentListenerActive = true
checkPendingDataFromMainActivity()

// Processar eventos de nenhuma intent pendentes
GoogleWalletModule.processNoIntentReceivedEvent(reactContext)

promise.resolve(true)
} catch (e: Exception) {
WalletLogger.e(TAG, "SET_INTENT_LISTENER_ERROR: ${e.message}", e)
Expand Down Expand Up @@ -634,7 +634,7 @@ class GoogleWalletImplementation(
val webUrl = GOOGLE_WALLET_PLAY_STORE_URL

val success = walletOpener!!.openWallet(packageName, appName, playStoreUrl, webUrl)

if (success) {
WalletLogger.d(TAG, "✅ [GOOGLE] Wallet aberto com sucesso")
promise.resolve(true)
Expand Down Expand Up @@ -725,33 +725,33 @@ class GoogleWalletImplementation(
try {
// Verificar se há dados pendentes
val hasData = hasPendingData()

if (hasData) {
WalletLogger.d(TAG, "✅ [GOOGLE] Dados pendentes encontrados")

// Obter os dados pendentes sem limpar
val data = getPendingIntentDataWithoutClearing()
val action = getPendingIntentAction()
val callingPackage = getPendingCallingPackage()

if (data != null && data.isNotEmpty()) {
WalletLogger.d(TAG, "📋 [GOOGLE] Processando dados pendentes: ${data.length} caracteres")
WalletLogger.d(TAG, "📋 [GOOGLE] Action: $action, CallingPackage: $callingPackage")

// Verificar se action e callingPackage estão disponíveis
if (action == null) {
WalletLogger.e(TAG, "❌ [GOOGLE] Action é null - não é possível processar intent")
return
}

if (callingPackage == null) {
WalletLogger.e(TAG, "❌ [GOOGLE] CallingPackage é null - não é possível processar intent")
return
}

// Processar os dados como um intent usando os valores reais
processWalletIntentData(data, action, callingPackage)

// Limpar dados após processamento bem-sucedido
clearPendingData()
} else {
Expand All @@ -772,18 +772,18 @@ class GoogleWalletImplementation(
WalletLogger.d(TAG, "🔍 [GOOGLE] processWalletIntentData chamado")
try {
WalletLogger.d(TAG, "✅ [GOOGLE] Intent processado: $action")

// Determinar o tipo de intent baseado na action
val intentType = if (action.endsWith(".action.ACTIVATE_TOKEN")) {
"ACTIVATE_TOKEN"
} else {
"WALLET_INTENT"
}

// Decodificar dados de base64 para string normal
var decodedData = data
var dataFormat = "raw"

try {
// Tentar decodificar como base64
val decodedBytes = android.util.Base64.decode(data, android.util.Base64.DEFAULT)
Expand All @@ -795,22 +795,22 @@ class GoogleWalletImplementation(
WalletLogger.w(TAG, "⚠️ [GOOGLE] Não foi possível decodificar como base64, usando dados originais: ${e.message}")
dataFormat = "raw"
}

val eventData = Arguments.createMap()
eventData.putString("action", action)
eventData.putString("type", intentType)
eventData.putString("data", decodedData)
eventData.putString("dataFormat", dataFormat)
eventData.putString("callingPackage", callingPackage)

// Adicionar dados originais em base64 para referência
eventData.putString("originalData", data)

WalletLogger.d(TAG, "🔍 [GOOGLE] Evento preparado - Action: $action, Type: $intentType, Format: $dataFormat")

// Enviar evento para React Native
sendEventToReactNative("GoogleWalletIntentReceived", eventData)

} catch (e: Exception) {
WalletLogger.e(TAG, "❌ [GOOGLE] Erro ao processar dados da intent: ${e.message}", e)
}
Expand Down Expand Up @@ -864,22 +864,22 @@ class GoogleWalletImplementation(
private const val GOOGLE_WALLET_PACKAGE = "com.google.android.gms"
private const val GOOGLE_WALLET_APP_PACKAGE = "com.google.android.apps.walletnfcrel"
private val GOOGLE_WALLET_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=$GOOGLE_WALLET_APP_PACKAGE&hl=pt_BR"

// Versão mínima do Android suportada pelo Google Wallet: Android 9.0 (Pie) - API level 28
private const val MIN_ANDROID_VERSION = Build.VERSION_CODES.P

// Variáveis estáticas para armazenar dados da intent
@Volatile
private var pendingIntentData: String? = null
@Volatile
private var pendingIntentAction: String? = null
@Volatile
private var pendingCallingPackage: String? = null

// Flag para indicar se há dados pendentes
@Volatile
private var hasPendingIntentData: Boolean = false

@JvmStatic
fun getPendingIntentData(): String? {
val data = pendingIntentData
Expand All @@ -892,50 +892,50 @@ class GoogleWalletImplementation(
}
return data
}

@JvmStatic
fun getPendingIntentAction(): String? = pendingIntentAction

@JvmStatic
fun getPendingCallingPackage(): String? = pendingCallingPackage

@JvmStatic
fun getPendingIntentDataWithoutClearing(): String? = pendingIntentData

@JvmStatic
fun clearPendingData() {
pendingIntentData = null
pendingIntentAction = null
pendingCallingPackage = null
hasPendingIntentData = false
}

@JvmStatic
fun hasPendingData(): Boolean = hasPendingIntentData

@JvmStatic
fun processIntent(activity: Activity, intent: Intent) {
WalletLogger.d(TAG, "🔍 [GOOGLE] processIntent chamado")

WalletLogger.d(TAG, "🔍 [GOOGLE] Intent encontrada: ${intent.action}")

// Verificar se é um intent do Google Pay/Wallet
if (isGooglePayIntent(intent)) {
WalletLogger.d(TAG, "✅ [GOOGLE] Intent do Google Pay detectada")

// Extrair dados da intent
val extraText = intent.getStringExtra(Intent.EXTRA_TEXT)
if (!extraText.isNullOrEmpty()) {
WalletLogger.d(TAG, "🔍 [GOOGLE] Dados EXTRA_TEXT encontrados: ${extraText.length} caracteres")

// Armazenar dados para processamento posterior
pendingIntentData = extraText
pendingIntentAction = intent.action
pendingCallingPackage = activity.callingPackage
hasPendingIntentData = true

WalletLogger.d(TAG, "✅ [GOOGLE] Dados armazenados para processamento - Action: ${intent.action}, CallingPackage: ${activity.callingPackage}")

// Limpar intent para evitar reprocessamento
activity.intent = Intent()
} else {
Expand All @@ -945,18 +945,18 @@ class GoogleWalletImplementation(
WalletLogger.d(TAG, "🔍 [GOOGLE] Intent não relacionada ao Google Pay")
}
}

/**
* Verifica se uma intent é relacionada ao Google Pay/Wallet
*/
private fun isGooglePayIntent(intent: Intent): Boolean {
val action = intent.action

WalletLogger.d(TAG, "🔍 [GOOGLE] Verificando intent - Action: $action")

// Verificar action
val isValidAction = action != null && action.endsWith(".action.ACTIVATE_TOKEN")

return isValidAction
}

Expand All @@ -967,7 +967,7 @@ class GoogleWalletImplementation(
fun isValidCallingPackage(activity: Activity): Boolean {
val callingPackage = activity.callingPackage
WalletLogger.d(TAG, "🔍 [GOOGLE] Chamador: $callingPackage")

return callingPackage != null && (callingPackage == GOOGLE_WALLET_PACKAGE || callingPackage == GOOGLE_WALLET_APP_PACKAGE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object ErrorCode {
CommonStatusCodes.CONNECTION_SUSPENDED_DURING_CALL -> "CONNECTION_SUSPENDED_DURING_CALL"
CommonStatusCodes.RECONNECTION_TIMED_OUT_DURING_UPDATE -> "RECONNECTION_TIMED_OUT_DURING_UPDATE"
CommonStatusCodes.RECONNECTION_TIMED_OUT -> "RECONNECTION_TIMED_OUT"

// TapAndPay Status Codes
TapAndPayStatusCodes.TAP_AND_PAY_NO_ACTIVE_WALLET -> "TAP_AND_PAY_NO_ACTIVE_WALLET"
TapAndPayStatusCodes.TAP_AND_PAY_TOKEN_NOT_FOUND -> "TAP_AND_PAY_TOKEN_NOT_FOUND"
Expand All @@ -42,11 +42,11 @@ object ErrorCode {
TapAndPayStatusCodes.TAP_AND_PAY_PAYMENT_CREDENTIALS_DELIVERY_TIMEOUT -> "TAP_AND_PAY_PAYMENT_CREDENTIALS_DELIVERY_TIMEOUT"
TapAndPayStatusCodes.TAP_AND_PAY_USER_CANCELED_FLOW -> "TAP_AND_PAY_USER_CANCELED_FLOW"
TapAndPayStatusCodes.TAP_AND_PAY_ENROLL_FOR_VIRTUAL_CARDS_FAILED -> "TAP_AND_PAY_ENROLL_FOR_VIRTUAL_CARDS_FAILED"

else -> "UNKNOWN_ERROR_$errorCode"
}
}

fun getErrorMessage(errorCode: Int): String {
return when (errorCode) {
// Common Status Codes - Mensagens amigáveis
Expand All @@ -69,7 +69,7 @@ object ErrorCode {
CommonStatusCodes.CONNECTION_SUSPENDED_DURING_CALL -> "Conexão suspensa durante chamada"
CommonStatusCodes.RECONNECTION_TIMED_OUT_DURING_UPDATE -> "Tempo de reconexão esgotado durante atualização"
CommonStatusCodes.RECONNECTION_TIMED_OUT -> "Tempo de reconexão esgotado"

// TapAndPay Status Codes - Mensagens amigáveis
TapAndPayStatusCodes.TAP_AND_PAY_NO_ACTIVE_WALLET -> "Nenhuma carteira ativa"
TapAndPayStatusCodes.TAP_AND_PAY_TOKEN_NOT_FOUND -> "Token não encontrado"
Expand All @@ -85,7 +85,7 @@ object ErrorCode {
TapAndPayStatusCodes.TAP_AND_PAY_PAYMENT_CREDENTIALS_DELIVERY_TIMEOUT -> "Tempo limite de entrega de credenciais"
TapAndPayStatusCodes.TAP_AND_PAY_USER_CANCELED_FLOW -> "Usuário cancelou a operação"
TapAndPayStatusCodes.TAP_AND_PAY_ENROLL_FOR_VIRTUAL_CARDS_FAILED -> "Falha ao registrar cartões virtuais"

else -> "Erro desconhecido"
}
}
Expand Down
Loading