I am using Braintree's v2 drop-in ui
android for payment and my backend server is in node.js
. I have successfully implemented payment section but now I need to store the card details
and deduct amount automatically from that stored debit/credit card
or paypal account
.
I am generating client token and store that token in my database. Using that token I am generating nonce. Then I am sending the nonce to backend server for transaction.sale()
.
Here is the code snippet for 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 anybody tell me the steps to store a credit/debit card
or paypal account
details and generate nonce from that stored payment-method
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support
Most of what you want to accomplish will be changes on your server-side. If you want to store a card, you can either pass into the options parameter storeInVaultOnSuccess, which will save that card on success and create an associated customer with that card. Otherwise, you can also pass that nonce into a PaymentMethod.Create call. If these calls are successful, a token will be created for those cards which you will then be able to reuse. Based on the fact you stated you wanted to "deduct amount automatically", I think you may want to setup a subscription using that token. For this, you'd need to create a plan, which is a template for your subscriptions in the control panel. Then you'd want to actually create the subscription using the stored token that you've created. If you want these saved cards to show up in the Drop-in for a customer to select, you'll want to pass the customer_id into the ClientToken.generate call. This will allow the customer to select a stored card from their list and reuse in the Drop-in.