3

When a customer wants to choose his payment method while creating a sale order I see it changed in the DropInUI(small tick mark) and I assume that should become the default payment method but that is not what happens at my server, I still get the payment token for the first one.

Here's what I'm doing:

String token = btGateway.customer().find(customerId).getDefaultPaymentMethod().getToken().toString();

Case:

  • Customer A places an order with his credit card - All Good
  • Customer A places another order, this time adding a paypal account and the drop in ui shows two options, customer selects his preferred payment method - All good

At my server I don't get a different payment token for credit card and paypal.

UPDATE:

Based on the Ryan's answer, I have a new query: How do you get the token for the payment method selected from the dropin(is there a delegate method that returns the payment method in iOS). Is there a way to identify the payment method selected by user so I fetch the token for it?

Atif Imran
  • 1,899
  • 2
  • 18
  • 33

2 Answers2

5

When you select a payment method from the DropIn, that payment method does not automatically get set at the customer's default. If you want to set a default payment method, you can do that via the SDK.

The card that gets displayed in the DropIn is most recently used card.

If you have any other questions, please feel free to email us at support@braintreepayments.com.

  • Hey Ryan thanks for the reply. Let me ask it another way. How do you get the token for the payment method selected from the dropin. Is there a way to identify the payment method selected by user so I fetch the token for it? – Atif Imran Feb 05 '15 at 02:53
  • Het Atif, Sorry for the late response. In order to find the most recently used payment method, you could access the first transaction in the transactions collection associated with the customer. Then look up the credit card details on that. This will end up looking something like this: `Braintree::Customer.find('xxx').transactions.first.credit_card_details.token` – Ryan O'Donnell Feb 05 '15 at 15:26
  • 1
    This has been identified as an [issue](https://github.com/braintree/braintree_android/issues/23) on Android and fixed. Will this be added to the JS drop-in anytime soon? This is a rather nasty shortcoming of the drop-in UI. – p4sh4 Apr 21 '16 at 04:11
2

All right, after nice inputs from Ryan and here. I figured out a way to make my payment method as default and fetch its token to make a sale with that later on. Later on since I am using marketplace I can't create a sale with service fee so I fetched the payment method from the token and went on to make a sale. Not sure if what I did is the best way but it serves the purpose.

Here's what I did:

Make the user selected payment method as default and save its token:

if(customerId!=null){
            PaymentMethodRequest request = new PaymentMethodRequest()
            .customerId(customerId)
            .paymentMethodNonce("paymentMethodNonceFromClient")
            .options()
                .makeDefault(true)
            .done();

            Result<PaymentMethod> result = (Result<PaymentMethod>) btGateway.paymentMethod().create(request);
            if(result.isSuccess())
                token = btGateway.customer().find(customerId).getDefaultPaymentMethod().getToken().toString();

Later on when making a transaction find the payment method and apply fee if it is a CreditCard:

PaymentMethod payMethod = btGateway.paymentMethod().find(token);
            if(payMethod instanceof CreditCard){
                request = new TransactionRequest()
                .amount(new BigDecimal(txnAmount))
                .paymentMethodToken(token)
                .merchantAccountId("merchantAccountId")
                .serviceFeeAmount(new BigDecimal(serviceFee));
            }else{
                request = new TransactionRequest()
                .amount(new BigDecimal(txnAmount))
                .paymentMethodToken(token);
            }
Atif Imran
  • 1,899
  • 2
  • 18
  • 33