Failure to generate payment nonce with direct Google Play integration
See original GitHub issueGeneral information
- SDK/Library version: 3.1.0
- Environment: Sandbox
- Android Version and Device: Emulator: Nexus 5X, API 26. Android 8.0
- Braintree dependencies: com.braintreepayments.api:braintree: 3.1.0 com.braintreepayments.api:data-collector: 3.1.0
Issue description
We have taken the Direct Google Play Services integration approach for Google Pay. Our integration has been live for over a year on version 2.x.x (currently on 2.22.0) but Google Pay has stopped working since upgrading to 3.1.0.
We are currently calling tokenize in the following way:
GooglePayment.tokenize(braintreeFragment, PaymentData.getFromIntent(data))
And this is resulting in the BraintreeErrorListener
callback being fired. The error returned is:
Error(error=java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference, code=, HTTPCode=400)
From what we can tell, the intent (data) being passed to getFromIntent()
does have the required PaymentData extra bundled. We extracted this from the debugger:
Bundle[{com.google.android.gms.wallet.PaymentData=[B@a5f3410}]
With no other changes, we can revert back to 2.22.0 in our build.gradle and Google Pay works again.
We are quite concerned that we will need to migrate to version 3.x.x in order to implement 3DS 2.0 in time for September deadlines. Any help would be greatly appreciated.
Many thanks, Tom
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:20 (8 by maintainers)
Top GitHub Comments
We just hit this issue too after upgrading Braintree SDK from 2.7.3 to 3.4.0
Will try the solution provided above.
Hello @tscott0 . Spoke with @Epreuve on our team to come back with the following:
In version 2.22.0 of the Braintree Android SDK, we use version 1.0.0 of Braintree Android Google Payment SDK. This uses V1 of the Google Play API. In version 3.1.0 of the Braintree Android SDK, we use version 3.0.1 of Braintree Android Google Payment SDK, which uses V2 of the Google Pay API.
So by bumping the Braintree Android SDK version, the version of the Google Pay API is changing as well. For the new Google Pay API, Google introduced some breaking changes. If you decide to use the Braintree SDK integration for Google Pay, these changes will be wrapped for you. But for a Direct Google Play Services integration, these changes you need to make your own.
You have to construct the
PaymentDataRequest
entirely from JSON now without using the previous builder functions. Have you made this change? You can see the changes outlined in steps 7-8 of this Google Pay guide.If your app IS working when you revert to 2.22.0, then you likely haven’t made the appropriate changes to adopt 3.1.0.
For reference you can check out how we handle setting all the required defaults and how we utilize Google’s
PaymentDataRequest.fromJson
.ALSO: Google’s guides mention how if
PaymentDataRequest
was not constructed.fromJson()
, then it’s.toJson()
will benull
.Please keep us posted if this doesn’t fix your integration!