Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

braintree Integration causing issues Android

I am getting client Token from server, but when call setup BraintreeFramgent it will says Tokenization Key or client token was invalid..

after then if i click on button then OnActivityResult Consider RESULT_CANCELED and show dialog.

Below Code

compile 'com.braintreepayments.api:braintree:2.+'

compile 'com.braintreepayments.api:drop-in:2.+'

java file

String clientToken;
private BraintreeFragment mBraintreeFragment;
private String mNonce;

OnCreate

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Warning, signature verification is disabled for this demo only, you should never
        // do this as it opens a security hole
        PayPalSignatureVerification.disableAppSwitchSignatureVerification();


        clienttoken();
    }

clienttoken()

public void clienttoken() {
        AsyncHttpClient client = new AsyncHttpClient();
        client.get("http://......&action=clientToken", new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                clientToken = responseString;
                setup();
                //Toast.makeText(MainActivity.this, clientToken, Toast.LENGTH_LONG).show();
            }
        });
    }

setup()

private void setup() {
        try {

            mBraintreeFragment = BraintreeFragment.newInstance(this, clientToken);

        } catch (InvalidArgumentException e) {
            showDialog(e.getMessage());
        }
    }

Button click

public void launchDropIn(View v) {
        startActivityForResult(onBraintreeSubmit().getIntent(this), DROP_IN_REQUEST);
    }

onBraintreeSubmit()

public PaymentRequest onBraintreeSubmit() {
        PaymentRequest paymentRequest = new PaymentRequest()
                .clientToken(clientToken)
                .primaryDescription(getString(R.string.cart))
                .secondaryDescription("1 Item")
                .amount("$1.00")
                .submitButtonText(getString(R.string.buy));

        return paymentRequest;
    }

onActivityResult

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);



        if (resultCode == Activity.RESULT_OK) {
            PaymentMethodNonce paymentMethodNonce =
                    data.getParcelableExtra(BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE);

            if (Settings.isThreeDSecureEnabled(this)) {
                mLoading = ProgressDialog.show(this, getString(R.string.loading),
                        getString(R.string.loading), true, false);
                ThreeDSecure.performVerification(mBraintreeFragment, mNonce, "1");
            } else {
                mCreateTransactionButton.setEnabled(true);
            }
        } else if (resultCode != RESULT_CANCELED) {
            safelyCloseLoadingView();
            showDialog(data.getStringExtra(BraintreePaymentActivity.EXTRA_ERROR_MESSAGE));
        }
    }

i am totally new with Braintree integration in android. what is the issue. is there i am wrong any where? or what else please suggest.

like image 993
RaRa Avatar asked Jan 04 '16 06:01

RaRa


1 Answers

Full disclosure: I work at Braintree.

The warning you are getting suggests that the client token you generated may be incorrect. Test your integration with the sample valid client token given here. If that works, please check to make sure your API keys for the Braintree gateway you are using (sandbox or production) are set up correctly in your project. You can find your API keys from the Braintree control panel by selecting Account > My User > View API Keys. Do not post your API keys on Stack Overflow. If you still have trouble with your integration or have any more questions, please contact Braintree support.

like image 116
Jessica d Avatar answered Oct 21 '22 12:10

Jessica d