Save and Retrieve Debit and Credit Card Information in Braintree

I am using Braintree v2 drop-in ui

android for payment and my server server is in node.js

. I have successfully completed the payment section, but now I need to save card details

and automatically subtract the amount from the saved debit/credit card

or paypal account

.

I create a client token and store this token in my database. Using this token, I generate a nonce. Then I send the server nonce to the backup server for transaction.sale()

.

Here is the code snippet for the payment section

if (!TextUtils.isEmpty(braintreeClientToken)) {
    DropInRequest dropInRequest = new DropInRequest()
                    .clientToken(braintreeClientToken);
    startActivityForResult(dropInRequest.getIntent(this), REQUEST_CODE);
}

      

OnActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
            PaymentMethodNonce paymentMethodNonce = result.getPaymentMethodNonce();
            String nonce = "";
            if (paymentMethodNonce != null)
                nonce = paymentMethodNonce.getNonce();
            // use the result to update your UI and send the payment method nonce to your server
            if (!TextUtils.isEmpty(nonce)) {
                NonceRequest obj = new NonceRequest("ANDROID", "1",
                            "DRIVER-SAVE-PAYMENT", "1", nonce);
                Call<NonceResponse> call = RestService.getInstance().restInterface.sendNonceToServer(userId, userToken, obj);
                    call.enqueue(new Callback<NonceResponse>() {
                    @Override
                    public void onResponse(Call<NonceResponse> call, Response<NonceResponse> response) {

                    }

                    @Override
                    public void onFailure(Call<NonceResponse> call, Throwable t) {

                    }
                });
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // the user canceled
        } else {
            // handle errors here, an exception may be available in
            Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
        }
    }
}

      

Can anyone please advise me on steps to store data credit/debit card

or paypal account

and generate a nonce from storedpayment-method

+3


source to share


1 answer


Full disclosure: I work at Braintree. If you have further questions, do not hesitate to contact support



Most of what you want to accomplish will be changed on your server side. If you want to save the map, you can either go to the options storeInVaultOnSuccess parameter , which will save this map on successful launch and create an associated client with this card. Otherwise, you can also pass this nonce to the PaymentMethod.Create call . If these calls are successful, a token will be generated for these cards that you can reuse. Based on the fact that you have stated that you want to "automatically subtract the amount" I think you can set up your subscription using this token. To do this, you need to create a plan , which is a template for your dashboard subscriptions. Then you want to createsubscription using the saved token you created. If you want these saved cards to appear in the Drop-In for the customer to select, you need to pass the customer_id in the ClientToken.generate call. This will allow the customer to select the saved card from their list and reuse it in the Drop-in.

+4


source







All Articles