11package com.stripe.android.paymentelement.confirmation.gpay
22
33import androidx.activity.result.ActivityResultCaller
4- import androidx.activity.result.ActivityResultLauncher
54import com.stripe.android.core.strings.resolvableString
65import com.stripe.android.core.utils.FeatureFlags
76import com.stripe.android.core.utils.UserFacingLogger
87import com.stripe.android.googlepaylauncher.GooglePayEnvironment
98import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher
109import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncherContractV2
11- import com.stripe.android.googlepaylauncher.injection.GooglePayPaymentMethodLauncherFactory
10+ import com.stripe.android.googlepaylauncher.InternalGooglePayPaymentMethodLauncher
11+ import com.stripe.android.googlepaylauncher.injection.InternalGooglePayPaymentMethodLauncherFactory
1212import com.stripe.android.model.PaymentIntent
1313import com.stripe.android.model.SetupIntent
1414import com.stripe.android.model.StripeIntent
@@ -18,17 +18,15 @@ import com.stripe.android.paymentelement.confirmation.EmptyConfirmationLauncherA
1818import com.stripe.android.paymentelement.confirmation.PaymentMethodConfirmationOption
1919import com.stripe.android.paymentsheet.PaymentSheet
2020import com.stripe.android.paymentsheet.R
21- import kotlinx.coroutines.CoroutineScope
22- import kotlinx.coroutines.Dispatchers
2321import javax.inject.Inject
2422import com.stripe.android.R as PaymentsCoreR
2523
2624internal class GooglePayConfirmationDefinition @Inject constructor(
27- private val googlePayPaymentMethodLauncherFactory : GooglePayPaymentMethodLauncherFactory ,
25+ private val googlePayPaymentMethodLauncherFactory : InternalGooglePayPaymentMethodLauncherFactory ,
2826 private val userFacingLogger : UserFacingLogger ? ,
2927) : ConfirmationDefinition<
3028 GooglePayConfirmationOption ,
31- ActivityResultLauncher < GooglePayPaymentMethodLauncherContractV2 . Args > ,
29+ InternalGooglePayPaymentMethodLauncher ,
3230 EmptyConfirmationLauncherArgs ,
3331 GooglePayPaymentMethodLauncher .Result ,
3432 > {
@@ -67,39 +65,41 @@ internal class GooglePayConfirmationDefinition @Inject constructor(
6765 override fun createLauncher (
6866 activityResultCaller : ActivityResultCaller ,
6967 onResult : (GooglePayPaymentMethodLauncher .Result ) -> Unit
70- ): ActivityResultLauncher < GooglePayPaymentMethodLauncherContractV2 . Args > {
71- return activityResultCaller.registerForActivityResult(
68+ ): InternalGooglePayPaymentMethodLauncher {
69+ val activityResultLauncher = activityResultCaller.registerForActivityResult(
7270 GooglePayPaymentMethodLauncherContractV2 (),
7371 onResult,
7472 )
73+
74+ return googlePayPaymentMethodLauncherFactory.create(
75+ activityResultLauncher = activityResultLauncher,
76+ )
7577 }
7678
7779 override fun launch (
78- launcher : ActivityResultLauncher < GooglePayPaymentMethodLauncherContractV2 . Args > ,
80+ launcher : InternalGooglePayPaymentMethodLauncher ,
7981 arguments : EmptyConfirmationLauncherArgs ,
8082 confirmationOption : GooglePayConfirmationOption ,
8183 confirmationArgs : ConfirmationHandler .Args ,
8284 ) {
8385 val config = confirmationOption.config
8486 val intent = confirmationArgs.intent
85- val googlePayLauncher = createGooglePayLauncher(
86- factory = googlePayPaymentMethodLauncherFactory,
87- activityLauncher = launcher,
88- config = confirmationOption.config,
89- confirmationArgs = confirmationArgs,
90- )
9187
92- googlePayLauncher .present(
88+ launcher .present(
9389 currencyCode = intent.asPaymentIntent()?.currency
9490 ? : config.merchantCurrencyCode.orEmpty(),
9591 amount = when (intent) {
9692 is PaymentIntent -> intent.amount ? : 0L
9793 is SetupIntent -> config.customAmount ? : 0L
9894 },
95+ config = config.toGooglePayLauncherConfig(confirmationArgs),
96+ cardBrandFilter = config.cardBrandFilter,
97+ cardFundingFilter = config.cardFundingFilter,
98+ clientAttributionMetadata = confirmationArgs.paymentMethodMetadata.clientAttributionMetadata,
9999 transactionId = intent.id,
100100 label = config.customLabel,
101- clientAttributionMetadata = confirmationArgs.paymentMethodMetadata.clientAttributionMetadata,
102101 isElements = true ,
102+ publishableKey = null ,
103103 displayItems = config.displayItems,
104104 billingEmailOverride = config.billingEmailOverride,
105105 )
@@ -143,34 +143,21 @@ internal class GooglePayConfirmationDefinition @Inject constructor(
143143 }
144144 }
145145
146- private fun createGooglePayLauncher (
147- factory : GooglePayPaymentMethodLauncherFactory ,
148- activityLauncher : ActivityResultLauncher <GooglePayPaymentMethodLauncherContractV2 .Args >,
149- config : GooglePayConfirmationOption .Config ,
146+ private fun GooglePayConfirmationOption.Config.toGooglePayLauncherConfig (
150147 confirmationArgs : ConfirmationHandler .Args ,
151- ): GooglePayPaymentMethodLauncher {
152- return factory.create(
153- lifecycleScope = CoroutineScope (Dispatchers .Default ),
154- config = GooglePayPaymentMethodLauncher .Config (
155- environment = when (config.environment) {
156- PaymentSheet .GooglePayConfiguration .Environment .Production -> GooglePayEnvironment .Production
157- else -> GooglePayEnvironment .Test
158- },
159- merchantCountryCode = config.merchantCountryCode,
160- merchantName = confirmationArgs.paymentMethodMetadata.sellerBusinessName
161- ? : config.merchantName,
162- isEmailRequired = config.isEmailRequired,
163- billingAddressConfig = config.billingDetailsCollectionConfiguration.toBillingAddressConfig(),
164- existingPaymentMethodRequired = ! FeatureFlags .allowNoExistingPaymentMethodForGooglePay.isEnabled,
165- additionalEnabledNetworks = config.additionalEnabledNetworks
166- ),
167- readyCallback = {
168- // Do nothing since we are skipping the ready check below
148+ ): GooglePayPaymentMethodLauncher .Config {
149+ return GooglePayPaymentMethodLauncher .Config (
150+ environment = when (environment) {
151+ PaymentSheet .GooglePayConfiguration .Environment .Production -> GooglePayEnvironment .Production
152+ else -> GooglePayEnvironment .Test
169153 },
170- activityResultLauncher = activityLauncher,
171- skipReadyCheck = true ,
172- cardBrandFilter = config.cardBrandFilter,
173- cardFundingFilter = config.cardFundingFilter,
154+ merchantCountryCode = merchantCountryCode,
155+ merchantName = confirmationArgs.paymentMethodMetadata.sellerBusinessName
156+ ? : merchantName,
157+ isEmailRequired = isEmailRequired,
158+ billingAddressConfig = billingDetailsCollectionConfiguration.toBillingAddressConfig(),
159+ existingPaymentMethodRequired = ! FeatureFlags .allowNoExistingPaymentMethodForGooglePay.isEnabled,
160+ additionalEnabledNetworks = additionalEnabledNetworks
174161 )
175162 }
176163
0 commit comments