问题
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?
回答1:
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.
回答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);
}
来源:https://stackoverflow.com/questions/28320119/braintree-not-updating-user-preferred-default-payment-method