Search code examples
ruby-on-railsbraintree

ruby on rails braintree fail on duplicate payment method


i am trying to implement braintree payments into a ruby app, and everything seems to be working fine, but when i pass fail_on_duplicate_payment_method_card as an option i am getting invalid keys: options[fail_on_duplicate_payment_method_card]

result = Braintree::PaymentMethod.create(
        :customer_id => current_user.customer_cim_id,
        :payment_method_nonce => 'fake-valid-amex-nonce',
        :cardholder_name => "#{current_user.first_name} #{current_user.last_name}",
        :options => {
            :make_default => true,
            :fail_on_duplicate_payment_method_card => true
        }
    )
    if result.success?
      customer = Braintree::Customer.find(current_user.customer_cim_id)
      puts customer.id
      puts customer.payment_methods[0].token
    else
      p result.errors
    end

Solution

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

    fail_on_duplicate_payment_method_card should be fail_on_duplicate_payment_method.

    result = Braintree::PaymentMethod.create(
            :customer_id => current_user.customer_cim_id,
            :payment_method_nonce => 'fake-valid-amex-nonce',
            :cardholder_name => "#{current_user.first_name} #{current_user.last_name}",
            :options => {
                :make_default => true,
                :fail_on_duplicate_payment_method => true
            }
        )