Rishabh Tayal
Rishabh Tayal

Reputation: 496

Braintree vault not storing payment methods

My sandbox account doesn't store payment methods for customer in their vault. I am creating a customer object using:

def create_customer
  result = Braintree::Customer.create(
    :first_name => params[:first_name],
    :last_name => params[:last_name],
    :email => params[:email],
    :phone => params[:phone]
    )
  if result.success?
    render :json => {'result' => result.customer.id}
  else
    render :json => {'errors' => result.errors}, :status => 400
  end
end

and then storing the customer_id in my database for later use.

When creating client_token I am sending the same customer_id to the API. Here is the code for creating client_token:

def client_token
  token = Braintree::ClientToken.generate(
    :customer_id => params[:customer_id]
    )
  render :json => {"token" => token}
end

Upvotes: 1

Views: 290

Answers (1)

agf
agf

Reputation: 176950

I work at Braintree. If you have more questions about your integration, you can always get in touch with our support team

You need to create a payment method with the nonce you receive back from your client:

result = Braintree::PaymentMethod.create(
  :customer_id => "131866",
  :payment_method_nonce => nonce_from_the_client
)

Upvotes: 1

Related Questions