Skip to content
Open
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
16 changes: 16 additions & 0 deletions app/src/main/kotlin/io/hyperswitch/react/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
class Utils {
Expand Down Expand Up @@ -88,6 +90,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 {
Expand All @@ -102,6 +117,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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down