From 6712f4c6417add39fd4a0453fb56648b94976411 Mon Sep 17 00:00:00 2001 From: Kuntimaddi Manideep Date: Mon, 1 Dec 2025 14:10:23 +0530 Subject: [PATCH] chore: disable gpay for non-google devices --- .../main/kotlin/io/hyperswitch/react/Utils.kt | 16 ++++++++++++++++ .../hyperswitch/paymentsession/LaunchOptions.kt | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app/src/main/kotlin/io/hyperswitch/react/Utils.kt b/app/src/main/kotlin/io/hyperswitch/react/Utils.kt index 2c817e49..40b33c4a 100644 --- a/app/src/main/kotlin/io/hyperswitch/react/Utils.kt +++ b/app/src/main/kotlin/io/hyperswitch/react/Utils.kt @@ -8,6 +8,8 @@ import android.os.Parcelable import android.webkit.WebSettings import androidx.fragment.app.FragmentActivity import com.facebook.react.ReactFragment +import com.google.android.gms.common.ConnectionResult +import com.google.android.gms.common.GoogleApiAvailability import io.hyperswitch.BuildConfig import java.util.Locale enum class SDKEnvironment{SANDBOX,PROD} @@ -90,6 +92,19 @@ class Utils { ipAddress shr 24 and 0xff ) } + private fun isGooglePlayServicesAvailable(context: Context?): Boolean { + try { + context?.let { + val availability = GoogleApiAvailability.getInstance() + val result = availability.isGooglePlayServicesAvailable(context) + return result == ConnectionResult.SUCCESS + } + return true + } catch (_: Exception) { + return false + } + } + // Get launch options for React Native fragment private fun getLaunchOptions(request: Bundle, message: String, context: FragmentActivity): Bundle { @@ -104,6 +119,7 @@ class Utils { hyperParams.putString("os_type", "android") hyperParams.putString("os_version", Build.VERSION.RELEASE) hyperParams.putString("deviceBrand", Build.BRAND) + hyperParams.putBoolean("gPaySupport", isGooglePlayServicesAvailable(context)) request.putBundle("hyperParams", hyperParams) val bundle = Bundle() diff --git a/hyperswitch-sdk-android-api/src/main/kotlin/io/hyperswitch/paymentsession/LaunchOptions.kt b/hyperswitch-sdk-android-api/src/main/kotlin/io/hyperswitch/paymentsession/LaunchOptions.kt index 6ea8167b..deb2e386 100644 --- a/hyperswitch-sdk-android-api/src/main/kotlin/io/hyperswitch/paymentsession/LaunchOptions.kt +++ b/hyperswitch-sdk-android-api/src/main/kotlin/io/hyperswitch/paymentsession/LaunchOptions.kt @@ -8,6 +8,8 @@ import android.view.View import android.view.WindowInsets import android.webkit.WebSettings import androidx.annotation.RequiresApi +import com.google.android.gms.common.ConnectionResult +import com.google.android.gms.common.GoogleApiAvailability import io.hyperswitch.PaymentConfiguration import io.hyperswitch.paymentsheet.PaymentSheet import org.json.JSONObject @@ -17,6 +19,19 @@ class LaunchOptions( private val sdkVersion: String ) { + private fun isGooglePlayServicesAvailable(context: Context?): Boolean { + try { + context?.let { + val availability = GoogleApiAvailability.getInstance() + val result = availability.isGooglePlayServicesAvailable(context) + return result == ConnectionResult.SUCCESS + } + return true + } catch (_: Exception) { + return false + } + } + private fun getHyperParams(configuration: PaymentSheet.Configuration? = null): Bundle = Bundle().apply { putString("appId", context?.packageName) @@ -28,6 +43,7 @@ class LaunchOptions( putString("os_type", "android") putString("os_version", Build.VERSION.RELEASE) putString("deviceBrand", Build.BRAND) + putBoolean("gPaySupport", isGooglePlayServicesAvailable(context)) val edgeInsets = getBottomInset(context) if(edgeInsets!=null) { putFloat("topInset", edgeInsets.top)