From 2098a9e966c98d3532a4d00d61aedf99fd34466e Mon Sep 17 00:00:00 2001 From: Charles Cruzan Date: Wed, 16 Mar 2022 15:44:20 -0400 Subject: [PATCH] fix: assign googlePayFragment on instantiation --- .../reactnativestripesdk/GooglePayFragment.kt | 3 --- .../reactnativestripesdk/StripeSdkModule.kt | 18 ++++++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt b/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt index fbf315d3f..9bcce32f6 100644 --- a/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt +++ b/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt @@ -87,9 +87,6 @@ class GooglePayFragment : Fragment() { readyCallback = ::onGooglePayLauncherReady, resultCallback = ::onGooglePayResult ) - - val intent = Intent(ON_GOOGLE_PAY_FRAGMENT_CREATED) - localBroadcastManager.sendBroadcast(intent) } fun presentForPaymentIntent(clientSecret: String) { diff --git a/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt b/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt index 2639426a9..0df2c3f64 100644 --- a/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +++ b/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt @@ -173,18 +173,17 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React private val googlePayReceiver: BroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent) { - if (intent.action == ON_GOOGLE_PAY_FRAGMENT_CREATED) { - currentActivity?.let { - googlePayFragment = it.supportFragmentManager.findFragmentByTag("google_pay_launch_fragment") as GooglePayFragment - } - } if (intent.action == ON_INIT_GOOGLE_PAY) { val isReady = intent.extras?.getBoolean("isReady") ?: false - if (isReady) { initGooglePayPromise?.resolve(WritableNativeMap()) } else { - initGooglePayPromise?.resolve(createError(GooglePayErrorType.Failed.toString(), "Google Pay is not available on this device")) + initGooglePayPromise?.resolve( + createError( + GooglePayErrorType.Failed.toString(), + "Google Pay is not available on this device. You can use isGooglePaySupported to preemptively check for Google Pay support." + ) + ) } } if (intent.action == ON_GOOGLE_PAYMENT_METHOD_RESULT) { @@ -305,7 +304,6 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React localBroadcastManager.registerReceiver(mPaymentSheetReceiver, IntentFilter(ON_CONFIGURE_FLOW_CONTROLLER)); localBroadcastManager.registerReceiver(mPaymentSheetReceiver, IntentFilter(ON_INIT_PAYMENT_SHEET)); - localBroadcastManager.registerReceiver(googlePayReceiver, IntentFilter(ON_GOOGLE_PAY_FRAGMENT_CREATED)) localBroadcastManager.registerReceiver(googlePayReceiver, IntentFilter(ON_INIT_GOOGLE_PAY)) localBroadcastManager.registerReceiver(googlePayReceiver, IntentFilter(ON_GOOGLE_PAY_RESULT)) localBroadcastManager.registerReceiver(googlePayReceiver, IntentFilter(ON_GOOGLE_PAYMENT_METHOD_RESULT)) @@ -641,7 +639,7 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React @ReactMethod fun initGooglePay(params: ReadableMap, promise: Promise) { - val fragment = GooglePayFragment().also { + googlePayFragment = GooglePayFragment().also { val bundle = toBundleObject(params) it.arguments = bundle } @@ -650,7 +648,7 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React initGooglePayPromise = promise it.supportFragmentManager.beginTransaction() - .add(fragment, "google_pay_launch_fragment") + .add(googlePayFragment!!, "google_pay_launch_fragment") .commit() } ?: run { promise.resolve(createMissingActivityError())