1
votes

I'm using BrainTree drop-in UI, and I'm generating a client token as follows:

token = Braintree::ClientToken.generate(customer_id: some_id, options: {make_default: true })

Then updating the customer through:

Braintree::Customer.update(
    some_id,
  payment_method_nonce: options[:payment_method_nonce]
)

However the selected credit card isn't set as the default one, as checking customer.default_payment_method always returns the same card. So any clue to update the default payment method when updating customer?

Edit

After some investigation, it seems when I add a new payment method, it is set as the default one, however when choosing a saved payment method, it is not set as default.

I ended up using the following code:

Braintree::PaymentMethod.create(
  customer_id: some_id,
  payment_method_nonce: options[:payment_method_nonce],
  options: {
    make_default: true
  }
)
1

1 Answers

0
votes

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

That's correct - the Drop-in UI as you've configured it will make newly-created payment methods the default, but will not do the same with an existing payment method selected by the customer for a particular transaction.

In order to get the result you're looking for, I'd suggest using the credit card token from the transaction result object to update the payment method as in this example:

result = Braintree::PaymentMethod.update(
  "the_token",
  :options => {
    :make_default => true
  }
)