简体   繁体   中英

Braintree - Android SDK: new credit card or existing one?

I'm new to the Android+Braintree world. At the moment I'm using the Drop-In interface. What I want to do is the following

"If the user is creating/adding a new card, ask him if he wants to save credit card information".

I need this info because later I will set the storeInVaultOnSuccess option in the transaction's params accordingly. Now, it seems that there is no way to insert an element in the drop-in GUI to understand if the user wants to save these data or not.

Fine, so I'm going to add an additional step just after the drop-in interface in which I'm only going to ask the user if he wants to save the credit card data or not.

But the problem is that I don't want to ask this question if he choose an already existent credit card, so I need to know if he created a new card or if he selected an existent one.

Is there a way to perform this task (or is there a better alternative)?

WHAT I'VE ALREADY TRIED: I've tried to see all the information given in the onActivityResult method, more specifically the content of the Intent given as the 3rd parameter. What I have is, of course, the EXTRA_PAYMENT_METHOD_NONCE , and then the EXTRA_PAYMENT_METHOD (type com.braintreepayments.api.models.Card ), but looking at the code of Card.java I'm not able to understand how to retrieve (if possible) this kind of information.

Thanks in advance.

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support .

The Drop-In UI doesn't support that workflow because at the time of entry the Drop-In automatically vaults the credit card and just provides the nonce (which doesn't contain any information about the card to the client for PCI reasons). In other words, storeInVaultOnSuccess won't apply since it's already there.

As you say, the way to get around this - while still using the Drop-In - would be to keep a reference to the payment method used in the transaction and ask after the transaction goes through. You can get this by examining the response object:

String payment_method_token = "";

TransactionRequest request = new TransactionRequest()
  .amount(new BigDecimal("100.00"));
  .paymentMethodNonce(nonceFromTheClient);
Result<Transaction> result = gateway.transaction().sale(request);
Transaction transaction = result.getTarget();

if (transaction.getPaymentInstrumentType().equals(PaymentInstrumentType.CREDIT_CARD){
  payment_method_token = transaction.getCreditCard.getToken();
}
// ... other payment method types that you support 

However, as you say, this is more complicated. You would have to make some selection based on: a) when the payment method was created (using createdAt), or a) comparing the arrays of payment methods before and after the checkout experience

This sort of flow really pushes the limits of the Drop-In, and these sorts of constraints often move developers to switch to a custom integration . In that case you would collect their preference - whether they want it stored - as they enter their credit card information .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM