Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] CustomerSheet and CustomerAdapter.create - StrictMode policy violation: android.os.strictmode.NetworkViolation #9118

Open
nicolasjafelle-latch opened this issue Aug 23, 2024 · 2 comments
Labels

Comments

@nicolasjafelle-latch
Copy link

Summary

When enable StrictMode Stripe SDK internally is Violating Network operations on Main Thread

Code to reproduce

Wrapping the CustomerAdapter and provides ephemeral key, customer id, and client secret after initialize with PaymentConfiguration.init(context, publishableKey)

@OptIn(ExperimentalCustomerSheetApi::class)
class CreditCardAdapter(
    context: Context,
    customerId: String,
    customerEphemeralKeySecret: String,
    clientSecret: String
) {

    internal val customerAdapter: CustomerAdapter = CustomerAdapter.create(
        context = context,
        customerEphemeralKeyProvider = {
            CustomerAdapter.Result.success(
                CustomerEphemeralKey.create(
                    customerId = customerId,
                    ephemeralKey = customerEphemeralKeySecret
                )
            )
        },
        setupIntentClientSecretProvider = { customerId ->
            CustomerAdapter.Result.success(
                clientSecret
            )
        }
    )
}
private fun LaunchInternal(
    creditCardAdapter: CreditCardAdapter,
    onPaymentSelected: (PaymentMethodResult) -> Unit
) {
    val customerSheet = rememberCustomerSheet(
        customerAdapter = creditCardAdapter.customerAdapter,
        configuration = buildConfig(),
        callback = { result ->
            result.toPaymentMethodResult()
            onPaymentSelected.invoke(result.toPaymentMethodResult())
        }
    )

    LaunchedEffect(Unit) {
        val result = customerSheet.retrievePaymentOptionSelection()
        onPaymentSelected.invoke(result.toPaymentMethodResult())
    }

    customerSheet.present()
}

Android version

All

Impacted devices

Emulator with SDK 33

Installation method

via Gradle dependency

Dependency Versions

kotlin: 1.9.22
stripe-android: "20.48.5"
Android Gradle Plugin: 8.3.0
Gradle: Gradle 8.4

SDK classes

com.stripe.android.customersheet.CustomerSheetActivity
com.stripe.android.customersheet.CustomerAdapter
com.stripe.android.customersheet.CustomerSheet

Other information

Logcat attached:

StrictMode D  
    StrictMode policy violation: android.os.strictmode.NetworkViolation (Ask Gemini)
    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1672)
    at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:115)
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
    at java.net.InetAddress.getAllByName(InetAddress.java:1152)
    at com.android.okhttp.Dns$1.lookup(Dns.java:41)
    at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178)
    at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144)
    at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86)
    at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176)
    at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
    at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
    at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
    at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
    at com.stripe.android.core.networking.StripeConnection$AbstractConnection.getResponseCode(StripeConnection.kt:31)
    at com.stripe.android.core.networking.StripeConnection$AbstractConnection.getResponse(StripeConnection.kt:39)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient.parseResponse(DefaultStripeNetworkClient.kt:80)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient.makeRequest(DefaultStripeNetworkClient.kt:65)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient.access$makeRequest(DefaultStripeNetworkClient.kt:14)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient$executeRequest$2.invoke(DefaultStripeNetworkClient.kt:24)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient$executeRequest$2.invoke(DefaultStripeNetworkClient.kt:23)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient$executeInternal$2.invokeSuspend(DefaultStripeNetworkClient.kt:43)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient$executeInternal$2.invoke(Unknown Source:8)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient$executeInternal$2.invoke(Unknown Source:4)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:61)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient.executeInternal$stripe_core_release(DefaultStripeNetworkClient.kt:42)
    at com.stripe.android.core.networking.DefaultStripeNetworkClient.executeRequest(DefaultStripeNetworkClient.kt:23)
    at com.stripe.android.networking.StripeApiRepository.makeApiRequest$payments_core_release(StripeApiRepository.kt:1547)
    at com.stripe.android.networking.StripeApiRepository.fetchStripeModelResult-BWLJW6A(StripeApiRepository.kt:1525)
    at com.stripe.android.networking.StripeApiRepository.retrieveElementsSession-BWLJW6A(StripeApiRepository.kt:1465)
    at com.stripe.android.networking.StripeApiRepository.retrieveElementsSession-0E7RQCE(StripeApiRepository.kt:1385)
    at com.stripe.android.paymentsheet.repositories.RealElementsSessionRepository.get-yxL6bBk(ElementsSessionRepository.kt:58)
    
StrictMode  D  	
    at com.stripe.android.customersheet.DefaultCustomerSheetLoader.retrieveElementsSession-gIAlu-s(CustomerSheetLoader.kt:121) (Ask Gemini)
    at com.stripe.android.customersheet.DefaultCustomerSheetLoader.load-gIAlu-s(CustomerSheetLoader.kt:72)
    at com.stripe.android.customersheet.CustomerSheetViewModel$loadCustomerSheetState$result$1.invokeSuspend(CustomerSheetViewModel.kt:234)
    at com.stripe.android.customersheet.CustomerSheetViewModel$loadCustomerSheetState$result$1.invoke(Unknown Source:8)
    at com.stripe.android.customersheet.CustomerSheetViewModel$loadCustomerSheetState$result$1.invoke(Unknown Source:4)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:61)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
    at com.stripe.android.customersheet.CustomerSheetViewModel.loadCustomerSheetState(CustomerSheetViewModel.kt:233)
    at com.stripe.android.customersheet.CustomerSheetViewModel.access$loadCustomerSheetState(CustomerSheetViewModel.kt:75)
    at com.stripe.android.customersheet.CustomerSheetViewModel$1.invokeSuspend(CustomerSheetViewModel.kt:157)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
@nicolasjafelle
Copy link

any comments?

@nicolasjafelle-latch
Copy link
Author

2 weeks and no action...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants