question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failure to generate payment nonce with direct Google Play integration

See original GitHub issue

General 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
krunk4evercommented, Aug 26, 2019

We just hit this issue too after upgrading Braintree SDK from 2.7.3 to 3.4.0

Will try the solution provided above.

1reaction
scannillocommented, Jul 3, 2019

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 be null.

Please keep us posted if this doesn’t fix your integration!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix payment issues on your account - Android
If you try to buy something on Google Play but your payment is declined or won't process, try the steps below. Troubleshoot Payment...
Read more >
Payment data cryptography for merchants
This guide provides information on how to generate a public key to request a Google-signed and encrypted payment method token, and details the...
Read more >
SafetyNet Attestation API
The SafetyNet Attestation API provides services for determining whether a device running your app satisfies Android compatibility tests.
Read more >
Protect‌ ‌your‌ ‌game‌ ‌and‌ ‌players‌ ‌on‌ ‌Google‌ ‌Play‌
Generally you integrate these checks as follows: Generate nonce: Generate a nonce on your server to initiate the check. A nonce is a...
Read more >
Migrating to 3D Secure 2 | Android - Braintree ...
Authentication unsuccessful. Merchants should prompt customers for another form of payment. status: authenticate_rejected, Visa. 4000000000001042; 01/20**.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found