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

Braintree Android PayPal Integration Error (ErrorWithResponse (422)) #304

Closed peterujah closed 3 years ago

peterujah commented 4 years ago

Am implementing Braintree Credit Card & PayPal using Android & PHP. From my backend I have below line of code to generate token. Everything works fine when I tried credit card both in custom form and dropin integration, but for PayPal I kept getting errors.

$gateway = new Braintree\Gateway([
    'environment' => 'sandbox',
    'merchantId' => '2vXXXXXXX',
    'publicKey' => 'rpXXXXX',
    'privateKey' => '0fXXXXXXXX'
]);
echo $gateway->clientToken()->generate();

Then implementing this on android as below

mBraintreeFragment = BraintreeFragment.newInstance(PaypalActivity.this, TOKEN_FROM_SERVER);
mBraintreeFragment.addListener(createdListener);
mBraintreeFragment.addListener(cancelListener);
mBraintreeFragment.addListener(errorListener);

PayPalRequest request = new PayPalRequest("10").currencyCode("USD")
.intent(PayPalRequest.INTENT_AUTHORIZE);

PayPal.requestOneTimePayment(mBraintreeFragment, request);

But am always getting below error

{"paymentResource":{"errorName":null,"errorMessage":null,"errorDetails":null,"debugId":null,"paypalHttpStatus":null}}
ErrorWithResponse (422): Parsing error response failed

I also tried using dropin but not luck.

SDK/Library version: Example: 2.22.0 Environment: Sandbox Android Version and Device: Samsung M40, version 10 Braintree dependencies: com.braintreepayments.api:braintree:x.y.z

sshropshire commented 4 years ago

Hi @peterujah thanks for using the Braintree SDK for Android.

As a first step, I would recommend upgrading to the latest version of our core/drop-in SDKs and see if the issue persists. I would also verify that your Braintree and PayPal sandbox accounts are linked.

peterujah commented 4 years ago

Is it upgrading drop-in SDK could be causing the problem? If that is the case am not using drop-in, I mentioned above that I also tried using drop-in. but no luck.

peterujah commented 4 years ago

Currently my minSdkVersion 19 and targetSdkVersion 30, I can upgrade the minSdkVersion 19 because my client doesn't want to loss support for some older device.

BeantSingh96 commented 4 years ago

Hello there i am facing this issue too. Help me to solve this.

sshropshire commented 4 years ago

@peterujah As an exercise, can you try upgrading the core sdk to com.braintreepayments.api:braintree:3.12.0 to see if that solves the issue? We suggest our merchants update regularly to the latest version of the SDK to take advantage of active development and bug fixes.

Otherwise, version v2.21.0 is the last 2.x version we have. Also, make sure you're using a Client Token and not a Tokenization key when creating a new BraintreeFragment.

sshropshire commented 4 years ago

Hi @peterujah and @BeantSingh96, were you able to resolve this issue?

panchao0716 commented 3 years ago

hi,I also encountered the same problem E/paypal: ErrorWithResponse (422): Parsing error response failed [] The version used is implementation 'com.braintreepayments.api:braintree:3.16.1'

peterujah commented 3 years ago

hi,I also encountered the same problem E/paypal: ErrorWithResponse (422): Parsing error response failed [] The version used is implementation 'com.braintreepayments.api:braintree:3.16.1'

Try doing this in your php

<?php
$gateway = new Braintree\Gateway([/....../]);
$theCustomer = "test123";
    try{
        $result = $gateway->customer()->find($theCustomer);
        $customer_id = $result->id;
    } catch (Braintree\Exception\NotFound $e) {
               //Create customer if not exist 
        $result = $gateway->customer()->create([
            'id' => $theCustomer,
            'firstName' => "Peter",
            'lastName' => "U",
            'phone' => "00000000",
            'email' => "peter@example.com",
            //  'paymentMethodNonce' => nonceFromTheClient
        ]);
        $customer_id = $result->customer->id;
    }

    $BrainTreeClientToken = $gateway->clientToken()->generate([
        "customerId" => $customer_id
    ]);