rubyruby-on-rails-4braintreebraintree-rails

How to store Brain Tree Transaction Details Into Database in Rails 4


In my rails 4 application I am using Braintree sandbox testing transaction gateway. I am able to perform transactions and the transaction details are visible in my sandbox account.But my question is how to store the Transaction details into a table in my database ?

For example : The transaction ID, amount, Customer details etc. ?

My Code is given bellow :

def payment_process  
    @paymentamnt=@@deviceprice.to_i
    @result = Braintree::Transaction.sale(
              amount: @paymentamnt,
              payment_method_nonce: params[:payment_method_nonce])
    if @result.success?
      redirect_to payments_customers_path
    else
      flash[:alert] = "Something went wrong while processing your transaction. Please try again!"
      gon.client_token = generate_client_token
      render :new
    end
end

Solution

  • The values you are looking for are stored in the transaction object of @result.

    So you can access them like this:

    puts @result.transaction.amount
    puts @result.transaction.order_id
    

    etc.