braintree / braintree_android

Braintree SDK for Android
https://developer.paypal.com/braintree/docs/start/hello-client/android/v4
MIT License
409 stars 234 forks source link

Calling onFailure Results Exception Stating Paypal is Not Enabled #821

Closed sdoward closed 10 months ago

sdoward commented 11 months ago

Braintree SDK Version

4.37.0

Environment

Sandbox

Android Version & Device

-

Braintree dependencies

com.braintreepayments.api:paypal

Describe the bug

Calling onFailure Results Exception Stating Paypal is Not Enabled

To reproduce

Setup The PayPayClient so it is able to tokenise paypal accounts

val scheme = "${activity.packageName}.${activity::class.java.simpleName}.braintree".lowercase(Locale.ENGLISH)
        val braintreeClient = BraintreeClient(activity, tokenProvider, scheme)
        return PayPalClient(activity, braintreeClient)

Setup the clientSetup a ClientTokenProvider that always calls onFailure

ClientTokenProvider {
    override fun getClientToken(callback: ClientTokenCallback) {
        activity.lifecycleScope.launch {
            callback.onFailure(Exception())
        }
    }
}

Expected Result Some reasonable exception that explains that Braintree was unable to retrieve the token

Actual Result Exception saying that Paypal is not enabled.

com.braintreepayments.api.BraintreeException: PayPal is not enabled. See https://developer.paypal.com/braintree/docs/guides/paypal/overview/android/v4 for more information.
at com.braintreepayments.api.PayPalClient.createPayPalError(PayPalClient.java:129)
at com.braintreepayments.api.PayPalClient.access$200(PayPalClient.java:22)
at com.braintreepayments.api.PayPalClient$3.onResult(PayPalClient.java:243)
at com.braintreepayments.api.BraintreeClient.getConfiguration$lambda-1(BraintreeClient.kt:183)
at com.braintreepayments.api.BraintreeClient.$r8$lambda$uXb_Q2SC3tZeqa7FJDcACDNy02I(Unknown Source:0)
at com.braintreepayments.api.BraintreeClient$$ExternalSyntheticLambda4.onAuthorizationResult(Unknown Source:4)
at com.braintreepayments.api.AuthorizationLoader$loadAuthorization$1.onFailure(AuthorizationLoader.kt:21)
at org.sharethemeal.app.payments.PaypalTokenProvider$getClientToken$1.invokeSuspend(PaypalTokenProvider.kt:16)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at org.sharethemeal.app.payments.PaypalTokenProvider.getClientToken(PaypalTokenProvider.kt:15)
at com.braintreepayments.api.AuthorizationLoader.loadAuthorization(AuthorizationLoader.kt:14)
at com.braintreepayments.api.BraintreeClient.getAuthorization(BraintreeClient.kt:193)
at com.braintreepayments.api.BraintreeClient.getConfiguration(BraintreeClient.kt:173)
at com.braintreepayments.api.PayPalClient.sendVaultRequest(PayPalClient.java:239)
at com.braintreepayments.api.PayPalClient.tokenizePayPalAccount(PayPalClient.java:175)
at com.braintreepayments.api.PayPalClient.tokenizePayPalAccount(PayPalClient.java:151)

Expected behavior

Some reasonable exception that explains that Braintree was unable to retrieve the token

Screenshots

No response

sarahkoop commented 11 months ago

Hi @sdoward - This error indicates that your Braintree account does not have PayPal enabled. Please follow the steps here to enable PayPal payments for your account.

sdoward commented 11 months ago

@sarahkoop Thats what the error indicates but the error is wrong. I have paypal up and running in production already.

Can you reopen the ticket at take a look at the problem?

sarahkoop commented 11 months ago

To better understand the issue - are you migrating to using ClientTokenProvider and now are seeing this PayPal is not enabled error?

The error is returned if your Braintree merchant configuration does not have PayPal enabled, or if the merchant configuration is unable to be fetched.

If you've confirmed PayPal is enabled for your account, then it's likely that there is an error fetching configuration (possibly related to the ClientTokenProvider implementation). Can you confirm if your provider is setup correctly, or provide additional implementation details for that?

sdoward commented 11 months ago

To better understand the issue - are you migrating to using ClientTokenProvider and now are seeing this PayPal is not enabled error?

I am debugging a separate issue. We are already using ClientTokenProvider. I found that if I pass in any exception to the callback.onFailure() function then the error shows that I don't have Paypal enabled. This is not correct.

The error is returned if your Braintree merchant configuration does not have PayPal enabled, or if the merchant configuration is unable to be fetched.

It is also returned if any exception is passed to the callback. Which is incorrect. This is the bug that I am reporting

Can you confirm if your provider is setup correctly, or provide additional implementation details for that?

As mentioned above, we have paypal working in production already. Is there something missing from the initial report?

Can you confirm you read through the initial report and looked at the code samples?

sarahkoop commented 11 months ago

Ok we can add a ticket to make the exception message here more specific (unable to fetch the merchant configuration so unable to determine if PayPal is enabled, instead of PayPal is not enabled).

sdoward commented 11 months ago

@sarahkoop from an API perspective that is a little strange. The error is with retrieving a token. The error should read Unable to retrieve ClientToken or something similar. Thought you suggest is also correct.

I am not too sure what merchant configuration you are referring. If that is an internal operation you don't need to provide that information externally.

sarahkoop commented 11 months ago

Ok we appreciate the feedback!

As an aside - we are also currently working on a new major version of the SDK that moves away from the ClientTokenProvider pattern altogether (we are also actively working on incorporating your feedback from #491). We would appreciate any input you have on v5 once the beta becomes available - or if you want to follow along with the active development!

sdoward commented 11 months ago

Thanks for the update! I am eagerly awaiting V5

hollabaq86 commented 10 months ago

for internal tracking, issue 30170

sarahkoop commented 10 months ago

This fix was released in version 4.40.1